Bug 1231758 - Fix bogus assertion in BCE for Annex B function assignment. (r=jorendorff)

This commit is contained in:
Shu-yu Guo 2015-12-10 12:48:46 -08:00
parent 95fc663831
commit 3a62ab69d0
2 changed files with 25 additions and 6 deletions

View File

@ -4389,13 +4389,25 @@ BytecodeEmitter::emitVariables(ParseNode* pn, VarEmitOption emitOption)
* i' to be hoisted out of the loop.
*/
MOZ_ASSERT(binding->isOp(JSOP_NOP));
MOZ_ASSERT(emitOption != DefineVars && emitOption != AnnexB);
MOZ_ASSERT(emitOption != DefineVars);
MOZ_ASSERT_IF(emitOption == AnnexB, binding->pn_left->isKind(PNK_NAME));
/*
* To allow the front end to rewrite var f = x; as f = x; when a
* function f(){} precedes the var, detect simple name assignment
* here and initialize the name.
*/
// To allow the front end to rewrite |var f = x;| as |f = x;| when a
// |function f(){}| precedes the var, detect simple name assignment
// here and initialize the name.
//
// There is a corner case where a function declaration synthesizes
// an Annex B declaration, which in turn gets rewritten later as a
// simple assignment due to hoisted function declaration of the
// same name. For example,
//
// {
// // Synthesizes an Annex B declaration because no 'f' binding
// // yet exists. This later gets rewritten as an assignment when
// // the outer function 'f' gets hoisted.
// function f() {}
// }
// function f() {}
if (binding->pn_left->isKind(PNK_NAME)) {
if (!emitSingleVariable(pn, binding->pn_left, binding->pn_right, emitOption))
return false;

View File

@ -0,0 +1,7 @@
{
function f() { return "inner"; }
}
function f() { return "outer"; }
reportCompare(f(), "inner");