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



commit 9f6fa0d9777e3cbb5f24bb0ea73e269661d85f47
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 36292b6..3c78404 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -190,11 +190,12 @@ import_directory(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",
@@ -202,13 +203,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);
@@ -437,6 +434,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)
 {
@@ -456,7 +454,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;
@@ -473,6 +471,7 @@ static bool
 do_import(JSContext       *context,
           JS::HandleObject obj,
           Importer        *priv,
+          JS::HandleId     id,
           const char      *name)
 {
     char *filename;
@@ -596,7 +595,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;
@@ -800,7 +799,7 @@ importer_resolve(JSContext        *context,
     }
 
     JSAutoRequest ar(context);
-    if (!do_import(context, obj, priv, name))
+    if (!do_import(context, obj, priv, id, name))
         return false;
 
     *resolved = true;


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