[gjs/wip/ptomato/mozjs38: 1/14] js: Adapt to new JS_DefinePropertyById() API



commit b13a628ce73152891f393fafe50954aa7c664da1
Author: Philip Chimento <philip chimento gmail com>
Date:   Wed Jan 11 22:51:59 2017 -0800

    js: Adapt to new JS_DefinePropertyById() API
    
    Like JS_DefineProperty() could already, JS_DefinePropertyById() is now
    overloaded to take several types as the property value. This allows us to
    pass rooted objects directly in, in order to avoid creating temporary
    JS::Values.

 gi/gerror.cpp    |    6 +++---
 gi/repo.cpp      |   17 +++++------------
 gjs/importer.cpp |    4 +---
 3 files changed, 9 insertions(+), 18 deletions(-)
---
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index c069a19..2503b98 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -417,13 +417,13 @@ define_error_properties(JSContext       *context,
         gjs_context_get_const_string(context, GJS_STRING_LINE_NUMBER));
 
     JS_DefinePropertyById(context, obj, stack_name, stack,
-                          NULL, NULL, JSPROP_ENUMERATE);
+                          JSPROP_ENUMERATE);
 
     JS_DefinePropertyById(context, obj, filename_name, fileName,
-                          NULL, NULL, JSPROP_ENUMERATE);
+                          JSPROP_ENUMERATE);
 
     JS_DefinePropertyById(context, obj, linenumber_name, lineNumber,
-                          NULL, NULL, JSPROP_ENUMERATE);
+                          JSPROP_ENUMERATE);
 }
 
 JSObject*
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 97cd44f..c67c8fe 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -234,8 +234,6 @@ static JSObject*
 repo_new(JSContext *context)
 {
     Repo *priv;
-    JSObject *versions;
-    JSObject *private_ns;
     bool found;
 
     JS::RootedObject global(context, gjs_get_import_global(context));
@@ -290,22 +288,17 @@ repo_new(JSContext *context)
     gjs_debug_lifecycle(GJS_DEBUG_GREPO,
                         "repo constructor, obj %p priv %p", repo.get(), priv);
 
-    versions = JS_NewObject(context, NULL, global);
+    JS::RootedObject versions(context, JS_NewObject(context, NULL, global));
     JS::RootedId versions_name(context,
         gjs_context_get_const_string(context, GJS_STRING_GI_VERSIONS));
-    JS_DefinePropertyById(context, repo,
-                          versions_name,
-                          JS::ObjectValue(*versions),
-                          NULL, NULL,
+    JS_DefinePropertyById(context, repo, versions_name, versions,
                           JSPROP_PERMANENT);
 
-    private_ns = JS_NewObject(context, NULL, global);
+    JS::RootedObject private_ns(context, JS_NewObject(context, NULL, global));
     JS::RootedId private_ns_name(context,
         gjs_context_get_const_string(context, GJS_STRING_PRIVATE_NS_MARKER));
-    JS_DefinePropertyById(context, repo,
-                          private_ns_name,
-                          JS::ObjectValue(*private_ns),
-                          NULL, NULL, JSPROP_PERMANENT);
+    JS_DefinePropertyById(context, repo, private_ns_name, private_ns,
+                          JSPROP_PERMANENT);
 
     /* FIXME - hack to make namespaces load, since
      * gobject-introspection does not yet search a path properly.
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 670185e..381cc62 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -380,8 +380,7 @@ load_module_init(JSContext       *context,
         goto out;
 
     if (!JS_DefinePropertyById(context, in_object,
-                               module_init_name, JS::ObjectValue(*module_obj),
-                               NULL, NULL,
+                               module_init_name, module_obj,
                                GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT))
         goto out;
 
@@ -1174,7 +1173,6 @@ gjs_define_root_importer_object(JSContext        *context,
         gjs_context_get_const_string(context, GJS_STRING_IMPORTS));
     if (!JS_DefinePropertyById(context, in_object,
                                imports_name, importer,
-                               NULL, NULL,
                                GJS_MODULE_PROP_FLAGS)) {
         gjs_debug(GJS_DEBUG_IMPORTER, "DefineProperty imports on %p failed",
                   in_object.get());


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