Bug 1143793 part 4. Stop supporting load.call(somerandomobj) in xpcshell. r=bholley
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 19 Mar 2015 10:13:34 -0400
changeset 234483 55efc4756e69b7b710dd1bc874bd587b5632ced8
parent 234482 909ca1afa40ffe9c09cfb9ad7273aed9a8524a84
child 234484 7f2b308acde09ec683d4094be51021ea53d310dc
push id28446
push userkwierso@gmail.com
push dateFri, 20 Mar 2015 02:15:45 +0000
treeherdermozilla-central@3257d9c4b257 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1143793, 1097987
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1143793 part 4. Stop supporting load.call(somerandomobj) in xpcshell. r=bholley I guess I should have done this in bug 1097987.
js/xpconnect/src/XPCShellImpl.cpp
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -313,16 +313,21 @@ static bool
 Load(JSContext *cx, unsigned argc, jsval *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
     JS::Rooted<JSObject*> obj(cx, JS_THIS_OBJECT(cx, vp));
     if (!obj)
         return false;
 
+    if (!JS_IsGlobalObject(obj)) {
+        JS_ReportError(cx, "Trying to load() into a non-global object");
+        return false;
+    }
+
     RootedString str(cx);
     for (unsigned i = 0; i < args.length(); i++) {
         str = ToString(cx, args[i]);
         if (!str)
             return false;
         JSAutoByteString filename(cx, str);
         if (!filename)
             return false;
@@ -332,33 +337,25 @@ Load(JSContext *cx, unsigned argc, jsval
                            filename.ptr());
             return false;
         }
         JS::CompileOptions options(cx);
         options.setUTF8(true)
                .setFileAndLine(filename.ptr(), 1)
                .setCompileAndGo(true);
         JS::Rooted<JSScript*> script(cx);
-        JS::Compile(cx, obj, options, file, &script);
+        JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
+        JS::Compile(cx, global, options, file, &script);
         fclose(file);
         if (!script)
             return false;
 
         if (!compileOnly) {
-            // XXXbz are we intentionally allowing load.call(someNonGlobalObject)?
-            if (JS_IsGlobalObject(obj)) {
-                if (!JS_ExecuteScript(cx, script)) {
-                    return false;
-                }
-            } else {
-                JS::AutoObjectVector scopeChain(cx);
-                if (!scopeChain.append(obj) ||
-                    !JS_ExecuteScript(cx, scopeChain, script)) {
-                    return false;
-                }
+            if (!JS_ExecuteScript(cx, script)) {
+                return false;
             }
         }
     }
     args.rval().setUndefined();
     return true;
 }
 
 static bool