diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index 9654cab8023..fe6c4045764 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -318,6 +318,11 @@ Load(JSContext *cx, unsigned argc, jsval *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]); @@ -337,23 +342,15 @@ Load(JSContext *cx, unsigned argc, jsval *vp) .setFileAndLine(filename.ptr(), 1) .setCompileAndGo(true); JS::Rooted script(cx); - JS::Compile(cx, obj, options, file, &script); + JS::Rooted 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; } } }