Bug 1491137 - Remove JS_Compile{,UC}Script, because except for argument ordering they're exactly identical to existing JS::Compile* functions. r=jandem

--HG--
extra : rebase_source : 89ae632dbc654f1f29f8186955042d4586aeeeff
This commit is contained in:
Jeff Walden 2018-09-13 16:41:00 -07:00
Родитель c1d9c9d203
Коммит 9667f8bf7d
13 изменённых файлов: 74 добавлений и 90 удалений

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

@ -341,7 +341,7 @@ XPCShellEnvironment::ProcessFile(JSContext *cx,
options.setUTF8(true);
JS::Rooted<JSScript*> script(cx);
if (JS_CompileScript(cx, buffer, strlen(buffer), options, &script)) {
if (JS::CompileUtf8(cx, options, buffer, strlen(buffer), &script)) {
JS::WarningReporter older;
ok = JS_ExecuteScript(cx, script, &result);
@ -492,10 +492,11 @@ XPCShellEnvironment::EvaluateString(const nsString& aString,
JS::CompileOptions options(cx);
options.setFileAndLine("typein", 0);
JS::Rooted<JSScript*> script(cx);
JS::SourceBufferHolder srcBuf(aString.get(), aString.Length(),
JS::SourceBufferHolder::NoOwnership);
if (!JS_CompileUCScript(cx, srcBuf, options, &script))
if (!JS::Compile(cx, options, srcBuf, &script))
{
return false;
}

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

@ -85,22 +85,6 @@ JS_ExecuteScript(JSContext* cx, JS::AutoVector<JSObject*>& envChain,
extern JS_PUBLIC_API(bool)
JS_ExecuteScript(JSContext* cx, JS::AutoVector<JSObject*>& envChain, JS::Handle<JSScript*> script);
/**
* |script| will always be set. On failure, it will be set to nullptr.
*/
extern JS_PUBLIC_API(bool)
JS_CompileScript(JSContext* cx, const char* bytes, size_t length,
const JS::CompileOptions& options,
JS::MutableHandle<JSScript*> script);
/**
* |script| will always be set. On failure, it will be set to nullptr.
*/
extern JS_PUBLIC_API(bool)
JS_CompileUCScript(JSContext* cx, JS::SourceBufferHolder& srcBuf,
const JS::CompileOptions& options,
JS::MutableHandle<JSScript*> script);
namespace JS {
/**
@ -186,33 +170,6 @@ extern JS_PUBLIC_API(bool)
CompileLatin1(JSContext* cx, const ReadOnlyCompileOptions& options,
const char* bytes, size_t length, MutableHandle<JSScript*> script);
/**
* DEPRECATED
*
* Compile the provided bytes into a script.
*
* If |options.utf8|, the bytes are interpreted as UTF-8 data. If the data
* contains any malformed UTF-8, an error is reported.
*
* Otherwise they are interpreted as Latin-1, i.e. each byte directly
* corresponds to the same Unicode code point.
*
* |script| is always set to the compiled script or to null in case of error.
*
* Do not use this API. The JS::CompileOptions::utf8 flag that indicates how
* to interpret |bytes| is currently being replaced by functions indicating an
* exact expected encoding. If you have byte data to compile, you should use
* either JS::CompileUtf8 or JS::CompileLatin1, as appropriate.
*/
inline bool
Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
const char* bytes, size_t length, MutableHandle<JSScript*> script)
{
return options.utf8
? CompileUtf8(cx, options, bytes, length, script)
: CompileLatin1(cx, options, bytes, length, script);
}
/**
* Compile the UTF-8 contents of the given file into a script. If the contents
* contain any malformed UTF-8, an error is reported.

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

@ -71,14 +71,12 @@ testCompile(bool nonSyntactic)
static_assert(sizeof(src_16) / sizeof(*src_16) - 1 == length,
"Source buffers must be same length");
JS::SourceBufferHolder buf(src_16, length, JS::SourceBufferHolder::NoOwnership);
JS::CompileOptions options(cx);
options.setNonSyntacticScope(nonSyntactic);
JS::RootedScript script(cx);
JS::SourceBufferHolder buf(src_16, length, JS::SourceBufferHolder::NoOwnership);
// Check explicit non-syntactic compilation first to make sure it doesn't
// modify our options object.
@ -98,7 +96,7 @@ testCompile(bool nonSyntactic)
CHECK(Compile(cx, options, buf, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);
CHECK(Compile(cx, options, src, length, &script));
CHECK(CompileLatin1(cx, options, src, length, &script));
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);
{

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

@ -27,9 +27,12 @@ BEGIN_TEST(testGCCellPtr)
CHECK(str);
const char* code = "function foo() { return 'bar'; }";
JS::CompileOptions opts(cx);
opts.setUTF8(true);
JS::RootedScript script(cx);
CHECK(JS_CompileScript(cx, code, strlen(code), opts, &script));
CHECK(JS::CompileUtf8(cx, opts, code, strlen(code), &script));
CHECK(script);
CHECK(!JS::GCCellPtr(nullptr));

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

@ -43,11 +43,14 @@ BEGIN_TEST(testPrivateGCThingValue)
CHECK(obj);
// Make a JSScript to stick into a PrivateGCThingValue.
JS::RootedScript script(cx);
const char code[] = "'objet petit a'";
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
CHECK(JS_CompileScript(cx, code, sizeof(code) - 1, options, &script));
options.setUTF8(true);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, code, sizeof(code) - 1, &script));
JS_SetReservedSlot(obj, 0, PrivateGCThingValue(script));
TestTracer trc(cx);

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

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

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

@ -44,8 +44,11 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript)
{
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
options.setUTF8(true);
JS::RootedScript script(cx);
CHECK(JS_CompileScript(cx, code, code_size, options, &script));
CHECK(JS::CompileUtf8(cx, options, code, code_size, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript)
@ -54,8 +57,11 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript_empty)
{
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
options.setUTF8(true);
JS::RootedScript script(cx);
CHECK(JS_CompileScript(cx, "", 0, options, &script));
CHECK(JS::CompileUtf8(cx, options, "", 0, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript_empty)
@ -64,8 +70,11 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScriptForPrincipals)
{
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
options.setUTF8(true);
JS::RootedScript script(cx);
CHECK(JS_CompileScript(cx, code, code_size, options, &script));
CHECK(JS::CompileUtf8(cx, options, code, code_size, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScriptForPrincipals)
@ -74,9 +83,11 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript)
{
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx);
JS::SourceBufferHolder srcBuf(uc_code, code_size, JS::SourceBufferHolder::NoOwnership);
CHECK(JS_CompileUCScript(cx, srcBuf, options, &script));
CHECK(JS::Compile(cx, options, srcBuf, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript)
@ -85,9 +96,11 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty)
{
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx);
JS::SourceBufferHolder srcBuf(uc_code, 0, JS::SourceBufferHolder::NoOwnership);
CHECK(JS_CompileUCScript(cx, srcBuf, options, &script));
CHECK(JS::Compile(cx, options, srcBuf, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty)
@ -96,9 +109,11 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScriptForPrincipal
{
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
JS::RootedScript script(cx);
JS::SourceBufferHolder srcBuf(uc_code, code_size, JS::SourceBufferHolder::NoOwnership);
CHECK(JS_CompileUCScript(cx, srcBuf, options, &script));
CHECK(JS::Compile(cx, options, srcBuf, &script));
return tryScript(script);
}
END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScriptForPrincipals)
@ -196,10 +211,14 @@ BEGIN_FIXTURE_TEST(ScriptObjectFixture, CloneAndExecuteScript)
JS::RootedValue fortyTwo(cx);
fortyTwo.setInt32(42);
CHECK(JS_SetProperty(cx, global, "val", fortyTwo));
JS::RootedScript script(cx);
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
CHECK(JS_CompileScript(cx, "val", 3, options, &script));
options.setUTF8(true);
JS::RootedScript script(cx);
CHECK(JS::CompileUtf8(cx, options, "val", 3, &script));
JS::RootedValue value(cx);
CHECK(JS_ExecuteScript(cx, script, &value));
CHECK(value.toInt32() == 42);

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

@ -88,12 +88,13 @@ BEGIN_TEST(test_ubiNodeZone)
CHECK(JS::ubi::Node(global2).zone() != global1->zone());
JS::CompileOptions options(cx);
options.setUTF8(true);
// Create a string and a script in the original zone...
RootedString string1(cx, JS_NewStringCopyZ(cx, "Simpson's Individual Stringettes!"));
CHECK(string1);
RootedScript script1(cx);
CHECK(JS::Compile(cx, options, "", 0, &script1));
CHECK(JS::CompileUtf8(cx, options, "", 0, &script1));
{
// ... and then enter global2's zone and create a string and script
@ -103,7 +104,7 @@ BEGIN_TEST(test_ubiNodeZone)
RootedString string2(cx, JS_NewStringCopyZ(cx, "A million household uses!"));
CHECK(string2);
RootedScript script2(cx);
CHECK(JS::Compile(cx, options, "", 0, &script2));
CHECK(JS::CompileUtf8(cx, options, "", 0, &script2));
CHECK(JS::ubi::Node(string1).zone() == global1->zone());
CHECK(JS::ubi::Node(script1).zone() == global1->zone());
@ -135,10 +136,11 @@ BEGIN_TEST(test_ubiNodeCompartment)
CHECK(JS::ubi::Node(global2).realm() != global1->nonCCWRealm());
JS::CompileOptions options(cx);
options.setUTF8(true);
// Create a script in the original realm...
RootedScript script1(cx);
CHECK(JS::Compile(cx, options, "", 0, &script1));
CHECK(JS::CompileUtf8(cx, options, "", 0, &script1));
{
// ... and then enter global2's realm and create a script
@ -146,7 +148,7 @@ BEGIN_TEST(test_ubiNodeCompartment)
JSAutoRealm ar(cx, global2);
RootedScript script2(cx);
CHECK(JS::Compile(cx, options, "", 0, &script2));
CHECK(JS::CompileUtf8(cx, options, "", 0, &script2));
CHECK(JS::ubi::Node(script1).compartment() == global1->compartment());
CHECK(JS::ubi::Node(script2).compartment() == global2->compartment());

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

@ -64,8 +64,10 @@ BEGIN_TEST(testXDR_bug506491)
// compile
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
options.setUTF8(true);
JS::RootedScript script(cx);
CHECK(JS_CompileScript(cx, s, strlen(s), options, &script));
CHECK(JS::CompileUtf8(cx, options, s, strlen(s), &script));
CHECK(script);
script = FreezeThaw(cx, script);
@ -91,8 +93,10 @@ BEGIN_TEST(testXDR_bug516827)
// compile an empty script
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
options.setUTF8(true);
JS::RootedScript script(cx);
CHECK(JS_CompileScript(cx, "", 0, options, &script));
CHECK(JS::CompileUtf8(cx, options, "", 0, &script));
CHECK(script);
script = FreezeThaw(cx, script);
@ -115,13 +119,18 @@ BEGIN_TEST(testXDR_source)
for (const char** s = samples; *s; s++) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
options.setUTF8(true);
JS::RootedScript script(cx);
CHECK(JS_CompileScript(cx, *s, strlen(*s), options, &script));
CHECK(JS::CompileUtf8(cx, options, *s, strlen(*s), &script));
CHECK(script);
script = FreezeThaw(cx, script);
CHECK(script);
JSString* out = JS_DecompileScript(cx, script);
CHECK(out);
bool equal;
CHECK(JS_StringEqualsAscii(cx, out, *s, &equal));
CHECK(equal);
@ -141,7 +150,9 @@ BEGIN_TEST(testXDR_sourceMap)
for (const char** sm = sourceMaps; *sm; sm++) {
JS::CompileOptions options(cx);
options.setFileAndLine(__FILE__, __LINE__);
CHECK(JS_CompileScript(cx, "", 0, options, &script));
options.setUTF8(true);
CHECK(JS::CompileUtf8(cx, options, "", 0, &script));
CHECK(script);
size_t len = strlen(*sm);

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

@ -2338,7 +2338,8 @@ Run(JSContext* cx, unsigned argc, Value* vp)
.setFileAndLine(filename.get(), 1)
.setIsRunOnce(true)
.setNoScriptRval(true);
if (!JS_CompileUCScript(cx, srcBuf, options, &script)) {
if (!JS::Compile(cx, options, srcBuf, &script)) {
return false;
}
}
@ -4603,7 +4604,7 @@ Compile(JSContext* cx, unsigned argc, Value* vp)
JS::SourceBufferHolder srcBuf(stableChars.twoByteRange().begin().get(),
scriptContents->length(),
JS::SourceBufferHolder::NoOwnership);
bool ok = JS_CompileUCScript(cx, srcBuf, options, &script);
bool ok = JS::Compile(cx, options, srcBuf, &script);
args.rval().setUndefined();
return ok;
}

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

@ -171,22 +171,6 @@ JS::CompileLatin1ForNonSyntacticScope(JSContext* cx, const ReadOnlyCompileOption
return ::CompileLatin1(cx, options, bytes, length, script);
}
JS_PUBLIC_API(bool)
JS_CompileScript(JSContext* cx, const char* bytes, size_t length,
const JS::CompileOptions& options, MutableHandleScript script)
{
return options.utf8
? ::CompileUtf8(cx, options, bytes, length, script)
: ::CompileLatin1(cx, options, bytes, length, script);
}
JS_PUBLIC_API(bool)
JS_CompileUCScript(JSContext* cx, JS::SourceBufferHolder& srcBuf,
const JS::CompileOptions& options, MutableHandleScript script)
{
return CompileSourceBuffer(cx, options, srcBuf, script);
}
JS_PUBLIC_API(bool)
JS_Utf8BufferIsCompilableUnit(JSContext* cx, HandleObject obj, const char* utf8, size_t length)
{

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

@ -739,7 +739,7 @@ ProcessUtf8Line(AutoJSAPI& jsapi, const char* buffer, int startline)
.setUTF8(true);
JS::RootedScript script(cx);
if (!JS_CompileScript(cx, buffer, strlen(buffer), options, &script)) {
if (!JS::CompileUtf8(cx, options, buffer, strlen(buffer), &script)) {
return false;
}
if (compileOnly) {

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

@ -757,11 +757,14 @@ ProxyAutoConfig::SetupJS()
bool isDataURI = nsDependentCSubstring(mPACURI, 0, 5).LowerCaseEqualsASCII("data:", 5);
SetRunning(this);
JS::Rooted<JSObject*> global(cx, mJSContext->Global());
JS::CompileOptions options(cx);
options.setFileAndLine(mPACURI.get(), 1);
JS::Rooted<JSScript*> script(cx);
if (!JS_CompileScript(cx, mPACScript.get(), mPACScript.Length(), options,
if (!JS::CompileLatin1(cx, options, mPACScript.get(), mPACScript.Length(),
&script) ||
!JS_ExecuteScript(cx, script))
{