[gjs/mozjs91: 126/135] Use new Script private API
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/mozjs91: 126/135] Use new Script private API
- Date: Sat, 9 Oct 2021 22:09:02 +0000 (UTC)
commit e2811e475b4fbf8ee9154e351b1cd595e513f5fc
Author: Evan Welsh <contact evanwelsh com>
Date: Sat Aug 7 14:27:27 2021 -0700
Use new Script private API
Setting Script privates has been removed from CompileOptions
(see changeset below) in favor of a specific API for dynamic
imports JS::[Set, Get]ScripePrivate (bug 1482153).
Because we must manipulate the Script object itself we can no longer
use the JS::Evaluate wrapper to set our environment chain and instead
must use JS_ExecuteScript. Because our environment chain is
"non-syntactic" (it doesn't come from any JS syntax) we have to specify
this option. JS::Evaluate previously handled this for us in
js/src/vm/CompilationAndEvaluation.cpp by passing ScopeKind::NonSyntactic
in the override we used.
Changeset: https://phabricator.services.mozilla.com/D110459
See: https://bugzilla.mozilla.org/show_bug.cgi?id=1702278
See: https://bugzilla.mozilla.org/show_bug.cgi?id=1482153
gjs/context.cpp | 10 +++++++---
gjs/module.cpp | 15 +++++++++++----
2 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 58b3a677..3d780ef9 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -1458,7 +1458,7 @@ bool GjsContextPrivate::eval_with_scope(JS::HandleObject scope_object,
}
JS::CompileOptions options(m_cx);
- options.setFileAndLine(filename, 1);
+ options.setFileAndLine(filename, 1).setNonSyntacticScope(true);
GjsAutoUnref<GFile> file = g_file_new_for_commandline_arg(filename);
GjsAutoChar uri = g_file_get_uri(file);
@@ -1466,9 +1466,13 @@ bool GjsContextPrivate::eval_with_scope(JS::HandleObject scope_object,
if (!priv)
return false;
- options.setPrivateValue(JS::ObjectValue(*priv));
+ JS::RootedScript script(m_cx);
+ script.set(JS::Compile(m_cx, options, buf));
+ if (!script)
+ return false;
- if (!JS::Evaluate(m_cx, scope_chain, options, buf, retval))
+ JS::SetScriptPrivate(script, JS::ObjectValue(*priv));
+ if (!JS_ExecuteScript(m_cx, scope_chain, script, retval))
return false;
schedule_gc_if_needed();
diff --git a/gjs/module.cpp b/gjs/module.cpp
index 12473e7f..938b88ea 100644
--- a/gjs/module.cpp
+++ b/gjs/module.cpp
@@ -124,13 +124,19 @@ class GjsScriptModule {
}
JS::CompileOptions options(cx);
- options.setFileAndLine(filename, 1);
+ options.setFileAndLine(filename, 1).setNonSyntacticScope(true);
JS::RootedObject priv(cx, build_private(cx, uri));
- options.setPrivateValue(JS::ObjectValue(*priv));
+ if (!priv)
+ return false;
+
+ JS::RootedScript script(cx, JS::Compile(cx, options, buf));
+ if (!script)
+ return false;
+ JS::SetScriptPrivate(script, JS::ObjectValue(*priv));
JS::RootedValue ignored_retval(cx);
- if (!JS::Evaluate(cx, scope_chain, options, buf, &ignored_retval))
+ if (!JS_ExecuteScript(cx, scope_chain, script, &ignored_retval))
return false;
GjsContextPrivate* gjs = GjsContextPrivate::from_cx(cx);
@@ -232,7 +238,8 @@ class GjsScriptModule {
public:
/*
- * Creates a JS object to pass to JS::CompileOptions as a script's private.
+ * Creates a JS object to pass to JS::SetScriptPrivate as a script's
+ * private.
*/
GJS_JSAPI_RETURN_CONVENTION
static JSObject* build_private(JSContext* cx, const char* script_uri) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]