[gjs/wip/ptomato/mozjs45: 15/33] FIXME - console: Evaluate on global object



commit f5690346e8786b2d420a96137c6fbd06a3d734a0
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Apr 16 23:13:48 2017 -0700

    FIXME - console: Evaluate on global object
    
    We previously evaluated typed-in scripts in the scope of the "this" object
    that was passed to Console.interact(), which would have been the Console
    module object. That is a strange thing to do. Instead, evaluate typed-in
    scripts in the scope of the global object.
    
    FIXME: See if we can evaluate in the global object scope elsewhere too.

 modules/console.cpp |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/modules/console.cpp b/modules/console.cpp
index 74e410a..8fd3fd4 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -159,10 +159,11 @@ gjs_console_interact(JSContext *context,
                      unsigned   argc,
                      JS::Value *vp)
 {
-    GJS_GET_THIS(context, argc, vp, argv, object);
+    JS::CallArgs argv = JS::CallArgsFromVp(argc, vp);
     bool eof = false;
     JS::RootedValue result(context);
     JS::RootedString str(context);
+    JS::RootedObject global(context, gjs_get_import_global(context));
     GString *buffer = NULL;
     char *temp_buf = NULL;
     int lineno;
@@ -191,12 +192,13 @@ gjs_console_interact(JSContext *context,
             g_string_append(buffer, temp_buf);
             g_free(temp_buf);
             lineno++;
-        } while (!JS_BufferIsCompilableUnit(context, object, buffer->str, buffer->len));
+        } while (!JS_BufferIsCompilableUnit(context, global,
+                                            buffer->str, buffer->len));
 
         JS::CompileOptions options(context);
         options.setUTF8(true)
                .setFileAndLine("typein", startline);
-        if (!JS::Evaluate(context, object, options, buffer->str, buffer->len,
+        if (!JS::Evaluate(context, global, options, buffer->str, buffer->len,
                           &result)) {
             /* If this was an uncatchable exception, throw another uncatchable
              * exception on up to the surrounding JS::Evaluate() in main(). This


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