[gjs/wip/ptomato/mozjs45: 13/33] jsapi-util: Use new scope chain API instead of JS::Evaluate



commit 216701409f77d8c4cee8ec2670cb48726e5109fe
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Apr 16 23:08:54 2017 -0700

    jsapi-util: Use new scope chain API instead of JS::Evaluate
    
    In gjs_eval_with_scope(), we split up compilation from execution in order
    to be able to use the new scope chain API on JS_ExecuteScript. In
    SpiderMonkey 45, you cannot pass in a custom global object anymore to
    JS::Evaluate(). Instead, you can either use the context's global object,
    or pass in a "scope chain". The scope chain implicitly has the global
    object at the end. In our case, we can pass in a scope chain of one object
    to get the previous behaviour of gjs_eval_with_scope().
    
    There is also a scope chain variant of JS::Evaluate(), but it does not
    take a UTF-8 char * buffer.

 gjs/jsapi-util.cpp |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 4d59d59..b4c664d 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -936,7 +936,13 @@ gjs_eval_with_scope(JSContext             *context,
            .setFileAndLine(filename, start_line_number)
            .setSourceIsLazy(true);
 
-    if (!JS::Evaluate(context, eval_obj, options, script, script_len, retval))
+    JS::RootedScript compiled_script(context);
+    if (!JS::Compile(context, options, script, script_len, &compiled_script))
+        return false;
+
+    JS::AutoObjectVector scope_chain(context);
+    scope_chain.append(eval_obj);
+    if (!JS_ExecuteScript(context, scope_chain, compiled_script, retval))
         return false;
 
     gjs_schedule_gc_if_needed(context);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]