Bug 1143793 part 4. Stop supporting load.call(somerandomobj) in xpcshell. r=bholley

I guess I should have done this in bug 1097987.
This commit is contained in:
Boris Zbarsky 2015-03-19 10:13:34 -04:00
parent 2f422f4b65
commit f0a4481730

View File

@ -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<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;
}
}
}