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



commit c5425f2ec6ea10b575dfa50abfe8a528d7ca171e
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 d1ebc6d..b25a97e 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]