Bug 1243793 - Fix handling of labels when emitting hoisted function definitions. (r=jorendorff)

This commit is contained in:
Shu-yu Guo 2016-02-02 14:26:37 -08:00 committed by Cameron Kaiser
parent 8a51cc1f91
commit c0ffd70f92
2 changed files with 19 additions and 5 deletions

View File

@ -5377,15 +5377,17 @@ BytecodeEmitter::emitHoistedFunctionsInList(ParseNode* list)
MOZ_ASSERT(list->pn_xflags & PNX_FUNCDEFS);
for (ParseNode* pn = list->pn_head; pn; pn = pn->pn_next) {
ParseNode* maybeFun = pn;
if (!sc->strict()) {
while (pn->isKind(PNK_LABEL))
pn = pn->as<LabeledStatement>().statement();
while (maybeFun->isKind(PNK_LABEL))
maybeFun = maybeFun->as<LabeledStatement>().statement();
}
if (pn->isKind(PNK_ANNEXB_FUNCTION) ||
(pn->isKind(PNK_FUNCTION) && pn->functionIsHoisted()))
if (maybeFun->isKind(PNK_ANNEXB_FUNCTION) ||
(maybeFun->isKind(PNK_FUNCTION) && maybeFun->functionIsHoisted()))
{
if (!emitTree(pn))
if (!emitTree(maybeFun))
return false;
}
}

View File

@ -9,6 +9,18 @@
// Annex B still works.
assertEq(f(), 4);
// The same thing with labels.
{
assertEq(f(), 4);
function f() { return 3; }
assertEq(f(), 4);
l: function f() { return 4; }
assertEq(f(), 4);
}
// Annex B still works.
assertEq(f(), 4);
function test() {
{
assertEq(f(), 2);