From c0ffd70f920f8a7fd86d0ee8c8ce6f74cd45ee89 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Tue, 2 Feb 2016 14:26:37 -0800 Subject: [PATCH] Bug 1243793 - Fix handling of labels when emitting hoisted function definitions. (r=jorendorff) --- js/src/frontend/BytecodeEmitter.cpp | 12 +++++++----- .../block-scoped-functions-deprecated-redecl.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 201c25054..435b1b4cf 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -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().statement(); + while (maybeFun->isKind(PNK_LABEL)) + maybeFun = maybeFun->as().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; } } diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-deprecated-redecl.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-deprecated-redecl.js index 6f023b454..af32be5d3 100644 --- a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-deprecated-redecl.js +++ b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-deprecated-redecl.js @@ -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);