Bug 1143793 part 6. Drop the obj argument of JS::Compile. r=luke

This is technically a behavior change for the shell's disfile() function, but
I really doubt anyone is doing disfile.call(someObj).
This commit is contained in:
Boris Zbarsky 2015-03-19 10:13:34 -04:00
parent 8699f29c8c
commit 58ae84cfe1
14 changed files with 52 additions and 60 deletions

View File

@ -1640,13 +1640,13 @@ nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
JS::Rooted<JSScript*> script(cx);
if (aRunInGlobalScope) {
if (!JS::Compile(cx, global, options, srcBuf, &script)) {
if (!JS::Compile(cx, options, srcBuf, &script)) {
return;
}
} else {
// We can't clone compile-and-go scripts.
options.setCompileAndGo(false);
if (!JS::Compile(cx, global, options, srcBuf, &script)) {
if (!JS::Compile(cx, options, srcBuf, &script)) {
return;
}
}

View File

@ -2826,7 +2826,7 @@ nsXULPrototypeScript::Compile(JS::SourceBufferHolder& aSrcBuf,
NS_ADDREF(aOffThreadReceiver);
} else {
JS::Rooted<JSScript*> script(cx);
if (!JS::Compile(cx, scope, options, aSrcBuf, &script))
if (!JS::Compile(cx, options, aSrcBuf, &script))
return NS_ERROR_OUT_OF_MEMORY;
Set(script);
}

View File

@ -167,12 +167,11 @@ Load(JSContext *cx,
JS_ReportError(cx, "cannot open file '%s' for reading", filename.ptr());
return false;
}
Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
JS::CompileOptions options(cx);
options.setUTF8(true)
.setFileAndLine(filename.ptr(), 1);
JS::Rooted<JSScript*> script(cx);
bool ok = JS::Compile(cx, obj, options, file, &script);
bool ok = JS::Compile(cx, options, file, &script);
fclose(file);
if (!ok)
return false;
@ -341,7 +340,7 @@ XPCShellEnvironment::ProcessFile(JSContext *cx,
options.setUTF8(true)
.setFileAndLine(filename, 1);
JS::Rooted<JSScript*> script(cx);
if (JS::Compile(cx, global, options, file, &script))
if (JS::Compile(cx, options, file, &script))
(void)JS_ExecuteScript(cx, script, &result);
return;

View File

@ -2276,7 +2276,7 @@ EvalReturningScope(JSContext *cx, unsigned argc, jsval *vp)
JS::SourceBufferHolder srcBuf(src, srclen, JS::SourceBufferHolder::NoOwnership);
RootedScript script(cx);
if (!JS::Compile(cx, cx->global(), options, srcBuf, &script))
if (!JS::Compile(cx, options, srcBuf, &script))
return false;
if (global) {
@ -2347,7 +2347,7 @@ ShellCloneAndExecuteScript(JSContext *cx, unsigned argc, Value *vp)
JS::SourceBufferHolder srcBuf(src, srclen, JS::SourceBufferHolder::NoOwnership);
RootedScript script(cx);
if (!JS::Compile(cx, cx->global(), options, srcBuf, &script))
if (!JS::Compile(cx, options, srcBuf, &script))
return false;
global = CheckedUnwrap(global);

View File

@ -107,7 +107,7 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile)
JS::CompileOptions options(cx);
options.setFileAndLine(script_filename, 1);
JS::RootedScript script(cx);
CHECK(JS::Compile(cx, global, options, script_filename, &script));
CHECK(JS::Compile(cx, options, script_filename, &script));
tempScript.remove();
return tryScript(script);
}
@ -122,7 +122,7 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile_empty)
JS::CompileOptions options(cx);
options.setFileAndLine(script_filename, 1);
JS::RootedScript script(cx);
CHECK(JS::Compile(cx, global, options, script_filename, &script));
CHECK(JS::Compile(cx, options, script_filename, &script));
tempScript.remove();
return tryScript(script);
}
@ -138,7 +138,7 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle)
JS::CompileOptions options(cx);
options.setFileAndLine(script_filename, 1);
JS::RootedScript script(cx);
CHECK(JS::Compile(cx, global, options, script_stream, &script));
CHECK(JS::Compile(cx, options, script_stream, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle)
@ -151,7 +151,7 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle_empty)
JS::CompileOptions options(cx);
options.setFileAndLine(script_filename, 1);
JS::RootedScript script(cx);
CHECK(JS::Compile(cx, global, options, script_stream, &script));
CHECK(JS::Compile(cx, options, script_stream, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle_empty)
@ -165,7 +165,7 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandleForPrincip
JS::CompileOptions options(cx);
options.setFileAndLine("temporary file", 1);
JS::RootedScript script(cx);
CHECK(JS::Compile(cx, global, options, script_stream, &script));
CHECK(JS::Compile(cx, options, script_stream, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandleForPrincipals)

View File

@ -30,7 +30,7 @@ BEGIN_TEST(test_ubiNodeZone)
RootedString string1(cx, JS_NewStringCopyZ(cx, "Simpson's Individual Stringettes!"));
CHECK(string1);
RootedScript script1(cx);
CHECK(JS::Compile(cx, global1, options, "", 0, &script1));
CHECK(JS::Compile(cx, options, "", 0, &script1));
{
// ... and then enter global2's zone and create a string and script
@ -40,7 +40,7 @@ BEGIN_TEST(test_ubiNodeZone)
RootedString string2(cx, JS_NewStringCopyZ(cx, "A million household uses!"));
CHECK(string2);
RootedScript script2(cx);
CHECK(JS::Compile(cx, global2, options, "", 0, &script2));
CHECK(JS::Compile(cx, options, "", 0, &script2));
CHECK(JS::ubi::Node(string1).zone() == global1->zone());
CHECK(JS::ubi::Node(script1).zone() == global1->zone());
@ -71,7 +71,7 @@ BEGIN_TEST(test_ubiNodeCompartment)
// Create a script in the original compartment...
RootedScript script1(cx);
CHECK(JS::Compile(cx, global1, options, "", 0, &script1));
CHECK(JS::Compile(cx, options, "", 0, &script1));
{
// ... and then enter global2's compartment and create a script
@ -79,7 +79,7 @@ BEGIN_TEST(test_ubiNodeCompartment)
JSAutoCompartment ac(cx, global2);
RootedScript script2(cx);
CHECK(JS::Compile(cx, global2, options, "", 0, &script2));
CHECK(JS::Compile(cx, options, "", 0, &script2));
CHECK(JS::ubi::Node(script1).compartment() == global1->compartment());
CHECK(JS::ubi::Node(script2).compartment() == global2->compartment());

View File

@ -3750,30 +3750,29 @@ JS::CompileOptions::CompileOptions(JSContext *cx, JSVersion version)
}
bool
JS::Compile(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
JS::Compile(JSContext *cx, const ReadOnlyCompileOptions &options,
SourceBufferHolder &srcBuf, MutableHandleScript script)
{
MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj);
AutoLastFrameCheck lfc(cx);
script.set(frontend::CompileScript(cx, &cx->tempLifoAlloc(), obj, NullPtr(), NullPtr(),
options, srcBuf));
script.set(frontend::CompileScript(cx, &cx->tempLifoAlloc(), cx->global(),
NullPtr(), NullPtr(), options, srcBuf));
return !!script;
}
bool
JS::Compile(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
JS::Compile(JSContext *cx, const ReadOnlyCompileOptions &options,
const char16_t *chars, size_t length, MutableHandleScript script)
{
SourceBufferHolder srcBuf(chars, length, SourceBufferHolder::NoOwnership);
return Compile(cx, obj, options, srcBuf, script);
return Compile(cx, options, srcBuf, script);
}
bool
JS::Compile(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options,
JS::Compile(JSContext *cx, const ReadOnlyCompileOptions &options,
const char *bytes, size_t length, MutableHandleScript script)
{
mozilla::UniquePtr<char16_t, JS::FreePolicy> chars;
@ -3784,22 +3783,22 @@ JS::Compile(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optio
if (!chars)
return false;
return Compile(cx, obj, options, chars.get(), length, script);
return Compile(cx, options, chars.get(), length, script);
}
bool
JS::Compile(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &options, FILE *fp,
JS::Compile(JSContext *cx, const ReadOnlyCompileOptions &options, FILE *fp,
MutableHandleScript script)
{
FileContents buffer(cx);
if (!ReadCompleteFile(cx, fp, buffer))
return false;
return Compile(cx, obj, options, buffer.begin(), buffer.length(), script);
return Compile(cx, options, buffer.begin(), buffer.length(), script);
}
bool
JS::Compile(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optionsArg, const char *filename,
JS::Compile(JSContext *cx, const ReadOnlyCompileOptions &optionsArg, const char *filename,
MutableHandleScript script)
{
AutoFile file;
@ -3807,7 +3806,7 @@ JS::Compile(JSContext *cx, HandleObject obj, const ReadOnlyCompileOptions &optio
return false;
CompileOptions options(cx, optionsArg);
options.setFileAndLine(filename, 1);
return Compile(cx, obj, options, file.fp(), script);
return Compile(cx, options, file.fp(), script);
}
JS_PUBLIC_API(bool)
@ -3864,14 +3863,14 @@ JS_PUBLIC_API(bool)
JS_CompileScript(JSContext *cx, const char *ascii, size_t length,
const JS::CompileOptions &options, MutableHandleScript script)
{
return Compile(cx, cx->global(), options, ascii, length, script);
return Compile(cx, options, ascii, length, script);
}
JS_PUBLIC_API(bool)
JS_CompileUCScript(JSContext *cx, const char16_t *chars, size_t length,
const JS::CompileOptions &options, MutableHandleScript script)
{
return Compile(cx, cx->global(), options, chars, length, script);
return Compile(cx, options, chars, length, script);
}
JS_PUBLIC_API(bool)

View File

@ -803,7 +803,7 @@ namespace JS {
// size_t length = 512;
// char16_t* chars = static_cast<char16_t*>(js_malloc(sizeof(char16_t) * length));
// JS::SourceBufferHolder srcBuf(chars, length, JS::SourceBufferHolder::GiveOwnership);
// JS::Compile(cx, obj, options, srcBuf);
// JS::Compile(cx, options, srcBuf);
//
class MOZ_STACK_CLASS SourceBufferHolder MOZ_FINAL
{
@ -3590,23 +3590,23 @@ class MOZ_STACK_CLASS JS_FRIEND_API(CompileOptions) : public ReadOnlyCompileOpti
* |script| will always be set. On failure, it will be set to nullptr.
*/
extern JS_PUBLIC_API(bool)
Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
Compile(JSContext *cx, const ReadOnlyCompileOptions &options,
SourceBufferHolder &srcBuf, JS::MutableHandleScript script);
extern JS_PUBLIC_API(bool)
Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
Compile(JSContext *cx, const ReadOnlyCompileOptions &options,
const char *bytes, size_t length, JS::MutableHandleScript script);
extern JS_PUBLIC_API(bool)
Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options,
Compile(JSContext *cx, const ReadOnlyCompileOptions &options,
const char16_t *chars, size_t length, JS::MutableHandleScript script);
extern JS_PUBLIC_API(bool)
Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, FILE *file,
Compile(JSContext *cx, const ReadOnlyCompileOptions &options, FILE *file,
JS::MutableHandleScript script);
extern JS_PUBLIC_API(bool)
Compile(JSContext *cx, JS::HandleObject obj, const ReadOnlyCompileOptions &options, const char *filename,
Compile(JSContext *cx, const ReadOnlyCompileOptions &options, const char *filename,
JS::MutableHandleScript script);
extern JS_PUBLIC_API(bool)

View File

@ -454,7 +454,7 @@ RunFile(JSContext *cx, const char *filename, FILE *file, bool compileOnly)
.setNoScriptRval(true);
gGotError = false;
(void) JS::Compile(cx, cx->global(), options, file, &script);
(void) JS::Compile(cx, options, file, &script);
MOZ_ASSERT_IF(!script, gGotError);
}
@ -484,7 +484,7 @@ EvalAndPrint(JSContext *cx, const char *bytes, size_t length,
.setCompileAndGo(true)
.setFileAndLine("typein", lineno);
RootedScript script(cx);
if (!JS::Compile(cx, cx->global(), options, bytes, length, &script))
if (!JS::Compile(cx, options, bytes, length, &script))
return false;
if (compileOnly)
return true;
@ -869,7 +869,7 @@ LoadScript(JSContext *cx, unsigned argc, jsval *vp, bool scriptRelative)
.setNoScriptRval(true);
RootedScript script(cx);
RootedValue unused(cx);
if ((compileOnly && !Compile(cx, cx->global(), opts, filename.ptr(), &script)) ||
if ((compileOnly && !Compile(cx, opts, filename.ptr(), &script)) ||
!Evaluate(cx, opts, filename.ptr(), &unused))
{
return false;
@ -1291,7 +1291,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
script = JS_DecodeScript(cx, loadBuffer, loadLength);
} else {
mozilla::Range<const char16_t> chars = codeChars.twoByteRange();
(void) JS::Compile(cx, global, options, chars.start().get(), chars.length(), &script);
(void) JS::Compile(cx, options, chars.start().get(), chars.length(), &script);
}
if (!script)
@ -2364,10 +2364,6 @@ DisassFile(JSContext *cx, unsigned argc, jsval *vp)
return true;
}
RootedObject thisobj(cx, JS_THIS_OBJECT(cx, vp));
if (!thisobj)
return false;
// We should change DisassembleOptionParser to store CallArgs.
JSString *str = JS::ToString(cx, HandleValue::fromMarkedLocation(&p.argv[0]));
if (!str)
@ -2385,7 +2381,7 @@ DisassFile(JSContext *cx, unsigned argc, jsval *vp)
.setCompileAndGo(true)
.setNoScriptRval(true);
if (!JS::Compile(cx, thisobj, options, filename.ptr(), &script))
if (!JS::Compile(cx, options, filename.ptr(), &script))
return false;
}
@ -2813,7 +2809,7 @@ WorkerMain(void *arg)
.setCompileAndGo(true);
RootedScript script(cx);
if (!JS::Compile(cx, global, options, input->chars, input->length, &script))
if (!JS::Compile(cx, options, input->chars, input->length, &script))
break;
RootedValue result(cx);
JS_ExecuteScript(cx, script, &result);

View File

@ -661,11 +661,10 @@ js::ExecuteKernel(JSContext *cx, HandleScript script, JSObject &scopeChainArg, c
bool
js::Execute(JSContext *cx, HandleScript script, JSObject &scopeChainArg, Value *rval)
{
/* The scope chain could be anything, so innerize just in case. */
/* The scope chain is something we control, so we know it can't
have any outer objects on it. */
RootedObject scopeChain(cx, &scopeChainArg);
scopeChain = GetInnerObject(scopeChain);
if (!scopeChain)
return false;
MOZ_ASSERT(scopeChain == GetInnerObject(scopeChain));
MOZ_RELEASE_ASSERT(scopeChain->is<GlobalObject>() || !script->compileAndGo(),
"Only non-compile-and-go scripts can be executed with "

View File

@ -1179,7 +1179,7 @@ JSRuntime::initSelfHosting(JSContext *cx)
char *filename = getenv("MOZ_SELFHOSTEDJS");
if (filename) {
RootedScript script(cx);
if (Compile(cx, shg, options, filename, &script))
if (Compile(cx, options, filename, &script))
ok = Execute(cx, script, *shg.get(), rv.address());
} else {
uint32_t srcLen = GetRawScriptsSize();

View File

@ -779,7 +779,7 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo &aInfo,
}
if (!mReuseLoaderGlobal) {
Compile(cx, obj, options, buf, fileSize32, &script);
Compile(cx, options, buf, fileSize32, &script);
} else {
// Note: exceptions will get handled further down;
// don't early return for them here.
@ -829,8 +829,7 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo &aInfo,
}
if (!mReuseLoaderGlobal) {
script = Compile(cx, obj, options, buf,
fileSize32);
script = Compile(cx, options, buf, fileSize32);
} else {
// Note: exceptions will get handled further down;
// don't early return for them here.
@ -875,7 +874,7 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo &aInfo,
buf[len] = '\0';
if (!mReuseLoaderGlobal) {
Compile(cx, obj, options, buf, bytesRead, &script);
Compile(cx, options, buf, bytesRead, &script);
} else {
// Note: exceptions will get handled further down;
// don't early return for them here.

View File

@ -177,7 +177,7 @@ mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *targetObj
}
if (!reuseGlobal) {
JS::Compile(cx, target_obj, options, srcBuf, script);
JS::Compile(cx, options, srcBuf, script);
} else {
AutoObjectVector scopeChain(cx);
if (!JS_IsGlobalObject(target_obj) &&
@ -193,7 +193,7 @@ mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *targetObj
// the lazy source loader doesn't know the encoding.
if (!reuseGlobal) {
options.setSourceIsLazy(true);
JS::Compile(cx, target_obj, options, buf.get(), len, script);
JS::Compile(cx, options, buf.get(), len, script);
} else {
AutoObjectVector scopeChain(cx);
if (!JS_IsGlobalObject(target_obj) &&

View File

@ -343,7 +343,7 @@ Load(JSContext *cx, unsigned argc, jsval *vp)
.setCompileAndGo(true);
JS::Rooted<JSScript*> script(cx);
JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
JS::Compile(cx, global, options, file, &script);
JS::Compile(cx, options, file, &script);
fclose(file);
if (!script)
return false;
@ -834,7 +834,7 @@ ProcessFile(JSContext *cx, const char *filename, FILE *file, bool forceTTY)
options.setUTF8(true)
.setFileAndLine(filename, 1)
.setCompileAndGo(true);
if (JS::Compile(cx, global, options, file, &script) && !compileOnly)
if (JS::Compile(cx, options, file, &script) && !compileOnly)
(void)JS_ExecuteScript(cx, script, &result);
JS_EndRequest(cx);