зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1426519 - Disable expression closures everywhere, but allow dynamic enabling them for tests. r=jandem
--HG-- extra : rebase_source : 8f17e69ba1a372fb692b0e0f69d4a54fc6926098 extra : histedit_source : 5d50c395fa592f96f4fb65b9b37323ddf93b9e28
This commit is contained in:
Родитель
082991a7bc
Коммит
693cf81007
|
@ -4963,6 +4963,24 @@ IsLegacyIterator(JSContext* cx, unsigned argc, Value* vp)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
EnableExpressionClosures(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JS::ContextOptionsRef(cx).setExpressionClosures(true);
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
DisableExpressionClosures(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
JS::ContextOptionsRef(cx).setExpressionClosures(false);
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
|
||||
static const JSFunctionSpecWithHelp TestingFunctions[] = {
|
||||
JS_FN_HELP("gc", ::GC, 0, 0,
|
||||
"gc([obj] | 'zone' [, 'shrinking'])",
|
||||
|
@ -5579,6 +5597,14 @@ gc::ZealModeHelpText),
|
|||
"getTimeZone()",
|
||||
" Get the current time zone.\n"),
|
||||
|
||||
JS_FN_HELP("enableExpressionClosures", EnableExpressionClosures, 0, 0,
|
||||
"enableExpressionClosures()",
|
||||
" Enables the deprecated, non-standard expression closures.\n"),
|
||||
|
||||
JS_FN_HELP("disableExpressionClosures", DisableExpressionClosures, 0, 0,
|
||||
"disableExpressionClosures()",
|
||||
" Disables the deprecated, non-standard expression closures.\n"),
|
||||
|
||||
JS_FS_HELP_END
|
||||
};
|
||||
|
||||
|
|
|
@ -3260,15 +3260,15 @@ Parser<FullParseHandler, CharT>::skipLazyInnerFunction(ParseNode* funcNode, uint
|
|||
if (!tokenStream.advance(fun->lazyScript()->end()))
|
||||
return false;
|
||||
|
||||
#if JS_HAS_EXPR_CLOSURES
|
||||
// Only expression closure can be Statement kind.
|
||||
// If we remove expression closure, we can remove isExprBody flag from
|
||||
// LazyScript and JSScript.
|
||||
if (kind == Statement && funbox->isExprBody()) {
|
||||
if (!matchOrInsertSemicolon())
|
||||
return false;
|
||||
if (allowExpressionClosures()) {
|
||||
// Only expression closure can be Statement kind.
|
||||
// If we remove expression closure, we can remove isExprBody flag from
|
||||
// LazyScript and JSScript.
|
||||
if (kind == Statement && funbox->isExprBody()) {
|
||||
if (!matchOrInsertSemicolon())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Append possible Annex B function box only upon successfully parsing.
|
||||
if (tryAnnexB && !pc->innermostScope()->addPossibleAnnexBFunctionBox(pc, funbox))
|
||||
|
@ -3778,14 +3778,14 @@ GeneralParser<ParseHandler, CharT>::functionFormalParametersAndBody(InHandling i
|
|||
return false;
|
||||
}
|
||||
|
||||
#if JS_HAS_EXPR_CLOSURES
|
||||
this->addTelemetry(DeprecatedLanguageExtension::ExpressionClosure);
|
||||
if (!warnOnceAboutExprClosure())
|
||||
if (allowExpressionClosures()) {
|
||||
this->addTelemetry(DeprecatedLanguageExtension::ExpressionClosure);
|
||||
if (!warnOnceAboutExprClosure())
|
||||
return false;
|
||||
} else {
|
||||
error(JSMSG_CURLY_BEFORE_BODY);
|
||||
return false;
|
||||
#else
|
||||
error(JSMSG_CURLY_BEFORE_BODY);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
anyChars.ungetToken();
|
||||
|
@ -3847,9 +3847,8 @@ GeneralParser<ParseHandler, CharT>::functionFormalParametersAndBody(InHandling i
|
|||
JSMSG_CURLY_OPENED, openedPos));
|
||||
funbox->setEnd(anyChars);
|
||||
} else {
|
||||
#if !JS_HAS_EXPR_CLOSURES
|
||||
MOZ_ASSERT(kind == Arrow);
|
||||
#endif
|
||||
MOZ_ASSERT_IF(!allowExpressionClosures(), kind == Arrow);
|
||||
|
||||
if (anyChars.hadError())
|
||||
return false;
|
||||
funbox->setEnd(anyChars);
|
||||
|
|
|
@ -340,7 +340,9 @@ class ParserBase
|
|||
|
||||
bool hasValidSimpleStrictParameterNames();
|
||||
|
||||
|
||||
bool allowExpressionClosures() const {
|
||||
return options().expressionClosuresOption;
|
||||
}
|
||||
/*
|
||||
* Create a new function object given a name (which is optional if this is
|
||||
* a function expression).
|
||||
|
@ -703,6 +705,7 @@ class GeneralParser
|
|||
using Base::isValidSimpleAssignmentTarget;
|
||||
using Base::pc;
|
||||
using Base::usedNames;
|
||||
using Base::allowExpressionClosures;
|
||||
|
||||
private:
|
||||
using Base::checkAndMarkSuperScope;
|
||||
|
@ -1403,6 +1406,7 @@ class Parser<FullParseHandler, CharT> final
|
|||
using Base::pos;
|
||||
using Base::ss;
|
||||
using Base::tokenStream;
|
||||
using Base::allowExpressionClosures;
|
||||
|
||||
private:
|
||||
using Base::alloc;
|
||||
|
|
|
@ -3991,6 +3991,7 @@ JS::TransitiveCompileOptions::copyPODTransitiveOptions(const TransitiveCompileOp
|
|||
canLazilyParse = rhs.canLazilyParse;
|
||||
strictOption = rhs.strictOption;
|
||||
extraWarningsOption = rhs.extraWarningsOption;
|
||||
expressionClosuresOption = rhs.expressionClosuresOption;
|
||||
werrorOption = rhs.werrorOption;
|
||||
asmJSOption = rhs.asmJSOption;
|
||||
throwOnAsmJSValidationFailureOption = rhs.throwOnAsmJSValidationFailureOption;
|
||||
|
@ -4112,6 +4113,7 @@ JS::CompileOptions::CompileOptions(JSContext* cx)
|
|||
{
|
||||
strictOption = cx->options().strictMode();
|
||||
extraWarningsOption = cx->compartment()->behaviors().extraWarnings(cx);
|
||||
expressionClosuresOption = cx->options().expressionClosures();
|
||||
isProbablySystemOrAddonCode = cx->compartment()->isProbablySystemOrAddonCode();
|
||||
werrorOption = cx->options().werror();
|
||||
if (!cx->options().asmJS())
|
||||
|
|
|
@ -1117,6 +1117,7 @@ class JS_PUBLIC_API(ContextOptions) {
|
|||
#ifdef FUZZING
|
||||
, fuzzing_(false)
|
||||
#endif
|
||||
, expressionClosures_(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1272,6 +1273,12 @@ class JS_PUBLIC_API(ContextOptions) {
|
|||
}
|
||||
#endif
|
||||
|
||||
bool expressionClosures() const { return expressionClosures_; }
|
||||
ContextOptions& setExpressionClosures(bool flag) {
|
||||
expressionClosures_ = flag;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void disableOptionsForSafeMode() {
|
||||
setBaseline(false);
|
||||
setIon(false);
|
||||
|
@ -1302,6 +1309,7 @@ class JS_PUBLIC_API(ContextOptions) {
|
|||
#ifdef FUZZING
|
||||
bool fuzzing_ : 1;
|
||||
#endif
|
||||
bool expressionClosures_ : 1;
|
||||
|
||||
};
|
||||
|
||||
|
@ -3668,6 +3676,7 @@ class JS_FRIEND_API(TransitiveCompileOptions)
|
|||
canLazilyParse(true),
|
||||
strictOption(false),
|
||||
extraWarningsOption(false),
|
||||
expressionClosuresOption(false),
|
||||
werrorOption(false),
|
||||
asmJSOption(AsmJSOption::Disabled),
|
||||
throwOnAsmJSValidationFailureOption(false),
|
||||
|
@ -3702,6 +3711,7 @@ class JS_FRIEND_API(TransitiveCompileOptions)
|
|||
bool canLazilyParse;
|
||||
bool strictOption;
|
||||
bool extraWarningsOption;
|
||||
bool expressionClosuresOption;
|
||||
bool werrorOption;
|
||||
AsmJSOption asmJSOption;
|
||||
bool throwOnAsmJSValidationFailureOption;
|
||||
|
|
|
@ -14,10 +14,6 @@
|
|||
#define JS_HAS_TOSOURCE 1 /* has Object/Array toSource method */
|
||||
#define JS_HAS_UNEVAL 1 /* has uneval() top-level function */
|
||||
|
||||
#ifndef NIGHTLY_BUILD
|
||||
#define JS_HAS_EXPR_CLOSURES 1 /* has function (formals) listexpr */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Feature for Object.prototype.__{define,lookup}{G,S}etter__ legacy support;
|
||||
* support likely to be made opt-in at some future time.
|
||||
|
|
Загрузка…
Ссылка в новой задаче