зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1626105 - Convert |JS::CompileForNonSyntacticScope| to |JS::CompileForNonSyntacticScopeDontInflate| semantics, and remove |JS::CompileForNonSyntacticScopeDontInflate|. r=evilpie
Differential Revision: https://phabricator.services.mozilla.com/D68908 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
e9cfd601ed
Коммит
1416a9aaa0
|
@ -202,25 +202,6 @@ nsresult nsJSUtils::ExecutionContext::JoinCompile(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static JSScript* CompileScript(
|
||||
JSContext* aCx, JS::Handle<JS::StackGCVector<JSObject*>> aScopeChain,
|
||||
JS::CompileOptions& aCompileOptions, JS::SourceText<char16_t>& aSrcBuf) {
|
||||
return aScopeChain.length() == 0
|
||||
? JS::Compile(aCx, aCompileOptions, aSrcBuf)
|
||||
: JS::CompileForNonSyntacticScope(aCx, aCompileOptions, aSrcBuf);
|
||||
}
|
||||
|
||||
static JSScript* CompileScript(
|
||||
JSContext* aCx, JS::Handle<JS::StackGCVector<JSObject*>> aScopeChain,
|
||||
JS::CompileOptions& aCompileOptions, JS::SourceText<Utf8Unit>& aSrcBuf) {
|
||||
// Once the UTF-8 overloads don't inflate, we can get rid of these two
|
||||
// |CompileScript| overloads and just call the JSAPI directly in the one
|
||||
// caller.
|
||||
return aScopeChain.length() == 0 ? JS::Compile(aCx, aCompileOptions, aSrcBuf)
|
||||
: JS::CompileForNonSyntacticScopeDontInflate(
|
||||
aCx, aCompileOptions, aSrcBuf);
|
||||
}
|
||||
|
||||
template <typename Unit>
|
||||
nsresult nsJSUtils::ExecutionContext::InternalCompile(
|
||||
JS::CompileOptions& aCompileOptions, JS::SourceText<Unit>& aSrcBuf) {
|
||||
|
@ -235,7 +216,10 @@ nsresult nsJSUtils::ExecutionContext::InternalCompile(
|
|||
#endif
|
||||
|
||||
MOZ_ASSERT(!mScript);
|
||||
mScript = CompileScript(mCx, mScopeChain, aCompileOptions, aSrcBuf);
|
||||
mScript =
|
||||
mScopeChain.length() == 0
|
||||
? JS::Compile(mCx, aCompileOptions, aSrcBuf)
|
||||
: JS::CompileForNonSyntacticScope(mCx, aCompileOptions, aSrcBuf);
|
||||
if (!mScript) {
|
||||
mSkip = true;
|
||||
mRv = EvaluationExceptionToNSResult(mCx);
|
||||
|
|
|
@ -230,24 +230,6 @@ extern JS_PUBLIC_API JSScript* CompileForNonSyntacticScope(
|
|||
JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
SourceText<mozilla::Utf8Unit>& srcBuf);
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*
|
||||
* The "DontInflate" suffix and (semantically unobservable) don't-inflate
|
||||
* characteristic are temporary while bugs in UTF-8 compilation are ironed out.
|
||||
* In the long term |JS::CompileForNonSyntacticScope| for UTF-8 will just never
|
||||
* inflate, and this separate function will die.
|
||||
*
|
||||
* NOTE: UTF-8 compilation is currently experimental, and it's possible it has
|
||||
* as-yet-undiscovered bugs that the UTF-16 compilation functions do not
|
||||
* have. Use only if you're willing to take a risk!
|
||||
*/
|
||||
extern JS_PUBLIC_API JSScript* CompileForNonSyntacticScopeDontInflate(
|
||||
JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
SourceText<mozilla::Utf8Unit>& srcBuf);
|
||||
|
||||
/**
|
||||
* Compile a function with envChain plus the global as its scope chain.
|
||||
* envChain must contain objects in the current compartment of cx. The actual
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "mozilla/Utf8.h" // mozilla::Utf8Unit
|
||||
|
||||
#include "js/CompilationAndEvaluation.h" // JS::Compile{,ForNonSyntacticScope{,DontInflate}}
|
||||
#include "js/CompilationAndEvaluation.h" // JS::Compile{,ForNonSyntacticScope}
|
||||
#include "js/SourceText.h" // JS::Source{Ownership,Text}
|
||||
#include "jsapi-tests/tests.h"
|
||||
#include "vm/HelperThreads.h"
|
||||
|
@ -78,7 +78,7 @@ bool testCompile(bool nonSyntactic) {
|
|||
JS::SourceText<mozilla::Utf8Unit> buf8;
|
||||
CHECK(buf8.init(cx, src, length, JS::SourceOwnership::Borrowed));
|
||||
|
||||
script = CompileForNonSyntacticScopeDontInflate(cx, options, buf8);
|
||||
script = CompileForNonSyntacticScope(cx, options, buf8);
|
||||
CHECK(script);
|
||||
CHECK_EQUAL(script->hasNonSyntacticScope(), true);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "mozilla/ArrayUtils.h" // mozilla::ArrayLength
|
||||
#include "mozilla/Utf8.h" // mozilla::Utf8Unit
|
||||
|
||||
#include "js/CompilationAndEvaluation.h" // JS::CompileForNonSyntacticScopeDontInflate
|
||||
#include "js/CompilationAndEvaluation.h" // JS::CompileForNonSyntacticScope
|
||||
#include "js/PropertySpec.h"
|
||||
#include "js/SourceText.h" // JS::Source{Ownership,Text}
|
||||
#include "jsapi-tests/tests.h"
|
||||
|
@ -33,8 +33,8 @@ BEGIN_TEST(testExecuteInJSMEnvironment_Basic) {
|
|||
CHECK(srcBuf.init(cx, src, mozilla::ArrayLength(src) - 1,
|
||||
JS::SourceOwnership::Borrowed));
|
||||
|
||||
JS::RootedScript script(
|
||||
cx, JS::CompileForNonSyntacticScopeDontInflate(cx, options, srcBuf));
|
||||
JS::RootedScript script(cx,
|
||||
JS::CompileForNonSyntacticScope(cx, options, srcBuf));
|
||||
CHECK(script);
|
||||
|
||||
JS::RootedObject varEnv(cx, js::NewJSMEnvironment(cx));
|
||||
|
@ -91,8 +91,8 @@ BEGIN_TEST(testExecuteInJSMEnvironment_Callback) {
|
|||
CHECK(srcBuf.init(cx, src, mozilla::ArrayLength(src) - 1,
|
||||
JS::SourceOwnership::Borrowed));
|
||||
|
||||
JS::RootedScript script(
|
||||
cx, JS::CompileForNonSyntacticScopeDontInflate(cx, options, srcBuf));
|
||||
JS::RootedScript script(cx,
|
||||
JS::CompileForNonSyntacticScope(cx, options, srcBuf));
|
||||
CHECK(script);
|
||||
|
||||
JS::RootedObject nsvo(cx, js::NewJSMEnvironment(cx));
|
||||
|
|
|
@ -77,28 +77,6 @@ static JSScript* CompileSourceBuffer(JSContext* cx,
|
|||
return frontend::CompileGlobalScript(compilationInfo, globalsc, srcBuf);
|
||||
}
|
||||
|
||||
static JSScript* CompileUtf8Inflating(JSContext* cx,
|
||||
const ReadOnlyCompileOptions& options,
|
||||
SourceText<Utf8Unit>& srcBuf) {
|
||||
auto bytes = srcBuf.get();
|
||||
size_t length = srcBuf.length();
|
||||
|
||||
auto chars = UniqueTwoByteChars(
|
||||
UTF8CharsToNewTwoByteCharsZ(cx, UTF8Chars(bytes, length), &length,
|
||||
js::MallocArena)
|
||||
.get());
|
||||
if (!chars) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SourceText<char16_t> source;
|
||||
if (!source.init(cx, std::move(chars), length)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return CompileSourceBuffer(cx, options, source);
|
||||
}
|
||||
|
||||
JSScript* JS::Compile(JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
SourceText<char16_t>& srcBuf) {
|
||||
return CompileSourceBuffer(cx, options, srcBuf);
|
||||
|
@ -152,14 +130,6 @@ JSScript* JS::CompileForNonSyntacticScope(
|
|||
SourceText<Utf8Unit>& srcBuf) {
|
||||
CompileOptions options(cx, optionsArg);
|
||||
options.setNonSyntacticScope(true);
|
||||
return CompileUtf8Inflating(cx, options, srcBuf);
|
||||
}
|
||||
|
||||
JSScript* JS::CompileForNonSyntacticScopeDontInflate(
|
||||
JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
|
||||
SourceText<Utf8Unit>& srcBuf) {
|
||||
CompileOptions options(cx, optionsArg);
|
||||
options.setNonSyntacticScope(true);
|
||||
return CompileSourceBuffer(cx, options, srcBuf);
|
||||
}
|
||||
|
||||
|
|
|
@ -859,8 +859,7 @@ nsresult mozJSComponentLoader::ObjectForLocation(
|
|||
JS::SourceText<mozilla::Utf8Unit> srcBuf;
|
||||
if (srcBuf.init(cx, buf.get(), map.size(),
|
||||
JS::SourceOwnership::Borrowed)) {
|
||||
script = reuseGlobal ? CompileForNonSyntacticScopeDontInflate(
|
||||
cx, options, srcBuf)
|
||||
script = reuseGlobal ? CompileForNonSyntacticScope(cx, options, srcBuf)
|
||||
: Compile(cx, options, srcBuf);
|
||||
} else {
|
||||
MOZ_ASSERT(!script);
|
||||
|
@ -872,8 +871,7 @@ nsresult mozJSComponentLoader::ObjectForLocation(
|
|||
JS::SourceText<mozilla::Utf8Unit> srcBuf;
|
||||
if (srcBuf.init(cx, str.get(), str.Length(),
|
||||
JS::SourceOwnership::Borrowed)) {
|
||||
script = reuseGlobal ? CompileForNonSyntacticScopeDontInflate(
|
||||
cx, options, srcBuf)
|
||||
script = reuseGlobal ? CompileForNonSyntacticScope(cx, options, srcBuf)
|
||||
: Compile(cx, options, srcBuf);
|
||||
} else {
|
||||
MOZ_ASSERT(!script);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "xpcprivate.h" // xpc::OptionsBase
|
||||
#include "js/CompilationAndEvaluation.h" // JS::Compile{,ForNonSyntacticScopeDontInflate}
|
||||
#include "js/CompilationAndEvaluation.h" // JS::Compile{,ForNonSyntacticScope}
|
||||
#include "js/SourceText.h" // JS::Source{Ownership,Text}
|
||||
#include "js/Wrapper.h"
|
||||
|
||||
|
@ -147,7 +147,7 @@ static JSScript* PrepareScript(nsIURI* uri, JSContext* cx,
|
|||
if (wantGlobalScript) {
|
||||
return JS::Compile(cx, options, srcBuf);
|
||||
}
|
||||
return JS::CompileForNonSyntacticScopeDontInflate(cx, options, srcBuf);
|
||||
return JS::CompileForNonSyntacticScope(cx, options, srcBuf);
|
||||
}
|
||||
|
||||
static bool EvalScript(JSContext* cx, HandleObject targetObj,
|
||||
|
|
Загрузка…
Ссылка в новой задаче