Bug 938907 - Get rid of the compile and go flag on ContextOptions; r=bholley

This commit is contained in:
Eddy Bruel 2013-11-19 12:41:42 +01:00
parent ae6cf6c2e9
commit cf91a893bd
14 changed files with 151 additions and 185 deletions

View File

@ -373,9 +373,10 @@ XPCShellEnvironment::ProcessFile(JSContext *cx,
/* Clear any pending exception from previous failed compiles. */
JS_ClearPendingException(cx);
script =
JS_CompileScriptForPrincipals(cx, obj, env->GetPrincipal(), buffer,
strlen(buffer), "typein", startline);
JS::CompileOptions options(cx);
options.setFileAndLine("typein", startline)
.setPrincipals(env->GetPrincipal());
script = JS_CompileScript(cx, obj, buffer, strlen(buffer), options);
if (script) {
JSErrorReporter older;
@ -583,10 +584,11 @@ XPCShellEnvironment::EvaluateString(const nsString& aString,
JS::Rooted<JSObject*> global(cx, GetGlobalObject());
JSAutoCompartment ac(cx, global);
JSScript* script =
JS_CompileUCScriptForPrincipals(cx, global, GetPrincipal(),
aString.get(), aString.Length(),
"typein", 0);
JS::CompileOptions options(cx);
options.setFileAndLine("typein", 0)
.setPrincipals(GetPrincipal());
JSScript* script = JS_CompileUCScript(cx, global, aString.get(),
aString.Length(), options);
if (!script) {
return false;
}

View File

@ -1009,8 +1009,10 @@ jsdScript::CreatePPLineMap()
"arg5", "arg6", "arg7", "arg8",
"arg9", "arg10", "arg11", "arg12"
};
JS::CompileOptions options(cx);
options.setFileAndLine("x-jsd:ppbuffer?type=function", 3);
fun = JS_CompileUCFunction (cx, obj, "ppfun", nargs, argnames, chars,
length, "x-jsd:ppbuffer?type=function", 3);
length, options);
if (!fun || !(script = JS_GetFunctionScript(cx, fun)))
return nullptr;
baseLine = 3;
@ -1030,7 +1032,9 @@ jsdScript::CreatePPLineMap()
}
JS::Anchor<JSString *> kungFuDeathGrip(jsstr);
script = JS_CompileUCScript (cx, obj, chars, length, "x-jsd:ppbuffer?type=script", 1);
JS::CompileOptions options(cx);
options.setFileAndLine("x-jsd:ppbuffer?type=script", 1);
script = JS_CompileUCScript(cx, obj, chars, length, options);
if (!script)
return nullptr;
baseLine = 1;
@ -1647,7 +1651,6 @@ jsdContext::GetJSContext(JSContext **_rval)
#define JSOPTION_WERROR JS_BIT(1)
#define JSOPTION_VAROBJFIX JS_BIT(2)
#define JSOPTION_PRIVATE_IS_NSISUPPORTS JS_BIT(3)
#define JSOPTION_COMPILE_N_GO JS_BIT(4)
#define JSOPTION_DONT_REPORT_UNCAUGHT JS_BIT(8)
#define JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT JS_BIT(11)
#define JSOPTION_NO_SCRIPT_RVAL JS_BIT(12)
@ -1666,7 +1669,6 @@ jsdContext::GetOptions(uint32_t *_rval)
| (JS::ContextOptionsRef(mJSCx).werror() ? JSOPTION_WERROR : 0)
| (JS::ContextOptionsRef(mJSCx).varObjFix() ? JSOPTION_VAROBJFIX : 0)
| (JS::ContextOptionsRef(mJSCx).privateIsNSISupports() ? JSOPTION_PRIVATE_IS_NSISUPPORTS : 0)
| (JS::ContextOptionsRef(mJSCx).compileAndGo() ? JSOPTION_COMPILE_N_GO : 0)
| (JS::ContextOptionsRef(mJSCx).dontReportUncaught() ? JSOPTION_DONT_REPORT_UNCAUGHT : 0)
| (JS::ContextOptionsRef(mJSCx).noDefaultCompartmentObject() ? JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT : 0)
| (JS::ContextOptionsRef(mJSCx).noScriptRval() ? JSOPTION_NO_SCRIPT_RVAL : 0)
@ -1692,7 +1694,6 @@ jsdContext::SetOptions(uint32_t options)
JS::ContextOptionsRef(mJSCx).setExtraWarnings(options & JSOPTION_EXTRA_WARNINGS)
.setWerror(options & JSOPTION_WERROR)
.setVarObjFix(options & JSOPTION_VAROBJFIX)
.setCompileAndGo(options & JSOPTION_COMPILE_N_GO)
.setDontReportUncaught(options & JSOPTION_DONT_REPORT_UNCAUGHT)
.setNoDefaultCompartmentObject(options & JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT)
.setNoScriptRval(options & JSOPTION_NO_SCRIPT_RVAL)

View File

@ -64,9 +64,11 @@ BEGIN_TEST(testChromeBuffer)
const char *paramName = "x";
const char *bytes = "return x ? 1 + trusted(x-1) : 0";
JS::HandleObject global = JS::HandleObject::fromMarkedLocation(&trusted_glob);
CHECK(fun = JS_CompileFunctionForPrincipals(cx, global, &system_principals,
"trusted", 1, &paramName, bytes, strlen(bytes),
"", 0));
JS::CompileOptions options(cx);
options.setFileAndLine("", 0)
.setPrincipals(&system_principals);
CHECK(fun = JS_CompileFunction(cx, global, "trusted", 1, &paramName,
bytes, strlen(bytes), options));
trusted_fun = JS_GetFunctionObject(fun);
if (!JS_AddNamedObjectRoot(cx, &trusted_fun, "trusted-function"))
return false;
@ -85,8 +87,10 @@ BEGIN_TEST(testChromeBuffer)
" return -1; "
" } "
"} ";
JS::CompileOptions options(cx);
options.setFileAndLine("", 0);
CHECK(fun = JS_CompileFunction(cx, global, "untrusted", 1, &paramName,
bytes, strlen(bytes), "", 0));
bytes, strlen(bytes), options));
JS::RootedValue rval(cx);
CHECK(JS_CallFunction(cx, nullptr, fun, 1, v.address(), rval.address()));
@ -107,9 +111,11 @@ BEGIN_TEST(testChromeBuffer)
" return 'From trusted: ' + e; "
"} ";
JS::HandleObject global = JS::HandleObject::fromMarkedLocation(&trusted_glob);
CHECK(fun = JS_CompileFunctionForPrincipals(cx, global, &system_principals,
"trusted", 1, &paramName, bytes, strlen(bytes),
"", 0));
JS::CompileOptions options(cx);
options.setFileAndLine("", 0)
.setPrincipals(&system_principals);
CHECK(fun = JS_CompileFunction(cx, global, "trusted", 1, &paramName,
bytes, strlen(bytes), options));
trusted_fun = JS_GetFunctionObject(fun);
}
@ -122,8 +128,10 @@ BEGIN_TEST(testChromeBuffer)
"} catch (e) { "
" return trusted(untrusted); "
"} ";
JS::CompileOptions options(cx);
options.setFileAndLine("", 0);
CHECK(fun = JS_CompileFunction(cx, global, "untrusted", 1, &paramName,
bytes, strlen(bytes), "", 0));
bytes, strlen(bytes), options));
JS::RootedValue rval(cx);
CHECK(JS_CallFunction(cx, nullptr, fun, 1, v.address(), rval.address()));
@ -141,9 +149,11 @@ BEGIN_TEST(testChromeBuffer)
JSAutoCompartment ac(cx, trusted_glob);
const char *bytes = "return 42";
JS::HandleObject global = JS::HandleObject::fromMarkedLocation(&trusted_glob);
CHECK(fun = JS_CompileFunctionForPrincipals(cx, global, &system_principals,
"trusted", 0, nullptr,
bytes, strlen(bytes), "", 0));
JS::CompileOptions options(cx);
options.setFileAndLine("", 0)
.setPrincipals(&system_principals);
CHECK(fun = JS_CompileFunction(cx, global, "trusted", 0, nullptr,
bytes, strlen(bytes), options));
trusted_fun = JS_GetFunctionObject(fun);
}
@ -156,8 +166,10 @@ BEGIN_TEST(testChromeBuffer)
"} catch (e) { "
" return f(); "
"} ";
JS::CompileOptions options(cx);
options.setFileAndLine("", 0);
CHECK(fun = JS_CompileFunction(cx, global, "untrusted", 1, &paramName,
bytes, strlen(bytes), "", 0));
bytes, strlen(bytes), options));
JS::RootedValue arg(cx, JS::ObjectValue(*callTrusted));
JS::RootedValue rval(cx);

View File

@ -33,8 +33,10 @@ BEGIN_TEST(test_cloneScript)
{
JSAutoCompartment a(cx, A);
JSFunction *fun;
CHECK(fun = JS_CompileFunction(cx, A, "f", 0, nullptr, source, strlen(source),
__FILE__, 1));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, 1);
CHECK(fun = JS_CompileFunction(cx, A, "f", 0, nullptr, source,
strlen(source), options));
CHECK(obj = JS_GetFunctionObject(fun));
}
@ -104,9 +106,12 @@ BEGIN_TEST(test_cloneScriptWithPrincipals)
// Compile in A
{
JSAutoCompartment a(cx, A);
JS::RootedFunction fun(cx, JS_CompileFunctionForPrincipals(cx, A, principalsA, "f",
mozilla::ArrayLength(argnames), argnames,
source, strlen(source), __FILE__, 1));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, 1)
.setPrincipals(principalsA);
JS::RootedFunction fun(cx, JS_CompileFunction(cx, A, "f",
mozilla::ArrayLength(argnames), argnames, source,
strlen(source), options));
CHECK(fun);
JSScript *script;

View File

@ -36,23 +36,26 @@ BEGIN_TEST(test_enclosingFunction)
RootedFunction fun(cx);
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
const char s1chars[] = "checkEnclosing()";
fun = JS_CompileFunction(cx, global, "s1", 0, nullptr, s1chars, strlen(s1chars),
__FILE__, __LINE__);
fun = JS_CompileFunction(cx, global, "s1", 0, nullptr, s1chars,
strlen(s1chars), options);
CHECK(fun);
EXEC("s1()");
CHECK(found == JS_GetFunctionScript(cx, fun));
const char s2chars[] = "return function() { checkEnclosing() }";
fun = JS_CompileFunction(cx, global, "s2", 0, nullptr, s2chars, strlen(s2chars),
__FILE__, __LINE__);
fun = JS_CompileFunction(cx, global, "s2", 0, nullptr, s2chars,
strlen(s2chars), options);
CHECK(fun);
EXEC("s2()()");
CHECK(found == JS_GetFunctionScript(cx, fun));
const char s3chars[] = "return function() { let (x) { function g() { checkEnclosing() } return g() } }";
fun = JS_CompileFunction(cx, global, "s3", 0, nullptr, s3chars, strlen(s3chars),
__FILE__, __LINE__);
fun = JS_CompileFunction(cx, global, "s3", 0, nullptr, s3chars,
strlen(s3chars), options);
CHECK(fun);
EXEC("s3()()");
CHECK(found == JS_GetFunctionScript(cx, fun));

View File

@ -37,7 +37,10 @@ BEGIN_TEST(testScriptInfo)
{
unsigned startLine = 1000;
JS::RootedScript script(cx, JS_CompileScript(cx, global, code, strlen(code), __FILE__, startLine));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, startLine);
JS::RootedScript script(cx, JS_CompileScript(cx, global, code, strlen(code),
options));
CHECK(script);

View File

@ -40,47 +40,56 @@ jschar ScriptObjectFixture::uc_code[ScriptObjectFixture::code_size];
BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript)
{
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
return tryScript(global, JS_CompileScript(cx, global, code, code_size,
__FILE__, __LINE__));
options));
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript)
BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript_empty)
{
return tryScript(global, JS_CompileScript(cx, global, "", 0,
__FILE__, __LINE__));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
return tryScript(global, JS_CompileScript(cx, global, "", 0, options));
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript_empty)
BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScriptForPrincipals)
{
return tryScript(global, JS_CompileScriptForPrincipals(cx, global, nullptr,
code, code_size,
__FILE__, __LINE__));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__)
.setPrincipals(nullptr);
return tryScript(global, JS_CompileScript(cx, global, code, code_size,
options));
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScriptForPrincipals)
BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript)
{
return tryScript(global, JS_CompileUCScript(cx, global,
uc_code, code_size,
__FILE__, __LINE__));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
return tryScript(global, JS_CompileUCScript(cx, global, uc_code, code_size,
options));
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript)
BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty)
{
return tryScript(global, JS_CompileUCScript(cx, global,
uc_code, 0,
__FILE__, __LINE__));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
return tryScript(global, JS_CompileUCScript(cx, global, uc_code, 0,
options));
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty)
BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScriptForPrincipals)
{
return tryScript(global, JS_CompileUCScriptForPrincipals(cx, global, nullptr,
uc_code, code_size,
__FILE__, __LINE__));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__)
.setPrincipals(nullptr);
return tryScript(global, JS_CompileUCScript(cx, global, uc_code, code_size,
options));
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScriptForPrincipals)

View File

@ -34,7 +34,10 @@ BEGIN_TEST(testTrap_gc)
;
// compile
JS::RootedScript script(cx, JS_CompileScript(cx, global, source, strlen(source), __FILE__, 1));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, 1);
JS::RootedScript script(cx, JS_CompileScript(cx, global, source,
strlen(source), options));
CHECK(script);
// execute

View File

@ -163,7 +163,10 @@ BEGIN_TEST(testXDR_bug506491)
"var f = makeClosure('0;', 'status', 'ok');\n";
// compile
JS::RootedScript script(cx, JS_CompileScript(cx, global, s, strlen(s), __FILE__, __LINE__));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx, JS_CompileScript(cx, global, s, strlen(s),
options));
CHECK(script);
script = FreezeThaw(cx, script);
@ -187,7 +190,9 @@ END_TEST(testXDR_bug506491)
BEGIN_TEST(testXDR_bug516827)
{
// compile an empty script
JS::RootedScript script(cx, JS_CompileScript(cx, global, "", 0, __FILE__, __LINE__));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx, JS_CompileScript(cx, global, "", 0, options));
CHECK(script);
script = FreezeThaw(cx, script);
@ -208,7 +213,10 @@ BEGIN_TEST(testXDR_source)
nullptr
};
for (const char **s = samples; *s; s++) {
JS::RootedScript script(cx, JS_CompileScript(cx, global, *s, strlen(*s), __FILE__, __LINE__));
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx, JS_CompileScript(cx, global, *s, strlen(*s),
options));
CHECK(script);
script = FreezeThaw(cx, script);
CHECK(script);
@ -231,7 +239,9 @@ BEGIN_TEST(testXDR_sourceMap)
};
JS::RootedScript script(cx);
for (const char **sm = sourceMaps; *sm; sm++) {
script = JS_CompileScript(cx, global, "", 0, __FILE__, __LINE__);
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
script = JS_CompileScript(cx, global, "", 0, options);
CHECK(script);
size_t len = strlen(*sm);

View File

@ -4399,7 +4399,7 @@ JS::CompileOptions::CompileOptions(JSContext *cx, JSVersion version)
{
this->version = (version != JSVERSION_UNKNOWN) ? version : cx->findVersion();
compileAndGo = cx->options().compileAndGo();
compileAndGo = false;
noScriptRval = cx->options().noScriptRval();
strictOption = cx->options().strictMode();
extraWarningsOption = cx->options().extraWarnings();
@ -4514,52 +4514,17 @@ JS::FinishOffThreadScript(JSContext *maybecx, JSRuntime *rt, void *token)
}
JS_PUBLIC_API(JSScript *)
JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *objArg, JSPrincipals *principals,
const jschar *chars, size_t length,
const char *filename, unsigned lineno)
JS_CompileScript(JSContext *cx, JS::HandleObject obj, const char *ascii,
size_t length, const JS::CompileOptions &options)
{
RootedObject obj(cx, objArg);
CompileOptions options(cx);
options.setPrincipals(principals)
.setFileAndLine(filename, lineno);
return Compile(cx, obj, options, chars, length);
}
JS_PUBLIC_API(JSScript *)
JS_CompileUCScript(JSContext *cx, JSObject *objArg, const jschar *chars, size_t length,
const char *filename, unsigned lineno)
{
RootedObject obj(cx, objArg);
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return Compile(cx, obj, options, chars, length);
}
JS_PUBLIC_API(JSScript *)
JS_CompileScriptForPrincipals(JSContext *cx, JSObject *objArg,
JSPrincipals *principals,
const char *ascii, size_t length,
const char *filename, unsigned lineno)
{
RootedObject obj(cx, objArg);
CompileOptions options(cx);
options.setPrincipals(principals)
.setFileAndLine(filename, lineno);
return Compile(cx, obj, options, ascii, length);
}
JS_PUBLIC_API(JSScript *)
JS_CompileScript(JSContext *cx, JSObject *objArg, const char *ascii, size_t length,
const char *filename, unsigned lineno)
JS_CompileUCScript(JSContext *cx, JS::HandleObject obj, const jschar *chars,
size_t length, const JS::CompileOptions &options)
{
RootedObject obj(cx, objArg);
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return Compile(cx, obj, options, ascii, length);
return Compile(cx, obj, options, chars, length);
}
JS_PUBLIC_API(bool)
@ -4675,43 +4640,20 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, const ReadOnlyCompileOption
}
JS_PUBLIC_API(JSFunction *)
JS_CompileUCFunction(JSContext *cx, JSObject *objArg, const char *name,
JS_CompileUCFunction(JSContext *cx, JS::HandleObject obj, const char *name,
unsigned nargs, const char *const *argnames,
const jschar *chars, size_t length,
const char *filename, unsigned lineno)
const CompileOptions &options)
{
RootedObject obj(cx, objArg);
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return CompileFunction(cx, obj, options, name, nargs, argnames, chars, length);
}
JS_PUBLIC_API(JSFunction *)
JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *objArg,
JSPrincipals *principals, const char *name,
unsigned nargs, const char *const *argnames,
const char *ascii, size_t length,
const char *filename, unsigned lineno)
{
RootedObject obj(cx, objArg);
CompileOptions options(cx);
options.setPrincipals(principals)
.setFileAndLine(filename, lineno);
return CompileFunction(cx, obj, options, name, nargs, argnames, ascii, length);
}
JS_PUBLIC_API(JSFunction *)
JS_CompileFunction(JSContext *cx, JSObject *objArg, const char *name,
JS_CompileFunction(JSContext *cx, JS::HandleObject obj, const char *name,
unsigned nargs, const char *const *argnames,
const char *ascii, size_t length,
const char *filename, unsigned lineno)
const JS::CompileOptions &options)
{
RootedObject obj(cx, objArg);
CompileOptions options(cx);
options.setFileAndLine(filename, lineno);
return CompileFunction(cx, obj, options, name, nargs, argnames, ascii, length);
}

View File

@ -1447,7 +1447,6 @@ class JS_PUBLIC_API(ContextOptions) {
werror_(false),
varObjFix_(false),
privateIsNSISupports_(false),
compileAndGo_(false),
dontReportUncaught_(false),
noDefaultCompartmentObject_(false),
noScriptRval_(false),
@ -1499,16 +1498,6 @@ class JS_PUBLIC_API(ContextOptions) {
return *this;
}
bool compileAndGo() const { return compileAndGo_; }
ContextOptions &setCompileAndGo(bool flag) {
compileAndGo_ = flag;
return *this;
}
ContextOptions &toggleCompileAndGo() {
compileAndGo_ = !compileAndGo_;
return *this;
}
bool dontReportUncaught() const { return dontReportUncaught_; }
ContextOptions &setDontReportUncaught(bool flag) {
dontReportUncaught_ = flag;
@ -1594,7 +1583,6 @@ class JS_PUBLIC_API(ContextOptions) {
bool werror_ : 1;
bool varObjFix_ : 1;
bool privateIsNSISupports_ : 1;
bool compileAndGo_ : 1;
bool dontReportUncaught_ : 1;
bool noDefaultCompartmentObject_ : 1;
bool noScriptRval_ : 1;
@ -3333,48 +3321,29 @@ extern JS_PUBLIC_API(bool)
JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj, const char *utf8, size_t length);
extern JS_PUBLIC_API(JSScript *)
JS_CompileScript(JSContext *cx, JSObject *obj,
JS_CompileScript(JSContext *cx, JS::HandleObject obj,
const char *ascii, size_t length,
const char *filename, unsigned lineno);
const JS::CompileOptions &options);
extern JS_PUBLIC_API(JSScript *)
JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
JSPrincipals *principals,
const char *ascii, size_t length,
const char *filename, unsigned lineno);
extern JS_PUBLIC_API(JSScript *)
JS_CompileUCScript(JSContext *cx, JSObject *obj,
JS_CompileUCScript(JSContext *cx, JS::HandleObject obj,
const jschar *chars, size_t length,
const char *filename, unsigned lineno);
extern JS_PUBLIC_API(JSScript *)
JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
JSPrincipals *principals,
const jschar *chars, size_t length,
const char *filename, unsigned lineno);
const JS::CompileOptions &options);
extern JS_PUBLIC_API(JSObject *)
JS_GetGlobalFromScript(JSScript *script);
extern JS_PUBLIC_API(JSFunction *)
JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
JS_CompileFunction(JSContext *cx, JS::HandleObject obj, const char *name,
unsigned nargs, const char *const *argnames,
const char *bytes, size_t length,
const char *filename, unsigned lineno);
const JS::CompileOptions &options);
extern JS_PUBLIC_API(JSFunction *)
JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
JSPrincipals *principals, const char *name,
unsigned nargs, const char *const *argnames,
const char *bytes, size_t length,
const char *filename, unsigned lineno);
extern JS_PUBLIC_API(JSFunction *)
JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
JS_CompileUCFunction(JSContext *cx, JS::HandleObject obj, const char *name,
unsigned nargs, const char *const *argnames,
const jschar *chars, size_t length,
const char *filename, unsigned lineno);
const JS::CompileOptions &options);
namespace JS {

View File

@ -388,12 +388,12 @@ RunFile(JSContext *cx, Handle<JSObject*> obj, const char *filename, FILE *file,
{
JS::AutoSaveContextOptions asco(cx);
JS::ContextOptionsRef(cx).setCompileAndGo(true)
.setNoScriptRval(true);
JS::ContextOptionsRef(cx).setNoScriptRval(true);
CompileOptions options(cx);
options.setUTF8(true)
.setFileAndLine(filename, 1);
.setFileAndLine(filename, 1)
.setCompileAndGo(true);
gGotError = false;
script = JS::Compile(cx, obj, options, file);
@ -1007,13 +1007,13 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
{
JS::AutoSaveContextOptions asco(cx);
JS::ContextOptionsRef(cx).setCompileAndGo(compileAndGo)
.setNoScriptRval(noScriptRval);
JS::ContextOptionsRef(cx).setNoScriptRval(noScriptRval);
CompileOptions options(cx);
options.setFileAndLine(fileName, lineNumber)
.setElement(element)
.setSourcePolicy(sourcePolicy);
.setSourcePolicy(sourcePolicy)
.setCompileAndGo(compileAndGo);
script = JS::Compile(cx, global, options, codeChars, codeLength);
if (!script)
@ -1170,10 +1170,12 @@ Run(JSContext *cx, unsigned argc, jsval *vp)
int64_t startClock = PRMJ_Now();
{
JS::AutoSaveContextOptions asco(cx);
JS::ContextOptionsRef(cx).setCompileAndGo(true)
.setNoScriptRval(true);
JS::ContextOptionsRef(cx).setNoScriptRval(true);
script = JS_CompileUCScript(cx, thisobj, ucbuf, buflen, filename.ptr(), 1);
JS::CompileOptions options(cx);
options.setFileAndLine(filename.ptr(), 1)
.setCompileAndGo(true);
script = JS_CompileUCScript(cx, thisobj, ucbuf, buflen, options);
if (!script)
return false;
}
@ -2005,12 +2007,12 @@ DisassFile(JSContext *cx, unsigned argc, jsval *vp)
{
JS::AutoSaveContextOptions asco(cx);
JS::ContextOptionsRef(cx).setCompileAndGo(true)
.setNoScriptRval(true);
JS::ContextOptionsRef(cx).setNoScriptRval(true);
CompileOptions options(cx);
options.setUTF8(true)
.setFileAndLine(filename.ptr(), 1);
.setFileAndLine(filename.ptr(), 1)
.setCompileAndGo(true);
script = JS::Compile(cx, thisobj, options, filename.ptr());
if (!script)
@ -3081,10 +3083,12 @@ Compile(JSContext *cx, unsigned argc, jsval *vp)
RootedObject global(cx, JS::CurrentGlobalOrNull(cx));
JSString *scriptContents = JSVAL_TO_STRING(arg0);
JS::AutoSaveContextOptions asco(cx);
JS::ContextOptionsRef(cx).setCompileAndGo(true)
.setNoScriptRval(true);
JS::ContextOptionsRef(cx).setNoScriptRval(true);
JS::CompileOptions options(cx);
options.setFileAndLine("<string>", 1)
.setCompileAndGo(true);
bool ok = JS_CompileUCScript(cx, global, JS_GetStringCharsZ(cx, scriptContents),
JS_GetStringLength(scriptContents), "<string>", 1);
JS_GetStringLength(scriptContents), options);
JS_SET_RVAL(cx, vp, UndefinedValue());
return ok;
}

View File

@ -946,8 +946,10 @@ ProcessFile(JSContext *cx, JS::Handle<JSObject*> obj, const char *filename, FILE
DoBeginRequest(cx);
/* Clear any pending exception from previous failed compiles. */
JS_ClearPendingException(cx);
script = JS_CompileScriptForPrincipals(cx, obj, gJSPrincipals, buffer,
strlen(buffer), "typein", startline);
JS::CompileOptions options(cx);
options.setFileAndLine("typein", startline)
.setPrincipals(gJSPrincipals);
script = JS_CompileScript(cx, obj, buffer, strlen(buffer), options);
if (script) {
JSErrorReporter older;
@ -1023,8 +1025,7 @@ ProcessArgsForCompartment(JSContext *cx, char **argv, int argc)
ContextOptionsRef(cx).toggleExtraWarnings();
break;
case 'I':
ContextOptionsRef(cx).toggleCompileAndGo()
.toggleIon()
ContextOptionsRef(cx).toggleIon()
.toggleAsmJS();
break;
case 'n':

View File

@ -616,10 +616,12 @@ ProxyAutoConfig::SetupJS()
bool isDataURI = nsDependentCSubstring(mPACURI, 0, 5).LowerCaseEqualsASCII("data:", 5);
sRunning = this;
JSScript *script = JS_CompileScript(mJSRuntime->Context(),
mJSRuntime->Global(),
JS::Rooted<JSObject *> global(mJSRuntime->Context(), mJSRuntime->Global());
JS::CompileOptions options(mJSRuntime->Context());
options.setFileAndLine(mPACURI.get(), 1);
JSScript *script = JS_CompileScript(mJSRuntime->Context(), global,
mPACScript.get(), mPACScript.Length(),
mPACURI.get(), 1);
options);
if (!script ||
!JS_ExecuteScript(mJSRuntime->Context(), mJSRuntime->Global(), script, nullptr)) {
nsString alertMessage(NS_LITERAL_STRING("PAC file failed to install from "));