Subject: [gjs/wip/ptomato/mozjs38: 4/17] js: Adapt to
new JS_DefinePropertyById() API



commit 7b6fb1ff181aaab5d6ee2bf19bee32d879b605a9
Author: Philip Chimento <[email protected]>
Date: Wed Jan 11 22:51:59 2017 -0800

js: Adapt to new JS_DefinePropertyById() API

Like JS_DefineProperty() could already, JS_DefinePropertyById() is now
overloaded to take several types as the property value. This allows us to
pass rooted objects directly in, in order to avoid creating temporary
JS::Values.

Also, JS_PropertyStub and JS_StrictPropertyStub are not allowed as values
for getter and setter. I previously thought that passing NULL for the
getter and setter was different than passing the stubs, but it doesn't
seem to make a difference after all.

gi/gerror.cpp | 6 +++---
gi/repo.cpp | 17 +++++------------
gjs/importer.cpp | 4 +---
gjs/jsapi-dynamic-class.cpp | 9 +++------
modules/system.cpp | 8 ++------
5 files changed, 14 insertions(+), 30 deletions(-)
---
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index 4e7e5c6..5ba56d1 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -417,13 +417,13 @@ define_error_properties(JSContext *context,
gjs_context_get_const_string(context, GJS_STRING_LINE_NUMBER));

JS_DefinePropertyById(context, obj, stack_name, stack,
- NULL, NULL, JSPROP_ENUMERATE);
+ JSPROP_ENUMERATE);

JS_DefinePropertyById(context, obj, filename_name, fileName,
- NULL, NULL, JSPROP_ENUMERATE);
+ JSPROP_ENUMERATE);

JS_DefinePropertyById(context, obj, linenumber_name, lineNumber,
- NULL, NULL, JSPROP_ENUMERATE);
+ JSPROP_ENUMERATE);
}

JSObject*
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 92add33..8c2e3e3 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -233,8 +233,6 @@ static JSObject*
repo_new(JSContext *context)
{
Repo *priv;
- JSObject *versions;
- JSObject *private_ns;
bool found;

JS::RootedObject global(context, gjs_get_import_global(context));
@@ -289,22 +287,17 @@ repo_new(JSContext *context)
gjs_debug_lifecycle(GJS_DEBUG_GREPO,
"repo constructor, obj %p priv %p", repo.get(), priv);

- versions = JS_NewObject(context, NULL, global);
+ JS::RootedObject versions(context, JS_NewObject(context, NULL, global));
JS::RootedId versions_name(context,
gjs_context_get_const_string(context, GJS_STRING_GI_VERSIONS));
- JS_DefinePropertyById(context, repo,
- versions_name,
- JS::ObjectValue(*versions),
- NULL, NULL,
+ JS_DefinePropertyById(context, repo, versions_name, versions,
JSPROP_PERMANENT);

- private_ns = JS_NewObject(context, NULL, global);
+ JS::RootedObject private_ns(context, JS_NewObject(context, NULL, global));
JS::RootedId private_ns_name(context,
gjs_context_get_const_string(context, GJS_STRING_PRIVATE_NS_MARKER));
- JS_DefinePropertyById(context, repo,
- private_ns_name,
- JS::ObjectValue(*private_ns),
- NULL, NULL, JSPROP_PERMANENT);
+ JS_DefinePropertyById(context, repo, private_ns_name, private_ns,
+ JSPROP_PERMANENT);

/* FIXME - hack to make namespaces load, since
* gobject-introspection does not yet search a path properly.
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 7a0e3e7..d8f9edb 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -380,8 +380,7 @@ load_module_init(JSContext *context,
goto out;

if (!JS_DefinePropertyById(context, in_object,
- module_init_name, JS::ObjectValue(*module_obj),
- NULL, NULL,
+ module_init_name, module_obj,
GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT))
goto out;

@@ -1173,7 +1172,6 @@ gjs_define_root_importer_object(JSContext *context,
gjs_context_get_const_string(context, GJS_STRING_IMPORTS));
if (!JS_DefinePropertyById(context, in_object,
imports_name, importer,
- NULL, NULL,
GJS_MODULE_PROP_FLAGS)) {
gjs_debug(GJS_DEBUG_IMPORTER, "DefineProperty imports on %p failed",
in_object.get());
diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp
index e53efcf..c219195 100644
--- a/gjs/jsapi-dynamic-class.cpp
+++ b/gjs/jsapi-dynamic-class.cpp
@@ -107,18 +107,15 @@ gjs_init_class_dynamic(JSContext *context,
goto out;

if (!JS_DefineProperty(context, constructor, "prototype", prototype,
- JSPROP_PERMANENT | JSPROP_READONLY,
- JS_PropertyStub, JS_StrictPropertyStub))
+ JSPROP_PERMANENT | JSPROP_READONLY))
goto out;
- if (!JS_DefineProperty(context, prototype, "constructor", constructor,
- 0, JS_PropertyStub, JS_StrictPropertyStub))
+ if (!JS_DefineProperty(context, prototype, "constructor", constructor, 0))
goto out;

/* The constructor defined by JS_InitClass has no property attributes, but
this
is a more useful default for gjs */
if (!JS_DefineProperty(context, in_object, class_name, constructor,
- GJS_MODULE_PROP_FLAGS,
- JS_PropertyStub, JS_StrictPropertyStub))
+ GJS_MODULE_PROP_FLAGS))
goto out;

res = true;
diff --git a/modules/system.cpp b/modules/system.cpp
index 7ab2e35..823585e 100644
--- a/modules/system.cpp
+++ b/modules/system.cpp
@@ -182,16 +182,12 @@ gjs_js_define_system_stuff(JSContext
*context,
if (!JS_DefineProperty(context, module,
"programInvocationName",
value,
- GJS_MODULE_PROP_FLAGS | JSPROP_READONLY,
- JS_PropertyStub,
- JS_StrictPropertyStub))
+ GJS_MODULE_PROP_FLAGS | JSPROP_READONLY))
goto out;

if (!JS_DefineProperty(context, module,
"version", GJS_VERSION,
- GJS_MODULE_PROP_FLAGS | JSPROP_READONLY,
- JS_PropertyStub,
- JS_StrictPropertyStub))
+ GJS_MODULE_PROP_FLAGS | JSPROP_READONLY))
goto out;

retval = true;
_______________________________________________
commits-list mailing list (read only)
https://mail.gnome.org/mailman/listinfo/commits-list

Want to limit the commits to a few modules? Go to above URL, log in to edit
your options and select the modules ('topics') you want.



Programming list archiving by: Enterprise Git Hosting