Bug 801195 - Delay changing generator state (r=luke)

This commit is contained in:
Bill McCloskey
2012-11-19 11:44:16 -08:00
parent 2ccb54d60f
commit e0f8b4a6e8

View File

@@ -1526,6 +1526,7 @@ SendToGenerator(JSContext *cx, JSGeneratorOp op, HandleObject obj,
*/
GeneratorWriteBarrierPre(cx, gen);
JSGeneratorState futureState;
JS_ASSERT(gen->state == JSGEN_NEWBORN || gen->state == JSGEN_OPEN);
switch (op) {
case JSGENOP_NEXT:
@@ -1537,18 +1538,18 @@ SendToGenerator(JSContext *cx, JSGeneratorOp op, HandleObject obj,
*/
gen->regs.sp[-1] = arg;
}
gen->state = JSGEN_RUNNING;
futureState = JSGEN_RUNNING;
break;
case JSGENOP_THROW:
cx->setPendingException(arg);
gen->state = JSGEN_RUNNING;
futureState = JSGEN_RUNNING;
break;
default:
JS_ASSERT(op == JSGENOP_CLOSE);
cx->setPendingException(MagicValue(JS_GENERATOR_CLOSING));
gen->state = JSGEN_CLOSING;
futureState = JSGEN_CLOSING;
break;
}
@@ -1560,6 +1561,12 @@ SendToGenerator(JSContext *cx, JSGeneratorOp op, HandleObject obj,
return JS_FALSE;
}
/*
* Don't change the state until after the frame is successfully pushed
* or else we might fail to scan some generator values.
*/
gen->state = futureState;
StackFrame *fp = gfg.fp();
gen->regs = cx->regs();