[gjs] native: Pass the module name to the import call



commit e01d8a177f38b7ce8b7333a4fb49c28c1a73dabf
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Feb 27 20:30:05 2013 -0500

    native: Pass the module name to the import call
    
    Rather than picking it up indirectly through meta properties.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694873

 gjs/importer.c |    2 +-
 gjs/native.c   |   22 +++++++---------------
 gjs/native.h   |    3 ++-
 3 files changed, 10 insertions(+), 17 deletions(-)
---
diff --git a/gjs/importer.c b/gjs/importer.c
index dde1ce1..fbc9873 100644
--- a/gjs/importer.c
+++ b/gjs/importer.c
@@ -254,7 +254,7 @@ import_native_file(JSContext  *context,
     if (!define_meta_properties(context, module_obj, NULL, name, obj))
         goto out;
 
-    if (!gjs_import_native_module(context, module_obj))
+    if (!gjs_import_native_module(context, module_obj, name))
         goto out;
 
     if (!finish_import(context, name))
diff --git a/gjs/native.c b/gjs/native.c
index e8a3c6b..eb75b2e 100644
--- a/gjs/native.c
+++ b/gjs/native.c
@@ -188,24 +188,16 @@ gjs_is_registered_native_module(JSContext  *context,
  */
 JSBool
 gjs_import_native_module(JSContext *context,
-                         JSObject  *module_obj)
+                         JSObject  *module_obj,
+                         const char *name)
 {
     GjsNativeModule *native_module;
     JSObject *parent;
-    jsval tmp;
-
-    /* dlopen() as a side effect should have registered us as
-     * a native module. We just have to reverse-engineer
-     * the module id from module_obj.
-     */
-    {
-        char *module_name = get_module_name(context, module_obj, &tmp);
-        native_module = lookup_native_module (context,
-                                              module_get_parent(context, module_obj),
-                                              module_name,
-                                              TRUE);
-        g_free(module_name);
-    }
+
+    native_module = lookup_native_module (context,
+                                          module_get_parent(context, module_obj),
+                                          name,
+                                          TRUE);
 
     if (!native_module)
         return JS_FALSE;
diff --git a/gjs/native.h b/gjs/native.h
index 27e5632..98bb4c0 100644
--- a/gjs/native.h
+++ b/gjs/native.h
@@ -97,7 +97,8 @@ gboolean gjs_is_registered_native_module(JSContext  *context,
 
 /* called by importer.c to load a statically linked native module */
 JSBool gjs_import_native_module (JSContext *context,
-                                 JSObject  *module_obj);
+                                 JSObject  *module_obj,
+                                 const char *name);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]