diff options
author | Philip Chimento <philip.chimento@gmail.com> | 2017-03-19 05:18:36 +0000 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2017-05-05 23:26:30 -0700 |
commit | b69add89ddcd7afda1e1e698bb47a57532fff3db (patch) | |
tree | 224c49016b8395716c95506204a3a080bc0f74bb | |
parent | ac2f29b1e6ed3846173634986075166b1022ae11 (diff) | |
download | gjs-b69add89ddcd7afda1e1e698bb47a57532fff3db.tar.gz |
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.
-rw-r--r-- | gjs/importer.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/gjs/importer.cpp b/gjs/importer.cpp index a7f1a2b2..b9097a88 100644 --- a/gjs/importer.cpp +++ b/gjs/importer.cpp @@ -208,11 +208,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", @@ -220,13 +221,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); @@ -457,6 +454,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) { @@ -479,7 +477,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; @@ -496,6 +494,7 @@ static bool do_import(JSContext *context, JS::HandleObject obj, Importer *priv, + JS::HandleId id, const char *name) { char *filename; @@ -621,7 +620,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; @@ -829,7 +828,7 @@ importer_resolve(JSContext *context, } JSAutoRequest ar(context); - if (!do_import(context, obj, priv, name)) { + if (!do_import(context, obj, priv, id, name)) { g_free(name); return false; } |