Bug 631082: assume functions defined or seen in generators escape, r=brendan

This commit is contained in:
David Mandelin 2011-02-03 17:18:18 -08:00
Родитель a194c71901
Коммит 5315ba1b46
2 изменённых файлов: 21 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,13 @@
var t;
(function () {
t = (function() {
yield k();
})();
function h() {
}
function k() {
return function() { h(); };
}
})();
t.next();

Просмотреть файл

@ -2092,8 +2092,15 @@ FindFunArgs(JSFunctionBox *funbox, int level, JSFunctionBoxQueue *queue)
* TCF_FUN_HEAVYWEIGHT bottom up, funbox's ancestor function nodes have * TCF_FUN_HEAVYWEIGHT bottom up, funbox's ancestor function nodes have
* already been marked as funargs by this point. Therefore we have to * already been marked as funargs by this point. Therefore we have to
* flag only funbox->node and funbox->kids' nodes here. * flag only funbox->node and funbox->kids' nodes here.
*
* Generators need to be treated in the same way. Even if the value
* of a generator function doesn't escape, anything defined or referred
* to inside the generator can escape through a call to the generator.
* We could imagine doing static analysis to track the calls and see
* if any iterators or values returned by iterators escape, but that
* would be hard, so instead we just assume everything might escape.
*/ */
if (funbox->tcflags & TCF_FUN_HEAVYWEIGHT) { if (funbox->tcflags & (TCF_FUN_HEAVYWEIGHT | TCF_FUN_IS_GENERATOR)) {
fn->setFunArg(); fn->setFunArg();
for (JSFunctionBox *kid = funbox->kids; kid; kid = kid->siblings) for (JSFunctionBox *kid = funbox->kids; kid; kid = kid->siblings)
kid->node->setFunArg(); kid->node->setFunArg();