[gjs/mozjs91: 70/87] Use new Script private API




commit 1fbe6cb99a83a6ee82f50c89ad4a053c18056ad7
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]ScriptPrivate (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 401d3284..24210b9c 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -1464,7 +1464,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);
@@ -1472,9 +1472,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 6d5fe262..51884958 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);
@@ -230,7 +236,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]