Skip to content

Commit

Permalink
hack: treat const in for(const x in y) as let.
Browse files Browse the repository at this point in the history
  • Loading branch information
roytam1 committed Feb 1, 2019
1 parent 7edbd8b commit f0dd403
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions js/src/frontend/BytecodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5496,7 +5496,7 @@ BytecodeEmitter::emitIterator()
bool
BytecodeEmitter::emitForInOrOfVariables(ParseNode* pn)
{
MOZ_ASSERT(pn->isKind(PNK_VAR) || pn->isKind(PNK_LET));
MOZ_ASSERT(pn->isKind(PNK_VAR) || pn->isKind(PNK_LET) || pn->isKind(PNK_CONST));

// ES6 specifies that loop variables get a fresh binding in each iteration.
// This is currently implemented for C-style for(;;) loops, but not
Expand All @@ -5518,7 +5518,7 @@ BytecodeEmitter::emitForInOrOfVariables(ParseNode* pn)
if (!emitVariables(pn, DefineVars))
return false;
} else {
MOZ_ASSERT(pn->isKind(PNK_LET));
MOZ_ASSERT(pn->isKind(PNK_LET) || pn->isKind(PNK_CONST));
if (!emitVariables(pn, InitializeVars))
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions js/src/frontend/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4583,10 +4583,10 @@ Parser<ParseHandler>::declarationPattern(Node decl, TokenKind tt, BindData<Parse
if (*forHeadKind != PNK_FORHEAD) {
// |for (const ... in ...);| and |for (const ... of ...);| are
// syntax errors for now. We'll fix this in bug 449811.
if (handler.declarationIsConst(decl)) {
/*if (handler.declarationIsConst(decl)) {
report(ParseError, false, pattern, JSMSG_BAD_CONST_DECL);
return null();
}
}*/

if (!checkDestructuringPattern(data, pattern))
return null();
Expand Down Expand Up @@ -4788,7 +4788,7 @@ Parser<ParseHandler>::declarationName(Node decl, TokenKind tt, BindData<ParseHan
if (isForIn || isForOf) {
// XXX Uncomment this when fixing bug 449811. Until then,
// |for (const ... in/of ...)| remains an error.
//constRequiringInitializer = false;
constRequiringInitializer = false;

*forHeadKind = isForIn ? PNK_FORIN : PNK_FOROF;
} else {
Expand Down

0 comments on commit f0dd403

Please sign in to comment.