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



commit 5b2dc43321bbfb3d11c9c836b58d935118030e2a
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 a0d33a3..09e2b52 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]