Backed out changeset d470f958ea61 (bug 1542910) for bustages in testEmptyWindowIsOmitted.cpp

This commit is contained in:
Noemi Erli 2019-04-09 19:24:46 +03:00
Родитель 5be23b518b
Коммит 4a518ba201
24 изменённых файлов: 281 добавлений и 263 удалений

Просмотреть файл

@ -1319,8 +1319,7 @@ void nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
options.setFileAndLine(url.get(), 1);
options.setNoScriptRval(true);
script = JS::CompileForNonSyntacticScope(cx, options, srcBuf);
if (!script) {
if (!JS::CompileForNonSyntacticScope(cx, options, srcBuf, &script)) {
return;
}
}

Просмотреть файл

@ -216,12 +216,16 @@ nsresult nsJSUtils::ExecutionContext::Compile(
#endif
MOZ_ASSERT(!mScript);
mScript =
mScopeChain.length() == 0
? JS::Compile(mCx, aCompileOptions, aSrcBuf)
: JS::CompileForNonSyntacticScope(mCx, aCompileOptions, aSrcBuf);
bool compiled = true;
if (mScopeChain.length() == 0) {
compiled = JS::Compile(mCx, aCompileOptions, aSrcBuf, &mScript);
} else {
compiled = JS::CompileForNonSyntacticScope(mCx, aCompileOptions, aSrcBuf,
&mScript);
}
if (!mScript) {
MOZ_ASSERT_IF(compiled, mScript);
if (!compiled) {
mSkip = true;
mRv = EvaluationExceptionToNSResult(mCx);
return mRv;

Просмотреть файл

@ -2147,10 +2147,9 @@ nsresult nsXULPrototypeScript::Compile(
}
NotifyOffThreadScriptCompletedRunnable::NoteReceiver(aOffThreadReceiver);
} else {
JS::Rooted<JSScript*> script(cx, JS::Compile(cx, options, srcBuf));
if (!script) {
JS::Rooted<JSScript*> script(cx);
if (!JS::Compile(cx, options, srcBuf, &script))
return NS_ERROR_OUT_OF_MEMORY;
}
Set(script);
}
return NS_OK;

Просмотреть файл

@ -139,9 +139,10 @@ static bool Load(JSContext *cx, unsigned argc, JS::Value *vp) {
JS::CompileOptions options(cx);
options.setFileAndLine(filename.get(), 1);
JS::Rooted<JSScript *> script(cx, JS::CompileUtf8File(cx, options, file));
JS::Rooted<JSScript *> script(cx);
bool ok = JS::CompileUtf8File(cx, options, file, &script);
fclose(file);
if (!script) return false;
if (!ok) return false;
if (!JS_ExecuteScript(cx, script)) {
return false;
@ -250,10 +251,9 @@ void XPCShellEnvironment::ProcessFile(JSContext *cx, const char *filename,
JS::CompileOptions options(cx);
options.setFileAndLine(filename, 1);
JS::Rooted<JSScript *> script(cx, JS::CompileUtf8File(cx, options, file));
if (script) {
JS::Rooted<JSScript *> script(cx);
if (JS::CompileUtf8File(cx, options, file, &script))
(void)JS_ExecuteScript(cx, script, &result);
}
return;
}
@ -288,9 +288,8 @@ void XPCShellEnvironment::ProcessFile(JSContext *cx, const char *filename,
JS::CompileOptions options(cx);
options.setFileAndLine("typein", startline);
JS::Rooted<JSScript *> script(
cx, JS::CompileUtf8(cx, options, buffer, strlen(buffer)));
if (script) {
JS::Rooted<JSScript *> script(cx);
if (JS::CompileUtf8(cx, options, buffer, strlen(buffer), &script)) {
ok = JS_ExecuteScript(cx, script, &result);
if (ok && !result.isUndefined()) {
/* Suppress warnings from JS::ToString(). */
@ -426,8 +425,8 @@ bool XPCShellEnvironment::EvaluateString(const nsString &aString,
return false;
}
JS::Rooted<JSScript *> script(cx, JS::Compile(cx, options, srcBuf));
if (!script) {
JS::Rooted<JSScript *> script(cx);
if (!JS::Compile(cx, options, srcBuf, &script)) {
return false;
}

Просмотреть файл

@ -147,12 +147,12 @@ extern JS_PUBLIC_API bool EvaluateUtf8Path(
MutableHandle<Value> rval);
/**
* Compile the provided script using the given options. Return the script on
* success, or return null on failure (usually with an error reported).
* |script| will always be set. On failure, it will be set to nullptr.
*/
extern JS_PUBLIC_API JSScript* Compile(JSContext* cx,
const ReadOnlyCompileOptions& options,
SourceText<char16_t>& srcBuf);
extern JS_PUBLIC_API bool Compile(JSContext* cx,
const ReadOnlyCompileOptions& options,
SourceText<char16_t>& srcBuf,
MutableHandle<JSScript*> script);
/**
* Identical to |JS::Compile|, but compiles UTF-8.
@ -165,73 +165,84 @@ extern JS_PUBLIC_API JSScript* Compile(JSContext* cx,
* compiling them. UTF-8 compilation is currently experimental and has
* known bugs. Use only if you're willing to tolerate unspecified bugs!
*/
extern JS_PUBLIC_API JSScript* CompileDontInflate(
extern JS_PUBLIC_API bool CompileDontInflate(
JSContext* cx, const ReadOnlyCompileOptions& options,
SourceText<mozilla::Utf8Unit>& srcBuf);
SourceText<mozilla::Utf8Unit>& srcBuf, MutableHandle<JSScript*> script);
/**
* Compile the provided UTF-8 data into a script. It is an error if the data
* contains invalid UTF-8. Return the script on success, or return null on
* failure (usually with an error reported).
* Compile the provided UTF-8 data into a script. If the data contains invalid
* UTF-8, an error is reported.
*
* |script| is always set to the compiled script or to null in case of error.
*/
extern JS_PUBLIC_API JSScript* CompileUtf8(
JSContext* cx, const ReadOnlyCompileOptions& options, const char* bytes,
size_t length);
extern JS_PUBLIC_API bool CompileUtf8(JSContext* cx,
const ReadOnlyCompileOptions& options,
const char* bytes, size_t length,
MutableHandle<JSScript*> script);
/**
* Compile the provided UTF-8 data into a script. It is an error if the data
* contains invalid UTF-8. Return the script on success, or return null on
* failure (usually with an error reported).
* Compile the provided UTF-8 data into a script. If the data contains invalid
* UTF-8, an error is reported.
*
* |script| is always set to the compiled script or to null in case of error.
*
* NOTE: This function DOES NOT INFLATE the UTF-8 bytes to UTF-16 before
* compiling them. UTF-8 compilation is currently experimental and has
* known bugs. Use only if you're willing to tolerate unspecified bugs!
*/
extern JS_PUBLIC_API JSScript* CompileUtf8DontInflate(
extern JS_PUBLIC_API bool CompileUtf8DontInflate(
JSContext* cx, const ReadOnlyCompileOptions& options, const char* bytes,
size_t length);
size_t length, MutableHandle<JSScript*> script);
/**
* Compile the UTF-8 contents of the given file into a script. It is an error
* if the file contains invalid UTF-8. Return the script on success, or return
* null on failure (usually with an error reported).
* Compile the UTF-8 contents of the given file into a script. If the contents
* contain any malformed UTF-8, an error is reported.
*
* |script| is always set to the compiled script or to null in case of error.
*/
extern JS_PUBLIC_API JSScript* CompileUtf8File(
JSContext* cx, const ReadOnlyCompileOptions& options, FILE* file);
extern JS_PUBLIC_API bool CompileUtf8File(JSContext* cx,
const ReadOnlyCompileOptions& options,
FILE* file,
MutableHandle<JSScript*> script);
/**
* Compile the UTF-8 contents of the given file into a script. It is an error
* if the file contains invalid UTF-8. Return the script on success, or return
* null on failure (usually with an error reported).
* Compile the UTF-8 contents of the given file into a script. If the contents
* contain any malformed UTF-8, an error is reported.
*
* |script| is always set to the compiled script or to null in case of error.
*
* NOTE: This function DOES NOT INFLATE the UTF-8 bytes to UTF-16 before
* compiling them. UTF-8 compilation is currently experimental and has
* known bugs. Use only if you're willing to tolerate unspecified bugs!
*/
extern JS_PUBLIC_API JSScript* CompileUtf8FileDontInflate(
JSContext* cx, const ReadOnlyCompileOptions& options, FILE* file);
extern JS_PUBLIC_API bool CompileUtf8FileDontInflate(
JSContext* cx, const ReadOnlyCompileOptions& options, FILE* file,
MutableHandle<JSScript*> script);
/**
* Compile the UTF-8 contents of the file at the given path into a script.
* (The path itself is in the system encoding, not [necessarily] UTF-8.) It
* is an error if the file's contents are invalid UTF-8. Return the script on
* success, or return null on failure (usually with an error reported).
* (The path itself is in the system encoding, not [necessarily] UTF-8.) If
* the contents contain any malformed UTF-8, an error is reported.
*
* |script| is always set to the compiled script or to null in case of error.
*/
extern JS_PUBLIC_API JSScript* CompileUtf8Path(
JSContext* cx, const ReadOnlyCompileOptions& options, const char* filename);
extern JS_PUBLIC_API bool CompileUtf8Path(JSContext* cx,
const ReadOnlyCompileOptions& options,
const char* filename,
MutableHandle<JSScript*> script);
extern JS_PUBLIC_API JSScript* CompileForNonSyntacticScope(
extern JS_PUBLIC_API bool CompileForNonSyntacticScope(
JSContext* cx, const ReadOnlyCompileOptions& options,
SourceText<char16_t>& srcBuf);
SourceText<char16_t>& srcBuf, MutableHandle<JSScript*> script);
/**
* Compile the provided UTF-8 data into a script in a non-syntactic scope. It
* is an error if the data contains invalid UTF-8. Return the script on
* success, or return null on failure (usually with an error reported).
* Compile the given UTF-8 data for non-syntactic scope.
*
* An exception is thrown if the data isn't valid UTF-8.
*/
extern JS_PUBLIC_API JSScript* CompileUtf8ForNonSyntacticScope(
extern JS_PUBLIC_API bool CompileUtf8ForNonSyntacticScope(
JSContext* cx, const ReadOnlyCompileOptions& options, const char* bytes,
size_t length);
size_t length, MutableHandle<JSScript*> script);
/**
* Compile a function with envChain plus the global as its scope chain.

Просмотреть файл

@ -3908,8 +3908,8 @@ static bool EvalReturningScope(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
RootedScript script(cx, JS::CompileForNonSyntacticScope(cx, options, srcBuf));
if (!script) {
RootedScript script(cx);
if (!JS::CompileForNonSyntacticScope(cx, options, srcBuf, &script)) {
return false;
}
@ -4012,8 +4012,8 @@ static bool ShellCloneAndExecuteScript(JSContext* cx, unsigned argc,
return false;
}
RootedScript script(cx, JS::Compile(cx, options, srcBuf));
if (!script) {
RootedScript script(cx);
if (!JS::Compile(cx, options, srcBuf, &script)) {
return false;
}
@ -5431,8 +5431,12 @@ JSScript* js::TestingFunctionArgumentToScript(
return nullptr;
}
RootedScript script(cx);
CompileOptions options(cx);
return JS::Compile(cx, options, source);
if (!JS::Compile(cx, options, source, &script)) {
return nullptr;
}
return script;
}
RootedFunction fun(cx, JS_ValueToFunction(cx, v));

Просмотреть файл

@ -69,37 +69,31 @@ bool testCompile(bool nonSyntactic) {
// Check explicit non-syntactic compilation first to make sure it doesn't
// modify our options object.
script = CompileForNonSyntacticScope(cx, options, buf);
CHECK(script);
CHECK(CompileForNonSyntacticScope(cx, options, buf, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), true);
script = CompileUtf8ForNonSyntacticScope(cx, options, src, length);
CHECK(script);
CHECK(CompileUtf8ForNonSyntacticScope(cx, options, src, length, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), true);
{
JS::SourceText<char16_t> srcBuf;
CHECK(srcBuf.init(cx, src_16, length, JS::SourceOwnership::Borrowed));
script = CompileForNonSyntacticScope(cx, options, srcBuf);
CHECK(script);
CHECK(CompileForNonSyntacticScope(cx, options, srcBuf, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), true);
}
script = Compile(cx, options, buf);
CHECK(script);
CHECK(Compile(cx, options, buf, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);
script = CompileUtf8(cx, options, src, length);
CHECK(script);
CHECK(CompileUtf8(cx, options, src, length, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);
{
JS::SourceText<char16_t> srcBuf;
CHECK(srcBuf.init(cx, src_16, length, JS::SourceOwnership::Borrowed));
script = Compile(cx, options, srcBuf);
CHECK(script);
CHECK(Compile(cx, options, srcBuf, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);
}

Просмотреть файл

@ -186,8 +186,7 @@ bool testBadUtf8(const char (&chars)[N], unsigned errorNumber,
JS::Rooted<JSScript*> script(cx);
{
JS::CompileOptions options(cx);
script = JS::CompileUtf8DontInflate(cx, options, chars, N - 1);
CHECK(script);
CHECK(!JS::CompileUtf8DontInflate(cx, options, chars, N - 1, &script));
}
JS::RootedValue exn(cx);
@ -266,8 +265,7 @@ bool testContext(const char (&chars)[N],
JS::Rooted<JSScript*> script(cx);
{
JS::CompileOptions options(cx);
script = JS::CompileUtf8DontInflate(cx, options, chars, N - 1);
CHECK(script);
CHECK(!JS::CompileUtf8DontInflate(cx, options, chars, N - 1, &script));
}
JS::RootedValue exn(cx);

Просмотреть файл

@ -85,29 +85,29 @@ static bool equals(const char* str, const char* expected) {
return std::strcmp(str, expected) == 0;
}
JSScript* compile(const char16_t* chars, size_t len) {
bool compile(const char16_t* chars, size_t len,
JS::MutableHandle<JSScript*> script) {
JS::SourceText<char16_t> source;
MOZ_RELEASE_ASSERT(
source.init(cx, chars, len, JS::SourceOwnership::Borrowed));
CHECK(source.init(cx, chars, len, JS::SourceOwnership::Borrowed));
JS::CompileOptions options(cx);
return JS::Compile(cx, options, source);
return JS::Compile(cx, options, source, script);
}
JSScript* compile(const char* chars, size_t len) {
bool compile(const char* chars, size_t len,
JS::MutableHandle<JSScript*> script) {
JS::SourceText<Utf8Unit> source;
MOZ_RELEASE_ASSERT(
source.init(cx, chars, len, JS::SourceOwnership::Borrowed));
CHECK(source.init(cx, chars, len, JS::SourceOwnership::Borrowed));
JS::CompileOptions options(cx);
return JS::CompileDontInflate(cx, options, source);
return JS::CompileDontInflate(cx, options, source, script);
}
template <typename CharT, size_t N>
bool testOmittedWindow(const CharT (&chars)[N], unsigned expectedErrorNumber,
const char* badCodeUnits = nullptr) {
JS::Rooted<JSScript*> script(cx, compile(chars, N - 1));
CHECK(script);
JS::Rooted<JSScript*> script(cx);
CHECK(!compile(chars, N - 1, &script));
JS::RootedValue exn(cx);
CHECK(JS_GetPendingException(cx, &exn));

Просмотреть файл

@ -25,9 +25,9 @@ BEGIN_TEST(testExecuteInJSMEnvironment_Basic) {
options.setFileAndLine(__FILE__, __LINE__);
options.setNoScriptRval(true);
JS::RootedScript script(cx, JS::CompileUtf8ForNonSyntacticScope(
cx, options, src, sizeof(src) - 1));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8ForNonSyntacticScope(cx, options, src, sizeof(src) - 1,
&script));
JS::RootedObject varEnv(cx, js::NewJSMEnvironment(cx));
JS::RootedObject lexEnv(cx, JS_ExtensibleLexicalEnvironment(varEnv));
@ -79,9 +79,9 @@ BEGIN_TEST(testExecuteInJSMEnvironment_Callback) {
options.setFileAndLine(__FILE__, __LINE__);
options.setNoScriptRval(true);
JS::RootedScript script(cx, JS::CompileUtf8ForNonSyntacticScope(
cx, options, src, sizeof(src) - 1));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8ForNonSyntacticScope(cx, options, src, sizeof(src) - 1,
&script));
JS::RootedObject nsvo(cx, js::NewJSMEnvironment(cx));
CHECK(nsvo);

Просмотреть файл

@ -25,7 +25,8 @@ BEGIN_TEST(testGCCellPtr) {
JS::CompileOptions opts(cx);
JS::RootedScript script(cx, JS::CompileUtf8(cx, opts, code, strlen(code)));
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, opts, code, strlen(code), &script));
CHECK(script);
CHECK(!JS::GCCellPtr(nullptr));

Просмотреть файл

@ -42,9 +42,8 @@ BEGIN_TEST(testPrivateGCThingValue) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx,
JS::CompileUtf8(cx, options, code, sizeof(code) - 1));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, code, sizeof(code) - 1, &script));
JS_SetReservedSlot(obj, 0, PrivateGCThingValue(script));
TestTracer trc(cx);

Просмотреть файл

@ -30,7 +30,8 @@ BEGIN_TEST(testScriptInfo) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, startLine);
JS::RootedScript script(cx, JS::CompileUtf8(cx, options, code, strlen(code)));
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, code, strlen(code), &script));
CHECK(script);
CHECK_EQUAL(JS_GetScriptBaseLineNumber(cx, script), startLine);

Просмотреть файл

@ -43,8 +43,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx, JS::CompileUtf8(cx, options, code, code_size));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, code, code_size, &script));
return tryScript(script);
}
@ -54,8 +54,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript_empty) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx, JS::CompileUtf8(cx, options, "", 0));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, "", 0, &script));
return tryScript(script);
}
@ -65,7 +65,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScriptForPrincipals) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx, JS::CompileUtf8(cx, options, code, code_size));
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, code, code_size, &script));
return tryScript(script);
}
@ -78,8 +79,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript) {
JS::SourceText<char16_t> srcBuf;
CHECK(srcBuf.init(cx, uc_code, code_size, JS::SourceOwnership::Borrowed));
JS::RootedScript script(cx, JS::Compile(cx, options, srcBuf));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::Compile(cx, options, srcBuf, &script));
return tryScript(script);
}
@ -92,8 +93,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty) {
JS::SourceText<char16_t> srcBuf;
CHECK(srcBuf.init(cx, uc_code, 0, JS::SourceOwnership::Borrowed));
JS::RootedScript script(cx, JS::Compile(cx, options, srcBuf));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::Compile(cx, options, srcBuf, &script));
return tryScript(script);
}
@ -107,8 +108,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture,
JS::SourceText<char16_t> srcBuf;
CHECK(srcBuf.init(cx, uc_code, code_size, JS::SourceOwnership::Borrowed));
JS::RootedScript script(cx, JS::Compile(cx, options, srcBuf));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::Compile(cx, options, srcBuf, &script));
return tryScript(script);
}
@ -124,9 +125,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile) {
JS::CompileOptions options(cx);
options.setFileAndLine(script_filename, 1);
JS::RootedScript script(cx,
JS::CompileUtf8Path(cx, options, script_filename));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8Path(cx, options, script_filename, &script));
tempScript.remove();
return tryScript(script);
@ -142,9 +142,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile_empty) {
JS::CompileOptions options(cx);
options.setFileAndLine(script_filename, 1);
JS::RootedScript script(cx,
JS::CompileUtf8Path(cx, options, script_filename));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8Path(cx, options, script_filename, &script));
tempScript.remove();
return tryScript(script);
@ -160,9 +159,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle) {
JS::CompileOptions options(cx);
options.setFileAndLine("temporary file", 1);
JS::RootedScript script(cx, JS::CompileUtf8File(cx, options, script_stream));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8File(cx, options, script_stream, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle)
@ -175,9 +173,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle_empty) {
JS::CompileOptions options(cx);
options.setFileAndLine("empty temporary file", 1);
JS::RootedScript script(cx, JS::CompileUtf8File(cx, options, script_stream));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8File(cx, options, script_stream, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle_empty)
@ -193,9 +190,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture,
JS::CompileOptions options(cx);
options.setFileAndLine("temporary file", 1);
JS::RootedScript script(cx, JS::CompileUtf8File(cx, options, script_stream));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8File(cx, options, script_stream, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture,
@ -209,8 +205,8 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, CloneAndExecuteScript) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx, JS::CompileUtf8(cx, options, "val", 3));
CHECK(script);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, "val", 3, &script));
JS::RootedValue value(cx);
CHECK(JS_ExecuteScript(cx, script, &value));

Просмотреть файл

@ -91,8 +91,8 @@ BEGIN_TEST(test_ubiNodeZone) {
RootedString string1(
cx, JS_NewStringCopyZ(cx, "Simpson's Individual Stringettes!"));
CHECK(string1);
RootedScript script1(cx, JS::CompileUtf8(cx, options, "", 0));
CHECK(script1);
RootedScript script1(cx);
CHECK(JS::CompileUtf8(cx, options, "", 0, &script1));
{
// ... and then enter global2's zone and create a string and script
@ -102,8 +102,8 @@ BEGIN_TEST(test_ubiNodeZone) {
RootedString string2(cx,
JS_NewStringCopyZ(cx, "A million household uses!"));
CHECK(string2);
RootedScript script2(cx, JS::CompileUtf8(cx, options, "", 0));
CHECK(script2);
RootedScript script2(cx);
CHECK(JS::CompileUtf8(cx, options, "", 0, &script2));
CHECK(JS::ubi::Node(string1).zone() == global1->zone());
CHECK(JS::ubi::Node(script1).zone() == global1->zone());
@ -137,16 +137,16 @@ BEGIN_TEST(test_ubiNodeCompartment) {
JS::CompileOptions options(cx);
// Create a script in the original realm...
RootedScript script1(cx, JS::CompileUtf8(cx, options, "", 0));
CHECK(script1);
RootedScript script1(cx);
CHECK(JS::CompileUtf8(cx, options, "", 0, &script1));
{
// ... and then enter global2's realm and create a script
// there, too.
JSAutoRealm ar(cx, global2);
RootedScript script2(cx, JS::CompileUtf8(cx, options, "", 0));
CHECK(script2);
RootedScript script2(cx);
CHECK(JS::CompileUtf8(cx, options, "", 0, &script2));
CHECK(JS::ubi::Node(script1).compartment() == global1->compartment());
CHECK(JS::ubi::Node(script2).compartment() == global2->compartment());

Просмотреть файл

@ -61,7 +61,8 @@ BEGIN_TEST(testXDR_bug506491) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx, JS::CompileUtf8(cx, options, s, strlen(s)));
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, s, strlen(s), &script));
CHECK(script);
script = FreezeThaw(cx, script);
@ -87,7 +88,8 @@ BEGIN_TEST(testXDR_bug516827) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx, JS::CompileUtf8(cx, options, "", 0));
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, "", 0, &script));
CHECK(script);
script = FreezeThaw(cx, script);
@ -116,7 +118,8 @@ BEGIN_TEST(testXDR_source) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx, JS::CompileUtf8(cx, options, *s, strlen(*s)));
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, *s, strlen(*s), &script));
CHECK(script);
script = FreezeThaw(cx, script);
@ -141,7 +144,7 @@ BEGIN_TEST(testXDR_sourceMap) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
script = JS::CompileUtf8(cx, options, "", 0);
CHECK(JS::CompileUtf8(cx, options, "", 0, &script));
CHECK(script);
size_t len = strlen(*sm);

Просмотреть файл

@ -861,14 +861,16 @@ static MOZ_MUST_USE bool RunFile(JSContext* cx, const char* filename,
fprintf(stderr, "(compiling '%s' as UTF-8 without inflating)\n",
filename);
script = JS::CompileUtf8FileDontInflate(cx, options, file);
if (!JS::CompileUtf8FileDontInflate(cx, options, file, &script)) {
return false;
}
} else {
script = JS::CompileUtf8File(cx, options, file);
if (!JS::CompileUtf8File(cx, options, file, &script)) {
return false;
}
}
if (!script) {
return false;
}
MOZ_ASSERT(script);
}
if (!RegisterScriptPathWithModuleLoader(cx, script, filename)) {
@ -1266,8 +1268,8 @@ static MOZ_MUST_USE bool EvalUtf8AndPrint(JSContext* cx, const char* bytes,
.setIsRunOnce(true)
.setFileAndLine("typein", lineno);
RootedScript script(cx, JS::CompileUtf8(cx, options, bytes, length));
if (!script) {
RootedScript script(cx);
if (!JS::CompileUtf8(cx, options, bytes, length, &script)) {
return false;
}
if (compileOnly) {
@ -1724,9 +1726,10 @@ static bool LoadScript(JSContext* cx, unsigned argc, Value* vp,
.setIsRunOnce(true)
.setNoScriptRval(true);
RootedScript script(cx);
RootedValue unused(cx);
if (!(compileOnly
? JS::CompileUtf8Path(cx, opts, filename.get()) != nullptr
? JS::CompileUtf8Path(cx, opts, filename.get(), &script)
: JS::EvaluateUtf8Path(cx, opts, filename.get(), &unused))) {
return false;
}
@ -2191,9 +2194,9 @@ static bool Evaluate(JSContext* cx, unsigned argc, Value* vp) {
}
if (envChain.length() == 0) {
script = JS::Compile(cx, options, srcBuf);
(void)JS::Compile(cx, options, srcBuf, &script);
} else {
script = JS::CompileForNonSyntacticScope(cx, options, srcBuf);
(void)JS::CompileForNonSyntacticScope(cx, options, srcBuf, &script);
}
}
@ -2450,8 +2453,7 @@ static bool Run(JSContext* cx, unsigned argc, Value* vp) {
.setIsRunOnce(true)
.setNoScriptRval(true);
script = JS::Compile(cx, options, srcBuf);
if (!script) {
if (!JS::Compile(cx, options, srcBuf, &script)) {
return false;
}
}
@ -3453,8 +3455,7 @@ static bool DisassFile(JSContext* cx, unsigned argc, Value* vp) {
.setIsRunOnce(true)
.setNoScriptRval(true);
script = JS::CompileUtf8Path(cx, options, filename.get());
if (!script) {
if (!JS::CompileUtf8Path(cx, options, filename.get(), &script)) {
return false;
}
}
@ -4024,14 +4025,11 @@ static void WorkerMain(WorkerInput* input) {
options.setFileAndLine("<string>", 1).setIsRunOnce(true);
AutoReportException are(cx);
RootedScript script(cx);
JS::SourceText<char16_t> srcBuf;
if (!srcBuf.init(cx, input->chars.get(), input->length,
JS::SourceOwnership::Borrowed)) {
break;
}
RootedScript script(cx, JS::Compile(cx, options, srcBuf));
if (!script) {
JS::SourceOwnership::Borrowed) ||
!JS::Compile(cx, options, srcBuf, &script)) {
break;
}
RootedValue result(cx);
@ -4666,8 +4664,8 @@ static bool Compile(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
RootedScript script(cx, JS::Compile(cx, options, srcBuf));
if (!script) {
RootedScript script(cx);
if (!JS::Compile(cx, options, srcBuf, &script)) {
return false;
}

Просмотреть файл

@ -55,9 +55,10 @@ JS_PUBLIC_API void JS::detail::ReportSourceTooLong(JSContext* cx) {
}
template <typename Unit>
static JSScript* CompileSourceBuffer(JSContext* cx,
const ReadOnlyCompileOptions& options,
SourceText<Unit>& srcBuf) {
static bool CompileSourceBuffer(JSContext* cx,
const ReadOnlyCompileOptions& options,
SourceText<Unit>& srcBuf,
JS::MutableHandleScript script) {
ScopeKind scopeKind =
options.nonSyntacticScope ? ScopeKind::NonSyntactic : ScopeKind::Global;
@ -66,113 +67,119 @@ static JSScript* CompileSourceBuffer(JSContext* cx,
CHECK_THREAD(cx);
frontend::GlobalScriptInfo info(cx, options, scopeKind);
return frontend::CompileGlobalScript(info, srcBuf);
script.set(frontend::CompileGlobalScript(info, srcBuf));
return !!script;
}
static JSScript* CompileUtf8(JSContext* cx,
const ReadOnlyCompileOptions& options,
const char* bytes, size_t length) {
static bool CompileUtf8(JSContext* cx, const ReadOnlyCompileOptions& options,
const char* bytes, size_t length,
JS::MutableHandleScript script) {
auto chars = UniqueTwoByteChars(
UTF8CharsToNewTwoByteCharsZ(cx, UTF8Chars(bytes, length), &length).get());
if (!chars) {
return nullptr;
return false;
}
SourceText<char16_t> source;
if (!source.init(cx, std::move(chars), length)) {
return nullptr;
return false;
}
return CompileSourceBuffer(cx, options, source);
return CompileSourceBuffer(cx, options, source, script);
}
static JSScript* CompileUtf8DontInflate(JSContext* cx,
const ReadOnlyCompileOptions& options,
const char* bytes, size_t length) {
static bool CompileUtf8DontInflate(JSContext* cx,
const ReadOnlyCompileOptions& options,
const char* bytes, size_t length,
JS::MutableHandleScript script) {
SourceText<Utf8Unit> source;
if (!source.init(cx, bytes, length, SourceOwnership::Borrowed)) {
return nullptr;
return false;
}
return CompileSourceBuffer(cx, options, source);
return CompileSourceBuffer(cx, options, source, script);
}
JSScript* JS::Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
SourceText<char16_t>& srcBuf) {
return CompileSourceBuffer(cx, options, srcBuf);
bool JS::Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
SourceText<char16_t>& srcBuf, JS::MutableHandleScript script) {
return CompileSourceBuffer(cx, options, srcBuf, script);
}
JSScript* JS::CompileDontInflate(JSContext* cx,
const ReadOnlyCompileOptions& options,
SourceText<Utf8Unit>& srcBuf) {
return CompileSourceBuffer(cx, options, srcBuf);
bool JS::CompileDontInflate(JSContext* cx,
const ReadOnlyCompileOptions& options,
SourceText<Utf8Unit>& srcBuf,
JS::MutableHandleScript script) {
return CompileSourceBuffer(cx, options, srcBuf, script);
}
JSScript* JS::CompileUtf8(JSContext* cx, const ReadOnlyCompileOptions& options,
const char* bytes, size_t length) {
return ::CompileUtf8(cx, options, bytes, length);
bool JS::CompileUtf8(JSContext* cx, const ReadOnlyCompileOptions& options,
const char* bytes, size_t length,
JS::MutableHandleScript script) {
return ::CompileUtf8(cx, options, bytes, length, script);
}
JSScript* JS::CompileUtf8DontInflate(JSContext* cx,
const ReadOnlyCompileOptions& options,
const char* bytes, size_t length) {
return ::CompileUtf8DontInflate(cx, options, bytes, length);
bool JS::CompileUtf8DontInflate(JSContext* cx,
const ReadOnlyCompileOptions& options,
const char* bytes, size_t length,
JS::MutableHandleScript script) {
return ::CompileUtf8DontInflate(cx, options, bytes, length, script);
}
JSScript* JS::CompileUtf8File(JSContext* cx,
const ReadOnlyCompileOptions& options,
FILE* file) {
bool JS::CompileUtf8File(JSContext* cx, const ReadOnlyCompileOptions& options,
FILE* file, JS::MutableHandleScript script) {
FileContents buffer(cx);
if (!ReadCompleteFile(cx, file, buffer)) {
return nullptr;
return false;
}
return ::CompileUtf8(cx, options,
reinterpret_cast<const char*>(buffer.begin()),
buffer.length());
buffer.length(), script);
}
JSScript* JS::CompileUtf8FileDontInflate(JSContext* cx,
const ReadOnlyCompileOptions& options,
FILE* file) {
bool JS::CompileUtf8FileDontInflate(JSContext* cx,
const ReadOnlyCompileOptions& options,
FILE* file,
JS::MutableHandleScript script) {
FileContents buffer(cx);
if (!ReadCompleteFile(cx, file, buffer)) {
return nullptr;
return false;
}
return ::CompileUtf8DontInflate(cx, options,
reinterpret_cast<const char*>(buffer.begin()),
buffer.length());
buffer.length(), script);
}
JSScript* JS::CompileUtf8Path(JSContext* cx,
const ReadOnlyCompileOptions& optionsArg,
const char* filename) {
bool JS::CompileUtf8Path(JSContext* cx,
const ReadOnlyCompileOptions& optionsArg,
const char* filename, JS::MutableHandleScript script) {
AutoFile file;
if (!file.open(cx, filename)) {
return nullptr;
return false;
}
CompileOptions options(cx, optionsArg);
options.setFileAndLine(filename, 1);
return CompileUtf8File(cx, options, file.fp());
return CompileUtf8File(cx, options, file.fp(), script);
}
JSScript* JS::CompileForNonSyntacticScope(
JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
SourceText<char16_t>& srcBuf) {
bool JS::CompileForNonSyntacticScope(JSContext* cx,
const ReadOnlyCompileOptions& optionsArg,
SourceText<char16_t>& srcBuf,
JS::MutableHandleScript script) {
CompileOptions options(cx, optionsArg);
options.setNonSyntacticScope(true);
return CompileSourceBuffer(cx, options, srcBuf);
return CompileSourceBuffer(cx, options, srcBuf, script);
}
JSScript* JS::CompileUtf8ForNonSyntacticScope(
bool JS::CompileUtf8ForNonSyntacticScope(
JSContext* cx, const ReadOnlyCompileOptions& optionsArg, const char* bytes,
size_t length) {
size_t length, JS::MutableHandleScript script) {
CompileOptions options(cx, optionsArg);
options.setNonSyntacticScope(true);
return ::CompileUtf8(cx, options, bytes, length);
return ::CompileUtf8(cx, options, bytes, length, script);
}
JS_PUBLIC_API bool JS_Utf8BufferIsCompilableUnit(JSContext* cx,

Просмотреть файл

@ -144,8 +144,8 @@ bool AsyncScriptCompiler::StartCompile(JSContext* aCx) {
return true;
}
Rooted<JSScript*> script(aCx, JS::Compile(aCx, mOptions, srcBuf));
if (!script) {
Rooted<JSScript*> script(aCx);
if (!JS::Compile(aCx, mOptions, srcBuf, &script)) {
return false;
}

Просмотреть файл

@ -856,16 +856,22 @@ nsresult mozJSComponentLoader::ObjectForLocation(
// Note: exceptions will get handled further down;
// don't early return for them here.
auto buf = map.get<char>();
script = reuseGlobal ? CompileUtf8ForNonSyntacticScope(
cx, options, buf.get(), map.size())
: CompileUtf8(cx, options, buf.get(), map.size());
if (reuseGlobal) {
CompileUtf8ForNonSyntacticScope(cx, options, buf.get(), map.size(),
&script);
} else {
CompileUtf8(cx, options, buf.get(), map.size(), &script);
}
} else {
nsCString str;
MOZ_TRY_VAR(str, ReadScript(aInfo));
script = reuseGlobal ? CompileUtf8ForNonSyntacticScope(
cx, options, str.get(), str.Length())
: CompileUtf8(cx, options, str.get(), str.Length());
if (reuseGlobal) {
CompileUtf8ForNonSyntacticScope(cx, options, str.get(), str.Length(),
&script);
} else {
CompileUtf8(cx, options, str.get(), str.Length(), &script);
}
}
// Propagate the exception, if one exists. Also, don't leave the stale
// exception on this context.

Просмотреть файл

@ -126,10 +126,9 @@ static void ReportError(JSContext* cx, const char* origMsg, nsIURI* uri) {
ReportError(cx, msg);
}
static JSScript* PrepareScript(nsIURI* uri, JSContext* cx,
bool wantGlobalScript, const char* uriStr,
const char* buf, int64_t len,
bool wantReturnValue) {
static bool PrepareScript(nsIURI* uri, JSContext* cx, bool wantGlobalScript,
const char* uriStr, const char* buf, int64_t len,
bool wantReturnValue, MutableHandleScript script) {
JS::CompileOptions options(cx);
options.setFileAndLine(uriStr, 1).setNoScriptRval(!wantReturnValue);
@ -144,9 +143,9 @@ static JSScript* PrepareScript(nsIURI* uri, JSContext* cx,
options.setSourceIsLazy(true);
if (wantGlobalScript) {
return JS::CompileUtf8(cx, options, buf, len);
return JS::CompileUtf8(cx, options, buf, len, script);
}
return JS::CompileUtf8ForNonSyntacticScope(cx, options, buf, len);
return JS::CompileUtf8ForNonSyntacticScope(cx, options, buf, len, script);
}
static bool EvalScript(JSContext* cx, HandleObject targetObj,
@ -373,10 +372,9 @@ AsyncScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
RootedObject targetObj(cx, mTargetObj);
RootedObject loadScope(cx, mLoadScope);
script = PrepareScript(uri, cx, JS_IsGlobalObject(targetObj), spec.get(),
reinterpret_cast<const char*>(aBuf), aLength,
mWantReturnValue);
if (!script) {
if (!PrepareScript(uri, cx, JS_IsGlobalObject(targetObj), spec.get(),
reinterpret_cast<const char*>(aBuf), aLength,
mWantReturnValue, &script)) {
return NS_OK;
}
@ -442,9 +440,14 @@ nsresult mozJSSubScriptLoader::ReadScriptAsync(nsIURI* uri,
return channel->AsyncOpen(listener);
}
JSScript* mozJSSubScriptLoader::ReadScript(
nsIURI* uri, JSContext* cx, HandleObject targetObj, const char* uriStr,
nsIIOService* serv, bool wantReturnValue, bool useCompilationScope) {
bool mozJSSubScriptLoader::ReadScript(nsIURI* uri, JSContext* cx,
HandleObject targetObj,
const char* uriStr, nsIIOService* serv,
bool wantReturnValue,
bool useCompilationScope,
MutableHandleScript script) {
script.set(nullptr);
// We create a channel and call SetContentType, to avoid expensive MIME type
// lookups (bug 632490).
nsCOMPtr<nsIChannel> chan;
@ -467,7 +470,7 @@ JSScript* mozJSSubScriptLoader::ReadScript(
if (NS_FAILED(rv)) {
ReportError(cx, LOAD_ERROR_NOSTREAM, uri);
return nullptr;
return false;
}
int64_t len = -1;
@ -475,17 +478,17 @@ JSScript* mozJSSubScriptLoader::ReadScript(
rv = chan->GetContentLength(&len);
if (NS_FAILED(rv) || len == -1) {
ReportError(cx, LOAD_ERROR_NOCONTENT, uri);
return nullptr;
return false;
}
if (len > INT32_MAX) {
ReportError(cx, LOAD_ERROR_CONTENTTOOBIG, uri);
return nullptr;
return false;
}
nsCString buf;
rv = NS_ReadInputStreamToString(instream, buf, len);
NS_ENSURE_SUCCESS(rv, nullptr);
NS_ENSURE_SUCCESS(rv, false);
Maybe<JSAutoRealm> ar;
@ -502,7 +505,7 @@ JSScript* mozJSSubScriptLoader::ReadScript(
}
return PrepareScript(uri, cx, JS_IsGlobalObject(targetObj), uriStr, buf.get(),
len, wantReturnValue);
len, wantReturnValue, script);
}
NS_IMETHODIMP
@ -669,13 +672,10 @@ nsresult mozJSSubScriptLoader::DoLoadSubScriptWithOptions(
// |script| came from the cache, so don't bother writing it
// |back there.
cache = nullptr;
} else {
script =
ReadScript(uri, cx, targetObj, static_cast<const char*>(uriStr.get()),
serv, options.wantReturnValue, useCompilationScope);
if (!script) {
return NS_OK;
}
} else if (!ReadScript(
uri, cx, targetObj, static_cast<const char*>(uriStr.get()),
serv, options.wantReturnValue, useCompilationScope, &script)) {
return NS_OK;
}
Unused << EvalScript(cx, targetObj, loadScope, retval, uri, !!cache,

Просмотреть файл

@ -31,9 +31,9 @@ class mozJSSubScriptLoader : public mozIJSSubScriptLoader {
private:
virtual ~mozJSSubScriptLoader();
JSScript* ReadScript(nsIURI* uri, JSContext* cx, JS::HandleObject targetObj,
const char* uriStr, nsIIOService* serv,
bool wantReturnValue, bool useCompilationScope);
bool ReadScript(nsIURI* uri, JSContext* cx, JS::HandleObject targetObj,
const char* uriStr, nsIIOService* serv, bool wantReturnValue,
bool useCompilationScope, JS::MutableHandleScript script);
nsresult ReadScriptAsync(nsIURI* uri, JS::HandleObject targetObj,
JS::HandleObject loadScope, nsIIOService* serv,

Просмотреть файл

@ -367,7 +367,7 @@ static bool Load(JSContext* cx, unsigned argc, Value* vp) {
options.setFileAndLine(filename.get(), 1).setIsRunOnce(true);
JS::Rooted<JSScript*> script(cx);
JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
script = JS::CompileUtf8File(cx, options, file);
JS::CompileUtf8File(cx, options, file, &script);
fclose(file);
if (!script) {
return false;
@ -699,9 +699,8 @@ static bool ProcessUtf8Line(AutoJSAPI& jsapi, const char* buffer,
JS::CompileOptions options(cx);
options.setFileAndLine("typein", startline).setIsRunOnce(true);
JS::RootedScript script(cx,
JS::CompileUtf8(cx, options, buffer, strlen(buffer)));
if (!script) {
JS::RootedScript script(cx);
if (!JS::CompileUtf8(cx, options, buffer, strlen(buffer), &script)) {
return false;
}
if (compileOnly) {
@ -764,8 +763,7 @@ static bool ProcessFile(AutoJSAPI& jsapi, const char* filename, FILE* file,
options.setFileAndLine(filename, 1)
.setIsRunOnce(true)
.setNoScriptRval(true);
script = JS::CompileUtf8File(cx, options, file);
if (!script) {
if (!JS::CompileUtf8File(cx, options, file, &script)) {
return false;
}
return compileOnly || JS_ExecuteScript(cx, script, &unused);

Просмотреть файл

@ -706,7 +706,8 @@ nsresult ProxyAutoConfig::SetupJS() {
JS::Rooted<JSObject *> global(cx, mJSContext->Global());
auto CompilePACScript = [this](JSContext *cx) -> JSScript * {
auto CompilePACScript = [this](JSContext *cx,
JS::MutableHandle<JSScript *> script) {
JS::CompileOptions options(cx);
options.setFileAndLine(this->mPACURI.get(), 1);
@ -715,7 +716,7 @@ nsresult ProxyAutoConfig::SetupJS() {
const char *scriptData = this->mConcatenatedPACData.get();
size_t scriptLength = this->mConcatenatedPACData.Length();
if (mozilla::IsValidUtf8(scriptData, scriptLength)) {
return JS::CompileUtf8(cx, options, scriptData, scriptLength);
return JS::CompileUtf8(cx, options, scriptData, scriptLength, script);
}
// nsReadableUtils.h says that "ASCII" is a misnomer "for legacy reasons",
@ -725,14 +726,14 @@ nsresult ProxyAutoConfig::SetupJS() {
JS::SourceText<char16_t> source;
if (!source.init(cx, inflated.get(), inflated.Length(),
JS::SourceOwnership::Borrowed)) {
return nullptr;
return false;
}
return JS::Compile(cx, options, source);
return JS::Compile(cx, options, source, script);
};
JS::Rooted<JSScript *> script(cx, CompilePACScript(cx));
if (!script || !JS_ExecuteScript(cx, script)) {
JS::Rooted<JSScript *> script(cx);
if (!CompilePACScript(cx, &script) || !JS_ExecuteScript(cx, script)) {
nsString alertMessage(
NS_LITERAL_STRING("PAC file failed to install from "));
if (isDataURI) {