[gjs] jsapi-util: Evaluate scripts in a new scope if NULL is passed for object



commit 60c0539527d474552c831a0eea32c3b66686e4bc
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Jan 15 15:04:45 2014 -0500

    jsapi-util: Evaluate scripts in a new scope if NULL is passed for object
    
    And make the gjs_context_eval (and more importantly, the console) execute
    the main function in a new scope, rather than the global scope.

 gjs/context.cpp    |    6 +-----
 gjs/jsapi-util.cpp |    6 +++---
 2 files changed, 4 insertions(+), 8 deletions(-)
---
diff --git a/gjs/context.cpp b/gjs/context.cpp
index e638c2a..b3d85b9 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -595,10 +595,7 @@ gjs_context_eval(GjsContext   *js_context,
 
     g_object_ref(G_OBJECT(js_context));
 
-    if (!gjs_eval_with_scope(js_context->context,
-                             js_context->global,
-                             script, script_len, filename,
-                             &retval)) {
+    if (!gjs_eval_with_scope(js_context->context, NULL, script, script_len, filename, &retval)) {
         gjs_log_exception(js_context->context);
         g_set_error(error,
                     GJS_ERROR,
@@ -611,7 +608,6 @@ gjs_context_eval(GjsContext   *js_context,
         if (JSVAL_IS_INT(retval)) {
             int code;
             if (JS_ValueToInt32(js_context->context, retval, &code)) {
-
                 gjs_debug(GJS_DEBUG_CONTEXT,
                           "Script returned integer code %d", code);
                 *exit_status_p = code;
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 19b0f89..7cd0d5d 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -1273,10 +1273,10 @@ gjs_eval_with_scope(JSContext    *context,
      */
     JS_BeginRequest(context);
 
-    if (!object)
-        object = JS_GetGlobalObject(context);
+    JSAutoCompartment ac(context, JS_GetGlobalObject(context));
 
-    JSAutoCompartment ac(context, object);
+    if (!object)
+        object = JS_NewObject(context, NULL, NULL, NULL);
 
     JS::CompileOptions options(context);
     options.setUTF8(true)


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