[gjs/mozjs91: 9/18] Adapt to new Maybe-based property descriptor API
- From: Evan Welsh <ewlsh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/mozjs91: 9/18] Adapt to new Maybe-based property descriptor API
- Date: Sat, 7 Aug 2021 22:15:39 +0000 (UTC)
commit 47f3ecda803072ef47c531cc892b41924f936155
Author: Evan Welsh <contact evanwelsh com>
Date: Sat Jul 10 20:38:39 2021 -0700
Adapt to new Maybe-based property descriptor API
object() was previously used to indicate whether a property descriptor
was found. Now it's indicated by whether the returned Maybe is Some or
Nothing and the descriptor object is returned separately in the holder
out-parameter.
See https://bugzilla.mozilla.org/show_bug.cgi?id=1706404
gi/gobject.cpp | 41 +++++++++++++++++++++++++----------------
gjs/importer.cpp | 12 ++++++++----
gjs/module.cpp | 11 ++++++-----
3 files changed, 39 insertions(+), 25 deletions(-)
---
diff --git a/gi/gobject.cpp b/gi/gobject.cpp
index ae5dad5a..9b8c7844 100644
--- a/gi/gobject.cpp
+++ b/gi/gobject.cpp
@@ -60,28 +60,38 @@ static bool jsobj_set_gproperty(JSContext* cx, JS::HandleObject object,
GjsAutoChar camel_name = gjs_hyphen_to_camel(pspec->name);
if (g_param_spec_get_qdata(pspec, ObjectBase::custom_property_quark())) {
- 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() &&
- !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))
- return false;
- if (jsprop.setter() &&
- !JS_SetProperty(cx, object, camel_name, jsvalue))
+ if (jsprop.isSome() && jsprop->setter() &&
+ !JS_SetProperty(cx, object, underscore_name, jsvalue)) {
return false;
+ }
}
- if (!JS_GetPropertyDescriptor(cx, object, pspec->name, &jsprop))
- return false;
- if (jsprop.setter() &&
+ if (!g_str_equal(camel_name.get(), pspec->name)) {
+ if (!JS_GetPropertyDescriptor(cx, object, camel_name, &jsprop,
+ &holder)) {
+ return false;
+ }
+
+ if (jsprop.isSome() && jsprop.value().setter() &&
+ !JS_SetProperty(cx, object, camel_name, jsvalue)) {
+ return false;
+ }
+ }
+
+ if (!JS_GetPropertyDescriptor(cx, object, pspec->name, &jsprop,
+ &holder))
+ return false;
+ if (jsprop.isSome() && jsprop.value().setter() &&
!JS_SetProperty(cx, object, pspec->name, jsvalue))
return false;
}
@@ -137,8 +147,7 @@ static GObject* gjs_object_constructor(
if (!constructor)
return nullptr;
- JS::RootedValue v_constructor(cx);
- v_constructor.setObject(*constructor);
+ JS::RootedValue v_constructor(cx, JS::ObjectValue(*constructor));
JS::RootedObject object(cx);
if (n_construct_properties) {
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index f21f6d6d..23947198 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -197,17 +197,21 @@ seal_import(JSContext *cx,
JS::HandleId id,
const char *name)
{
- JS::Rooted<JS::PropertyDescriptor> descr(cx);
+ JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> descr(cx);
- if (!JS_GetOwnPropertyDescriptorById(cx, obj, id, &descr) || !descr.object()) {
+ if (!JS_GetOwnPropertyDescriptorById(cx, obj, id, &descr) ||
+ descr.isNothing()) {
gjs_debug(GJS_DEBUG_IMPORTER,
"Failed to get attributes to seal '%s' in importer",
name);
return false;
}
- descr.setConfigurable(false);
- if (!JS_DefinePropertyById(cx, descr.object(), id, descr)) {
+ JS::Rooted<JS::PropertyDescriptor> descr_(cx, descr.value());
+
+ descr_.setConfigurable(false);
+
+ if (!JS_DefinePropertyById(cx, obj, id, descr_)) {
gjs_debug(GJS_DEBUG_IMPORTER,
"Failed to redefine attributes to seal '%s' in importer",
name);
diff --git a/gjs/module.cpp b/gjs/module.cpp
index 0e05fce0..68df0a11 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -175,9 +175,11 @@ class GjsScriptModule {
return true; /* nothing imported yet */
}
- if (!JS_HasPropertyById(cx, lexical, id, resolved))
+ JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> maybe_desc(cx);
+ JS::RootedObject holder(cx);
+ if (!JS_GetPropertyDescriptorById(cx, lexical, id, &maybe_desc, &holder))
return false;
- if (!*resolved)
+ if (maybe_desc.isNothing())
return true;
/* The property is present in the lexical environment. This should not
@@ -193,9 +195,8 @@ 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<JS::PropertyDescriptor> desc(cx, maybe_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]