Bug 1357506 - Remove assert that constructorBox can only be set once when parsing classes. (r=Yoric)

Both asm.js and syntax parsing can abort and rewind parsing of an inner
function. The bookkeeping to make sure that a class's constructor
FunctionBox is only set once is not worth it -- duplicate constructor
definitions already throw an early error.
This commit is contained in:
Shu-yu Guo 2017-04-20 15:22:17 -07:00
Родитель a606cd8b60
Коммит d888297d71
4 изменённых файлов: 14 добавлений и 33 удалений

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

@ -548,7 +548,7 @@ FunctionBox::initWithEnclosingParseContext(ParseContext* enclosing, FunctionSynt
if (kind == ClassConstructor || kind == DerivedClassConstructor) { if (kind == ClassConstructor || kind == DerivedClassConstructor) {
auto stmt = enclosing->findInnermostStatement<ParseContext::ClassStatement>(); auto stmt = enclosing->findInnermostStatement<ParseContext::ClassStatement>();
MOZ_ASSERT(stmt); MOZ_ASSERT(stmt);
stmt->setConstructorBox(this); stmt->constructorBox = this;
if (kind == DerivedClassConstructor) { if (kind == DerivedClassConstructor) {
setDerivedClassConstructor(); setDerivedClassConstructor();
@ -574,16 +574,6 @@ FunctionBox::initWithEnclosingParseContext(ParseContext* enclosing, FunctionSynt
} }
} }
void
FunctionBox::resetForAbortedSyntaxParse(ParseContext* enclosing, FunctionSyntaxKind kind)
{
if (kind == ClassConstructor || kind == DerivedClassConstructor) {
auto stmt = enclosing->findInnermostStatement<ParseContext::ClassStatement>();
MOZ_ASSERT(stmt);
stmt->clearConstructorBoxForAbortedSyntaxParse(this);
}
}
void void
FunctionBox::initWithEnclosingScope(Scope* enclosingScope) FunctionBox::initWithEnclosingScope(Scope* enclosingScope)
{ {
@ -3455,7 +3445,6 @@ Parser<FullParseHandler>::trySyntaxParseInnerFunction(ParseNode* pn, HandleFunct
// correctness. // correctness.
parser->clearAbortedSyntaxParse(); parser->clearAbortedSyntaxParse();
usedNames.rewind(token); usedNames.rewind(token);
funbox->resetForAbortedSyntaxParse(pc, kind);
MOZ_ASSERT_IF(!parser->context->helperThread(), MOZ_ASSERT_IF(!parser->context->helperThread(),
!parser->context->isExceptionPending()); !parser->context->isExceptionPending());
break; break;
@ -7168,7 +7157,7 @@ Parser<ParseHandler>::classDefinition(YieldHandling yieldHandling,
errorAt(nameOffset, JSMSG_BAD_METHOD_DEF); errorAt(nameOffset, JSMSG_BAD_METHOD_DEF);
return null(); return null();
} }
if (classStmt.constructorBox()) { if (classStmt.constructorBox) {
errorAt(nameOffset, JSMSG_DUPLICATE_PROPERTY, "constructor"); errorAt(nameOffset, JSMSG_DUPLICATE_PROPERTY, "constructor");
return null(); return null();
} }
@ -7215,7 +7204,7 @@ Parser<ParseHandler>::classDefinition(YieldHandling yieldHandling,
// Amend the toStringEnd offset for the constructor now that we've // Amend the toStringEnd offset for the constructor now that we've
// finished parsing the class. // finished parsing the class.
uint32_t classEndOffset = pos().end; uint32_t classEndOffset = pos().end;
if (FunctionBox* ctorbox = classStmt.constructorBox()) { if (FunctionBox* ctorbox = classStmt.constructorBox) {
if (ctorbox->function()->isInterpretedLazy()) if (ctorbox->function()->isInterpretedLazy())
ctorbox->function()->lazyScript()->setToStringEnd(classEndOffset); ctorbox->function()->lazyScript()->setToStringEnd(classEndOffset);
ctorbox->toStringEnd = classEndOffset; ctorbox->toStringEnd = classEndOffset;

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

@ -87,29 +87,14 @@ class ParseContext : public Nestable<ParseContext>
} }
}; };
class ClassStatement : public Statement struct ClassStatement : public Statement
{ {
FunctionBox* constructorBox_; FunctionBox* constructorBox;
public:
explicit ClassStatement(ParseContext* pc) explicit ClassStatement(ParseContext* pc)
: Statement(pc, StatementKind::Class), : Statement(pc, StatementKind::Class),
constructorBox_(nullptr) constructorBox(nullptr)
{ } { }
void clearConstructorBoxForAbortedSyntaxParse(FunctionBox* funbox) {
MOZ_ASSERT(constructorBox_ == funbox);
constructorBox_ = nullptr;
}
void setConstructorBox(FunctionBox* funbox) {
MOZ_ASSERT(!constructorBox_);
constructorBox_ = funbox;
}
FunctionBox* constructorBox() const {
return constructorBox_;
}
}; };
// The intra-function scope stack. // The intra-function scope stack.

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

@ -503,7 +503,6 @@ class FunctionBox : public ObjectBox, public SharedContext
void initFromLazyFunction(); void initFromLazyFunction();
void initStandaloneFunction(Scope* enclosingScope); void initStandaloneFunction(Scope* enclosingScope);
void initWithEnclosingParseContext(ParseContext* enclosing, FunctionSyntaxKind kind); void initWithEnclosingParseContext(ParseContext* enclosing, FunctionSyntaxKind kind);
void resetForAbortedSyntaxParse(ParseContext* enclosing, FunctionSyntaxKind kind);
ObjectBox* toObjectBox() override { return this; } ObjectBox* toObjectBox() override { return this; }
JSFunction* function() const { return &object->as<JSFunction>(); } JSFunction* function() const { return &object->as<JSFunction>(); }

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

@ -0,0 +1,8 @@
// Test that constructors that abort due to asm.js do not assert due to the
// parser keeping track of the FunctionBox corresponding to the constructor.
class a {
constructor() {
"use asm";
}
}