[gjs/wip/ptomato/mozjs52: 25/40] importer: Seal import with JSPropertyDescriptor directly



commit 662920b90ff04f0ef5b099f2d68b1db0dccba359
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Mar 19 05:18:36 2017 +0000

    importer: Seal import with JSPropertyDescriptor directly
    
    Previously we "sealed" the import by redefining the property on the
    importer object so that it was undeleteable. Now we can do this in a more
    direct way by getting and modifying the property's descriptor.
    
    In order to make this more convenient and faster we thread the jsid
    through the call stack so we don't have to convert it to and from a
    string.

 gjs/importer.cpp |   19 +++++++++----------
 1 files changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index a7f1a2b..b9097a8 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -208,11 +208,12 @@ define_import(JSContext       *context,
 static bool
 seal_import(JSContext       *cx,
             JS::HandleObject obj,
+            JS::HandleId     id,
             const char      *name)
 {
     JS::Rooted<JSPropertyDescriptor> descr(cx);
 
-    if (!JS_GetOwnPropertyDescriptor(cx, obj, name, &descr) ||
+    if (!JS_GetOwnPropertyDescriptorById(cx, obj, id, &descr) ||
         descr.object() == NULL) {
         gjs_debug(GJS_DEBUG_IMPORTER,
                   "Failed to get attributes to seal '%s' in importer",
@@ -220,13 +221,9 @@ seal_import(JSContext       *cx,
         return false;
     }
 
-    /* COMPAT: in mozjs45 use .setConfigurable(false) and the form of
-     * JS_DefineProperty that takes the JSPropertyDescriptor directly */
+    descr.setConfigurable(false);
 
-    if (!JS_DefineProperty(cx, descr.object(), name, descr.value(),
-                           descr.attributes() | JSPROP_PERMANENT,
-                           JS_PROPERTYOP_GETTER(descr.getter()),
-                           JS_PROPERTYOP_SETTER(descr.setter()))) {
+    if (!JS_DefinePropertyById(cx, descr.object(), id, descr)) {
         gjs_debug(GJS_DEBUG_IMPORTER,
                   "Failed to redefine attributes to seal '%s' in importer",
                   name);
@@ -457,6 +454,7 @@ import_symbol_from_init_js(JSContext       *cx,
 static bool
 import_file_on_module(JSContext       *context,
                       JS::HandleObject obj,
+                      JS::HandleId     id,
                       const char      *name,
                       GFile           *file)
 {
@@ -479,7 +477,7 @@ import_file_on_module(JSContext       *context,
                            0, 0))
         goto out;
 
-    if (!seal_import(context, obj, name))
+    if (!seal_import(context, obj, id, name))
         goto out;
 
     retval = true;
@@ -496,6 +494,7 @@ static bool
 do_import(JSContext       *context,
           JS::HandleObject obj,
           Importer        *priv,
+          JS::HandleId     id,
           const char      *name)
 {
     char *filename;
@@ -621,7 +620,7 @@ do_import(JSContext       *context,
             continue;
         }
 
-        if (import_file_on_module (context, obj, name, gfile)) {
+        if (import_file_on_module(context, obj, id, name, gfile)) {
             gjs_debug(GJS_DEBUG_IMPORTER,
                       "successfully imported module '%s'", name);
             result = true;
@@ -829,7 +828,7 @@ importer_resolve(JSContext        *context,
     }
 
     JSAutoRequest ar(context);
-    if (!do_import(context, obj, priv, name)) {
+    if (!do_import(context, obj, priv, id, name)) {
         g_free(name);
         return false;
     }


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