[gjs/wip/ptomato/mozjs52: 20/35] importer: Seal import with JSPropertyDescriptor directly
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs52: 20/35] importer: Seal import with JSPropertyDescriptor directly
- Date: Sun, 11 Jun 2017 03:13:53 +0000 (UTC)
commit f28a50ed8497bef3b0ba25277f4e3e2fa3c5ab3b
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Mar 19 05:18:36 2017 +0000
importer: Seal import with JSPropertyDescriptor directly
Previously we "sealed" the import by redefining the property on the
importer object so that it was undeleteable. Now we can do this in a more
direct way by getting and modifying the property's descriptor.
In order to make this more convenient and faster we thread the jsid
through the call stack so we don't have to convert it to and from a
string.
gjs/importer.cpp | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index bf8460c..442bcc5 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -206,11 +206,12 @@ define_import(JSContext *context,
static bool
seal_import(JSContext *cx,
JS::HandleObject obj,
+ JS::HandleId id,
const char *name)
{
JS::Rooted<JSPropertyDescriptor> descr(cx);
- if (!JS_GetOwnPropertyDescriptor(cx, obj, name, &descr) ||
+ if (!JS_GetOwnPropertyDescriptorById(cx, obj, id, &descr) ||
descr.object() == NULL) {
gjs_debug(GJS_DEBUG_IMPORTER,
"Failed to get attributes to seal '%s' in importer",
@@ -218,13 +219,9 @@ seal_import(JSContext *cx,
return false;
}
- /* COMPAT: in mozjs45 use .setConfigurable(false) and the form of
- * JS_DefineProperty that takes the JSPropertyDescriptor directly */
+ descr.setConfigurable(false);
- if (!JS_DefineProperty(cx, descr.object(), name, descr.value(),
- descr.attributes() | JSPROP_PERMANENT,
- JS_PROPERTYOP_GETTER(descr.getter()),
- JS_PROPERTYOP_SETTER(descr.setter()))) {
+ if (!JS_DefinePropertyById(cx, descr.object(), id, descr)) {
gjs_debug(GJS_DEBUG_IMPORTER,
"Failed to redefine attributes to seal '%s' in importer",
name);
@@ -454,6 +451,7 @@ import_symbol_from_init_js(JSContext *cx,
static bool
import_file_on_module(JSContext *context,
JS::HandleObject obj,
+ JS::HandleId id,
const char *name,
GFile *file)
{
@@ -476,7 +474,7 @@ import_file_on_module(JSContext *context,
0, 0))
goto out;
- if (!seal_import(context, obj, name))
+ if (!seal_import(context, obj, id, name))
goto out;
retval = true;
@@ -493,6 +491,7 @@ static bool
do_import(JSContext *context,
JS::HandleObject obj,
Importer *priv,
+ JS::HandleId id,
const char *name)
{
char *filename;
@@ -616,7 +615,7 @@ do_import(JSContext *context,
continue;
}
- if (import_file_on_module (context, obj, name, gfile)) {
+ if (import_file_on_module(context, obj, id, name, gfile)) {
gjs_debug(GJS_DEBUG_IMPORTER,
"successfully imported module '%s'", name);
result = true;
@@ -820,7 +819,7 @@ importer_resolve(JSContext *context,
}
JSAutoRequest ar(context);
- if (!do_import(context, obj, priv, name))
+ if (!do_import(context, obj, priv, id, name))
return false;
*resolved = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]