зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1575055 - Privatize js::CompileOptions::strictMode. r=jandem
We already have an accessor to make sure this is can only be set but not cleared so hide the underlying storage. Differential Revision: https://phabricator.services.mozilla.com/D42559 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
f6f8dc5112
Коммит
5aa2fa2264
|
@ -103,6 +103,10 @@ class JS_PUBLIC_API TransitiveCompileOptions {
|
|||
// conditions are checked in the CompileOptions constructor.
|
||||
bool forceFullParse_ = false;
|
||||
|
||||
// Either the Realm configuration or the compile request may force
|
||||
// strict-mode.
|
||||
bool forceStrictMode_ = false;
|
||||
|
||||
const char* filename_ = nullptr;
|
||||
const char* introducerFilename_ = nullptr;
|
||||
const char16_t* sourceMapURL_ = nullptr;
|
||||
|
@ -111,7 +115,6 @@ class JS_PUBLIC_API TransitiveCompileOptions {
|
|||
// POD options.
|
||||
bool selfHostingMode = false;
|
||||
bool canLazilyParse = true;
|
||||
bool strictOption = false;
|
||||
bool extraWarningsOption = false;
|
||||
bool werrorOption = false;
|
||||
AsmJSOption asmJSOption = AsmJSOption::Disabled;
|
||||
|
@ -148,6 +151,7 @@ class JS_PUBLIC_API TransitiveCompileOptions {
|
|||
// depends on the derived type.
|
||||
bool mutedErrors() const { return mutedErrors_; }
|
||||
bool forceFullParse() const { return forceFullParse_; }
|
||||
bool forceStrictMode() const { return forceStrictMode_; }
|
||||
const char* filename() const { return filename_; }
|
||||
const char* introducerFilename() const { return introducerFilename_; }
|
||||
const char16_t* sourceMapURL() const { return sourceMapURL_; }
|
||||
|
@ -439,8 +443,8 @@ class MOZ_STACK_CLASS JS_PUBLIC_API CompileOptions final
|
|||
CompileOptions& setIntroductionInfoToCaller(JSContext* cx,
|
||||
const char* introductionType);
|
||||
|
||||
CompileOptions& maybeMakeStrictMode(bool strict) {
|
||||
strictOption = strictOption || strict;
|
||||
CompileOptions& setForceStrictMode() {
|
||||
forceStrictMode_ = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -294,9 +294,12 @@ static bool EvalKernel(JSContext* cx, HandleValue v, EvalType evalType,
|
|||
options.setIsRunOnce(true)
|
||||
.setNoScriptRval(false)
|
||||
.setMutedErrors(mutedErrors)
|
||||
.maybeMakeStrictMode(evalType == DIRECT_EVAL && IsStrictEvalPC(pc))
|
||||
.setScriptOrModule(maybeScript);
|
||||
|
||||
if (evalType == DIRECT_EVAL && IsStrictEvalPC(pc)) {
|
||||
options.setForceStrictMode();
|
||||
}
|
||||
|
||||
if (introducerFilename) {
|
||||
options.setFileAndLine(filename, 1);
|
||||
options.setIntroductionInfo(introducerFilename, "eval", lineno,
|
||||
|
@ -381,10 +384,13 @@ bool js::DirectEvalStringFromIon(JSContext* cx, HandleObject env,
|
|||
RootedScope enclosing(cx, callerScript->innermostScope(pc));
|
||||
|
||||
CompileOptions options(cx);
|
||||
options.setIsRunOnce(true)
|
||||
.setNoScriptRval(false)
|
||||
.setMutedErrors(mutedErrors)
|
||||
.maybeMakeStrictMode(IsStrictEvalPC(pc));
|
||||
options.setIsRunOnce(true);
|
||||
options.setNoScriptRval(false);
|
||||
options.setMutedErrors(mutedErrors);
|
||||
|
||||
if (IsStrictEvalPC(pc)) {
|
||||
options.setForceStrictMode();
|
||||
}
|
||||
|
||||
if (introducerFilename) {
|
||||
options.setFileAndLine(filename, 1);
|
||||
|
|
|
@ -789,9 +789,11 @@ static bool EvaluateInEnv(JSContext* cx, Handle<Env*> env,
|
|||
options.setIsRunOnce(true)
|
||||
.setNoScriptRval(false)
|
||||
.setFileAndLine(filename, lineno)
|
||||
.setIntroductionType("debugger eval")
|
||||
.maybeMakeStrictMode(frame && frame.hasScript() ? frame.script()->strict()
|
||||
: false);
|
||||
.setIntroductionType("debugger eval");
|
||||
|
||||
if (frame && frame.hasScript() && frame.script()->strict()) {
|
||||
options.setForceStrictMode();
|
||||
}
|
||||
|
||||
SourceText<char16_t> srcBuf;
|
||||
if (!srcBuf.init(cx, chars.begin().get(), chars.length(),
|
||||
|
|
|
@ -393,7 +393,7 @@ BytecodeCompiler::BytecodeCompiler(JSContext* cx,
|
|||
cx(cx),
|
||||
options(options),
|
||||
sourceObject(cx),
|
||||
directives(options.strictOption),
|
||||
directives(options.forceStrictMode()),
|
||||
script(cx) {}
|
||||
|
||||
bool BytecodeCompiler::createScriptSource(
|
||||
|
@ -753,7 +753,7 @@ JSScript* frontend::CompileGlobalBinASTScript(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Directives directives(options.strictOption);
|
||||
Directives directives(options.forceStrictMode());
|
||||
GlobalSharedContext globalsc(cx, ScopeKind::Global, directives,
|
||||
options.extraWarningsOption);
|
||||
|
||||
|
@ -804,8 +804,8 @@ static ModuleObject* InternalParseModule(
|
|||
AutoAssertReportedException assertException(cx);
|
||||
|
||||
CompileOptions options(cx, optionsInput);
|
||||
options.maybeMakeStrictMode(
|
||||
true); // ES6 10.2.1 Module code is always strict mode code.
|
||||
options.setForceStrictMode(); // ES6 10.2.1 Module code is always strict mode
|
||||
// code.
|
||||
options.setIsRunOnce(true);
|
||||
options.allowHTMLComments = false;
|
||||
|
||||
|
|
|
@ -439,7 +439,7 @@ template <class ParseHandler, typename Unit>
|
|||
typename ParseHandler::ListNodeType GeneralParser<ParseHandler, Unit>::parse() {
|
||||
MOZ_ASSERT(checkOptionsCalled_);
|
||||
|
||||
Directives directives(options().strictOption);
|
||||
Directives directives(options().forceStrictMode());
|
||||
GlobalSharedContext globalsc(cx_, ScopeKind::Global, directives,
|
||||
options().extraWarningsOption);
|
||||
SourceParseContext globalpc(this, &globalsc, /* newDirectives = */ nullptr);
|
||||
|
|
|
@ -3526,9 +3526,9 @@ void JS::TransitiveCompileOptions::copyPODTransitiveOptions(
|
|||
const TransitiveCompileOptions& rhs) {
|
||||
mutedErrors_ = rhs.mutedErrors_;
|
||||
forceFullParse_ = rhs.forceFullParse_;
|
||||
forceStrictMode_ = rhs.forceStrictMode_;
|
||||
selfHostingMode = rhs.selfHostingMode;
|
||||
canLazilyParse = rhs.canLazilyParse;
|
||||
strictOption = rhs.strictOption;
|
||||
extraWarningsOption = rhs.extraWarningsOption;
|
||||
werrorOption = rhs.werrorOption;
|
||||
asmJSOption = rhs.asmJSOption;
|
||||
|
@ -3624,7 +3624,6 @@ JS::CompileOptions::CompileOptions(JSContext* cx)
|
|||
elementAttributeNameRoot(cx),
|
||||
introductionScriptRoot(cx),
|
||||
scriptOrModuleRoot(cx) {
|
||||
strictOption = cx->options().strictMode();
|
||||
extraWarningsOption = cx->realm()->behaviors().extraWarnings(cx);
|
||||
discardSource = cx->realm()->behaviors().discardSource();
|
||||
werrorOption = cx->options().werror();
|
||||
|
@ -3639,6 +3638,9 @@ JS::CompileOptions::CompileOptions(JSContext* cx)
|
|||
cx->options().throwOnAsmJSValidationFailure();
|
||||
fieldsEnabledOption = cx->realm()->creationOptions().getFieldsEnabled();
|
||||
|
||||
// Certain modes of operation force strict-mode in general.
|
||||
forceStrictMode_ = cx->options().strictMode();
|
||||
|
||||
// Certain modes of operation disallow syntax parsing in general.
|
||||
forceFullParse_ = cx->realm()->behaviors().disableLazyParsing() ||
|
||||
coverage::IsLCovEnabled();
|
||||
|
|
|
@ -951,7 +951,7 @@ static bool InitModuleLoader(JSContext* cx) {
|
|||
options.setSelfHostingMode(false);
|
||||
options.setCanLazilyParse(false);
|
||||
options.werrorOption = true;
|
||||
options.strictOption = true;
|
||||
options.setForceStrictMode();
|
||||
|
||||
JS::SourceText<Utf8Unit> srcBuf;
|
||||
if (!srcBuf.init(cx, std::move(src), srcLen)) {
|
||||
|
@ -5245,7 +5245,7 @@ static bool Parse(JSContext* cx, unsigned argc, Value* vp) {
|
|||
options.setIntroductionType("js shell parse").setFileAndLine("<string>", 1);
|
||||
if (goal == frontend::ParseGoal::Module) {
|
||||
// See frontend::CompileModule.
|
||||
options.maybeMakeStrictMode(true);
|
||||
options.setForceStrictMode();
|
||||
options.allowHTMLComments = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -2628,8 +2628,8 @@ void js::FillSelfHostingCompileOptions(CompileOptions& options) {
|
|||
options.setSelfHostingMode(true);
|
||||
options.setCanLazilyParse(false);
|
||||
options.werrorOption = true;
|
||||
options.strictOption = true;
|
||||
options.extraWarningsOption = true;
|
||||
options.setForceStrictMode();
|
||||
}
|
||||
|
||||
GlobalObject* JSRuntime::createSelfHostingGlobal(JSContext* cx) {
|
||||
|
|
|
@ -6936,7 +6936,7 @@ static bool HandleInstantiationFailure(JSContext* cx, CallArgs args,
|
|||
// The exported function inherits an implicit strict context if the module
|
||||
// also inherited it somehow.
|
||||
if (metadata.strict) {
|
||||
options.strictOption = true;
|
||||
options.setForceStrictMode();
|
||||
}
|
||||
|
||||
AutoStableStringChars stableChars(cx);
|
||||
|
|
|
@ -845,7 +845,7 @@ nsresult mozJSComponentLoader::ObjectForLocation(
|
|||
// See bug 1303754.
|
||||
CompileOptions options(cx);
|
||||
options.setNoScriptRval(true)
|
||||
.maybeMakeStrictMode(true)
|
||||
.setForceStrictMode()
|
||||
.setFileAndLine(nativePath.get(), 1)
|
||||
.setSourceIsLazy(cache || ScriptPreloader::GetSingleton().Active());
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче