Bug 1320403 - Move JSFunction::EXPR_BODY to JSScript, LazyScript, and FunctionBox. r=jandem

This commit is contained in:
Tooru Fujisawa 2016-11-29 09:08:43 +09:00
Родитель 2ed4747eb8
Коммит 1b94319fed
9 изменённых файлов: 55 добавлений и 26 удалений

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

@ -3407,12 +3407,7 @@ ASTSerializer::function(ParseNode* pn, ASTType type, MutableHandleValue dst)
: GeneratorStyle::None;
bool isAsync = pn->pn_funbox->isAsync();
bool isExpression =
#if JS_HAS_EXPR_CLOSURES
func->isExprBody();
#else
false;
#endif
bool isExpression = pn->pn_funbox->isExprBody();
RootedValue id(cx);
RootedAtom funcAtom(cx, func->name());

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

@ -466,6 +466,7 @@ FunctionBox::FunctionBox(ExclusiveContext* cx, LifoAlloc& alloc, ObjectBox* trac
usesThis(false),
usesReturn(false),
hasRest_(false),
isExprBody_(false),
funCxFlags()
{
// Functions created at parse time may be set singleton after parsing and
@ -2248,6 +2249,8 @@ Parser<SyntaxParseHandler>::finishFunction(bool isStandaloneFunction /* = false
lazy->setAsyncKind(funbox->asyncKind());
if (funbox->hasRest())
lazy->setHasRest();
if (funbox->isExprBody())
lazy->setIsExprBody();
if (funbox->isLikelyConstructorWrapper())
lazy->setLikelyConstructorWrapper();
if (funbox->isDerivedClassConstructor())
@ -2989,6 +2992,8 @@ Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, FunctionSyntaxKin
LazyScript* lazy = fun->lazyScript();
if (lazy->needsHomeObject())
funbox->setNeedsHomeObject();
if (lazy->isExprBody())
funbox->setIsExprBody();
PropagateTransitiveParseFlags(lazy, pc->sc());
@ -3001,10 +3006,15 @@ Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, FunctionSyntaxKin
if (!tokenStream.advance(fun->lazyScript()->end() - userbufBase))
return false;
if (kind == Statement && fun->isExprBody()) {
#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 (!matchOrInsertSemicolonAfterExpression())
return false;
}
#endif
return true;
}
@ -3444,9 +3454,7 @@ Parser<ParseHandler>::functionFormalParametersAndBody(InHandling inHandling,
tokenStream.ungetToken();
bodyType = ExpressionBody;
#if JS_HAS_EXPR_CLOSURES
fun->setIsExprBody();
#endif
funbox->setIsExprBody();
}
// Arrow function parameters inherit yieldHandling from the enclosing
@ -6083,7 +6091,7 @@ Parser<ParseHandler>::yieldExpression(InHandling inHandling)
if (pc->funHasReturnExpr
#if JS_HAS_EXPR_CLOSURES
|| pc->functionBox()->function()->isExprBody()
|| pc->functionBox()->isExprBody()
#endif
)
{

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

@ -472,6 +472,9 @@ class FunctionBox : public ObjectBox, public SharedContext
bool usesThis:1; /* contains 'this' */
bool usesReturn:1; /* contains a 'return' statement */
bool hasRest_:1; /* has rest parameter */
bool isExprBody_:1; /* arrow function with expression
* body or expression closure:
* function(x) x*x */
FunctionContextFlags funCxFlags;
@ -545,6 +548,11 @@ class FunctionBox : public ObjectBox, public SharedContext
hasRest_ = true;
}
bool isExprBody() const { return isExprBody_; }
void setIsExprBody() {
isExprBody_ = true;
}
void setGeneratorKind(GeneratorKind kind) {
// A generator kind can be set at initialization, or when "yield" is
// first seen. In both cases the transition can only happen from

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

@ -1020,8 +1020,6 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint)
return nullptr;
}
} else {
MOZ_ASSERT(!fun->isExprBody());
bool derived = fun->infallibleIsDefaultClassConstructor(cx);
if (derived && fun->isDerivedClassConstructor()) {
if (!out.append("(...args) {\n ") ||

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

@ -52,8 +52,6 @@ class JSFunction : public js::NativeObject
CONSTRUCTOR = 0x0002, /* function that can be called as a constructor */
EXTENDED = 0x0004, /* structure is FunctionExtended */
BOUND_FUN = 0x0008, /* function was created with Function.prototype.bind. */
EXPR_BODY = 0x0010, /* arrow function with expression body or
* expression closure: function(x) x*x */
HAS_GUESSED_ATOM = 0x0020, /* function had no explicit name, but a
name was guessed for it anyway */
LAMBDA = 0x0040, /* function comes from a FunctionExpression, ArrowFunction, or
@ -93,7 +91,7 @@ class JSFunction : public js::NativeObject
INTERPRETED_GENERATOR = INTERPRETED,
NO_XDR_FLAGS = RESOLVED_LENGTH | RESOLVED_NAME,
STABLE_ACROSS_CLONES = CONSTRUCTOR | EXPR_BODY | HAS_GUESSED_ATOM | LAMBDA |
STABLE_ACROSS_CLONES = CONSTRUCTOR | HAS_GUESSED_ATOM | LAMBDA |
SELF_HOSTED | FUNCTION_KIND_MASK
};
@ -178,7 +176,6 @@ class JSFunction : public js::NativeObject
bool isAsmJSNative() const { return kind() == AsmJS; }
/* Possible attributes of an interpreted function: */
bool isExprBody() const { return flags() & EXPR_BODY; }
bool hasGuessedAtom() const { return flags() & HAS_GUESSED_ATOM; }
bool isLambda() const { return flags() & LAMBDA; }
bool isBoundFunction() const { return flags() & BOUND_FUN; }
@ -280,11 +277,6 @@ class JSFunction : public js::NativeObject
flags_ |= SELF_HOSTED;
}
// Can be called multiple times by the parser.
void setIsExprBody() {
flags_ |= EXPR_BODY;
}
void setArrow() {
setKind(Arrow);
}

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

@ -318,6 +318,7 @@ js::XDRScript(XDRState<mode>* xdr, HandleScope scriptEnclosingScope, HandleScrip
IsStarGenerator,
IsAsync,
HasRest,
IsExprBody,
OwnSource,
ExplicitUseStrict,
SelfHosted,
@ -435,6 +436,8 @@ js::XDRScript(XDRState<mode>* xdr, HandleScope scriptEnclosingScope, HandleScrip
scriptBits |= (1 << IsAsync);
if (script->hasRest())
scriptBits |= (1 << HasRest);
if (script->isExprBody())
scriptBits |= (1 << IsExprBody);
if (script->hasSingletons())
scriptBits |= (1 << HasSingleton);
if (script->treatAsRunOnce())
@ -588,6 +591,8 @@ js::XDRScript(XDRState<mode>* xdr, HandleScope scriptEnclosingScope, HandleScrip
script->setAsyncKind(AsyncFunction);
if (scriptBits & (1 << HasRest))
script->setHasRest();
if (scriptBits & (1 << IsExprBody))
script->setIsExprBody();
}
JS_STATIC_ASSERT(sizeof(jsbytecode) == 1);
@ -2630,6 +2635,8 @@ JSScript::initFromFunctionBox(ExclusiveContext* cx, HandleScript script,
script->setAsyncKind(funbox->asyncKind());
if (funbox->hasRest())
script->setHasRest();
if (funbox->isExprBody())
script->setIsExprBody();
PositionalFormalParameterIter fi(script);
while (fi && !fi.closedOver())
@ -3291,6 +3298,7 @@ js::detail::CopyScript(JSContext* cx, HandleScript src, HandleScript dst,
dst->isDefaultClassConstructor_ = src->isDefaultClassConstructor();
dst->isAsync_ = src->asyncKind() == AsyncFunction;
dst->hasRest_ = src->hasRest_;
dst->isExprBody_ = src->isExprBody_;
if (nconsts != 0) {
GCPtrValue* vector = Rebase<GCPtrValue>(dst, src, src->consts()->vector);
@ -4025,6 +4033,7 @@ LazyScript::Create(ExclusiveContext* cx, HandleFunction fun,
p.hasThisBinding = false;
p.isAsync = false;
p.hasRest = false;
p.isExprBody = false;
p.numClosedOverBindings = closedOverBindings.length();
p.numInnerFunctions = innerFunctions.length();
p.generatorKindBits = GeneratorKindAsBits(NotGenerator);

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

@ -1013,6 +1013,7 @@ class JSScript : public js::gc::TenuredCell
bool isAsync_:1;
bool hasRest_:1;
bool isExprBody_:1;
// Add padding so JSScript is gc::Cell aligned. Make padding protected
// instead of private to suppress -Wunused-private-field compiler warnings.
@ -1317,6 +1318,13 @@ class JSScript : public js::gc::TenuredCell
hasRest_ = true;
}
bool isExprBody() const {
return isExprBody_;
}
void setIsExprBody() {
isExprBody_ = true;
}
void setNeedsHomeObject() {
needsHomeObject_ = true;
}
@ -1922,7 +1930,7 @@ class LazyScript : public gc::TenuredCell
#endif
private:
static const uint32_t NumClosedOverBindingsBits = 21;
static const uint32_t NumClosedOverBindingsBits = 20;
static const uint32_t NumInnerFunctionsBits = 20;
struct PackedView {
@ -1932,7 +1940,12 @@ class LazyScript : public gc::TenuredCell
uint32_t shouldDeclareArguments : 1;
uint32_t hasThisBinding : 1;
uint32_t isAsync : 1;
uint32_t isExprBody : 1;
uint32_t numClosedOverBindings : NumClosedOverBindingsBits;
// -- 32bit boundary --
uint32_t numInnerFunctions : NumInnerFunctionsBits;
uint32_t generatorKindBits : 2;
@ -2085,6 +2098,13 @@ class LazyScript : public gc::TenuredCell
p_.hasRest = true;
}
bool isExprBody() const {
return p_.isExprBody;
}
void setIsExprBody() {
p_.isExprBody = true;
}
bool strict() const {
return p_.strict;
}

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

@ -2676,7 +2676,7 @@ DisassembleScript(JSContext* cx, HandleScript script, HandleFunction fun,
if (sp->put(" CONSTRUCTOR") < 0)
return false;
}
if (fun->isExprBody()) {
if (script->isExprBody()) {
if (sp->put(" EXPRESSION_CLOSURE") < 0)
return false;
}

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

@ -3250,10 +3250,9 @@ CheckModuleLevelName(ModuleValidator& m, ParseNode* usepn, PropertyName* name)
static bool
CheckFunctionHead(ModuleValidator& m, ParseNode* fn)
{
JSFunction* fun = FunctionObject(fn);
if (fn->pn_funbox->hasRest())
return m.fail(fn, "rest args not allowed");
if (fun->isExprBody())
if (fn->pn_funbox->isExprBody())
return m.fail(fn, "expression closures not allowed");
if (fn->pn_funbox->hasDestructuringArgs)
return m.fail(fn, "destructuring args not allowed");