Bug 620838: propagate aliases-globals flag to inner lexical scopes, r=jwalden

This commit is contained in:
David Mandelin 2010-12-28 10:41:22 -08:00
parent 5b174f775e
commit 7325cf5f95
3 changed files with 26 additions and 5 deletions

View File

@ -0,0 +1,22 @@
function g() {
return "global";
}
function q(fun) {
return fun();
}
function f(x) {
if (x) {
function g() {
return "local";
}
var ans = q(function() {
return g();
});
}
g = null;
return ans;
}
assertEq(f(true), "local");

View File

@ -4626,7 +4626,8 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
if (!cg2->init())
return JS_FALSE;
cg2->flags = pn->pn_funbox->tcflags | TCF_COMPILING | TCF_IN_FUNCTION;
cg2->flags = pn->pn_funbox->tcflags | TCF_COMPILING | TCF_IN_FUNCTION |
(cg->flags & TCF_FUN_MIGHT_ALIAS_LOCALS);
#if JS_HAS_SHARP_VARS
if (cg2->flags & TCF_HAS_SHARPS) {
cg2->sharpSlotBase = fun->sharpSlotBase(cx);

View File

@ -252,10 +252,8 @@ struct JSStmtInfo {
#define TCF_COMPILE_FOR_EVAL 0x2000000
/*
* The function has broken or incorrect def-use information, and it cannot
* safely optimize free variables to global names. This can happen because
* of a named function statement not at the top level (emitting a DEFFUN),
* or a variable declaration inside a "with".
* The function or a function that encloses it may define new local names
* at runtime through means other than calling eval.
*/
#define TCF_FUN_MIGHT_ALIAS_LOCALS 0x4000000