[gjs/wip/ptomato/mozjs31: 9/11] importer: Remove deprecated JS_{Get, Set}PropertyAttributes



commit 4f13a0b7e9de632cb6652b8ffe005998fe3bc1d8
Author: Philip Chimento <philip endlessm com>
Date:   Fri Oct 21 17:50:38 2016 -0700

    importer: Remove deprecated JS_{Get,Set}PropertyAttributes
    
    This has no direct replacement in mozjs31, but the way to do it is to get
    the property's descriptor, and overwrite the existing property with
    JS_DefineProperty() when we want to change the attributes.

 gjs/importer.cpp |   23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)
---
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 8ccc108..6db3248 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -153,27 +153,28 @@ define_import(JSContext       *context,
  * we do this after the import succesfully completes.
  */
 static bool
-seal_import(JSContext  *context,
-            JSObject   *obj,
-            const char *name)
+seal_import(JSContext       *cx,
+            JS::HandleObject obj,
+            const char      *name)
 {
-    bool found;
-    unsigned attrs;
+    JS::Rooted<JSPropertyDescriptor> descr(cx);
 
-    if (!JS_GetPropertyAttributes(context, obj, name,
-                                  &attrs, &found) || !found) {
+    if (!JS_GetOwnPropertyDescriptor(cx, obj, name, &descr) ||
+        descr.object() == NULL) {
         gjs_debug(GJS_DEBUG_IMPORTER,
                   "Failed to get attributes to seal '%s' in importer",
                   name);
         return false;
     }
 
-    attrs |= JSPROP_PERMANENT;
+    /* COMPAT: in mozjs45 use .setConfigurable(false) and the form of
+     * JS_DefineProperty that takes the JSPropertyDescriptor directly */
 
-    if (!JS_SetPropertyAttributes(context, obj, name,
-                                  attrs, &found) || !found) {
+    if (!JS_DefineProperty(cx, descr.object(), name, descr.value(),
+                           descr.attributes() | JSPROP_PERMANENT,
+                           descr.getter(), descr.setter())) {
         gjs_debug(GJS_DEBUG_IMPORTER,
-                  "Failed to set attributes to seal '%s' in importer",
+                  "Failed to redefine attributes to seal '%s' in importer",
                   name);
         return false;
     }


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