[gjs/mozjs91: 17/21] Adapt to new Maybe-based property descriptor API




commit 4b7b2f8d5638bd4fe8776423baaff2a562276aaa
Author: Evan Welsh <contact evanwelsh com>
Date:   Sat Jul 10 20:38:39 2021 -0700

    Adapt to new Maybe-based property descriptor API

 gi/gobject.cpp | 18 +++++++++++-------
 gjs/module.cpp | 14 +++++++++++---
 2 files changed, 22 insertions(+), 10 deletions(-)
---
diff --git a/gi/gobject.cpp b/gi/gobject.cpp
index ca359314..373664cb 100644
--- a/gi/gobject.cpp
+++ b/gi/gobject.cpp
@@ -58,28 +58,32 @@ static bool jsobj_set_gproperty(JSContext* cx, JS::HandleObject object,
     if (pspec->flags & G_PARAM_CONSTRUCT_ONLY) {
         unsigned flags = GJS_MODULE_PROP_FLAGS | JSPROP_READONLY;
         GjsAutoChar camel_name = gjs_hyphen_to_camel(pspec->name);
-        JS::Rooted<JS::PropertyDescriptor> jsprop(cx);
+        JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> jsprop(cx);
+        JS::RootedObject holder(cx);
 
         // Ensure to call any associated setter method
         if (!g_str_equal(underscore_name.get(), pspec->name)) {
-            if (!JS_GetPropertyDescriptor(cx, object, underscore_name, &jsprop))
+            if (!JS_GetPropertyDescriptor(cx, object, underscore_name, &jsprop,
+                                          &holder))
                 return false;
-            if (jsprop.setter() &&
+            if (jsprop.isSome() && jsprop.value().setter() &&
                 !JS_SetProperty(cx, object, underscore_name, jsvalue))
                 return false;
         }
 
         if (!g_str_equal(camel_name.get(), pspec->name)) {
-            if (!JS_GetPropertyDescriptor(cx, object, camel_name, &jsprop))
+            if (!JS_GetPropertyDescriptor(cx, object, camel_name, &jsprop,
+                                          &holder))
                 return false;
-            if (jsprop.setter() &&
+            if (jsprop.isSome() && jsprop.value().setter() &&
                 !JS_SetProperty(cx, object, camel_name, jsvalue))
                 return false;
         }
 
-        if (!JS_GetPropertyDescriptor(cx, object, pspec->name, &jsprop))
+        if (!JS_GetPropertyDescriptor(cx, object, pspec->name, &jsprop,
+                                      &holder))
             return false;
-        if (jsprop.setter() &&
+        if (jsprop.isSome() && jsprop.value().setter() &&
             !JS_SetProperty(cx, object, pspec->name, jsvalue))
             return false;
 
diff --git a/gjs/module.cpp b/gjs/module.cpp
index cba01409..5d22d28a 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -202,9 +202,17 @@ class GjsScriptModule {
                   "please fix your code anyway.",
                   gjs_debug_id(id).c_str(), m_name);
 
-        JS::Rooted<JS::PropertyDescriptor> desc(cx);
-        return JS_GetPropertyDescriptorById(cx, lexical, id, &desc) &&
-            JS_DefinePropertyById(cx, module, id, desc);
+        JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> desc(cx);
+        JS::Rooted<JS::PropertyDescriptor> desc_(cx);
+        JS::RootedObject holder(cx);
+
+        if (!JS_GetPropertyDescriptorById(cx, lexical, id, &desc, &holder) ||
+            desc.isNothing())
+            return false;
+
+        desc_.set(desc.value());
+
+        return JS_DefinePropertyById(cx, module, id, desc_);
     }
 
     GJS_JSAPI_RETURN_CONVENTION


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