Bug 387871: proper state checks when closing the generator. r=brendan

This commit is contained in:
igor@mir2.org 2007-07-16 23:41:20 -07:00
parent 64b66b6dc6
commit b2ae154e62

View File

@ -829,6 +829,13 @@ SendToGenerator(JSContext *cx, JSGeneratorOp op, JSObject *obj,
JSArena *arena;
JSBool ok;
if (gen->state == JSGEN_RUNNING || gen->state == JSGEN_CLOSING) {
js_ReportValueError(cx, JSMSG_NESTING_GENERATOR,
JSDVG_SEARCH_STACK, OBJECT_TO_JSVAL(obj),
JS_GetFunctionId(gen->frame.fun));
return JS_FALSE;
}
JS_ASSERT(gen->state == JSGEN_NEWBORN || gen->state == JSGEN_OPEN);
switch (op) {
case JSGENOP_NEXT:
@ -917,7 +924,6 @@ CloseGenerator(JSContext *cx, JSObject *obj)
return JS_TRUE;
}
JS_ASSERT(gen->state != JSGEN_RUNNING && gen->state != JSGEN_CLOSING);
if (gen->state == JSGEN_CLOSED)
return JS_TRUE;
@ -944,8 +950,7 @@ generator_op(JSContext *cx, JSGeneratorOp op,
goto closed_generator;
}
switch (gen->state) {
case JSGEN_NEWBORN:
if (gen->state == JSGEN_NEWBORN) {
switch (op) {
case JSGENOP_NEXT:
case JSGENOP_THROW:
@ -964,21 +969,7 @@ generator_op(JSContext *cx, JSGeneratorOp op,
gen->state = JSGEN_CLOSED;
return JS_TRUE;
}
break;
case JSGEN_OPEN:
break;
case JSGEN_RUNNING:
case JSGEN_CLOSING:
js_ReportValueError(cx, JSMSG_NESTING_GENERATOR,
JSDVG_SEARCH_STACK, argv[-1],
JS_GetFunctionId(gen->frame.fun));
return JS_FALSE;
default:
JS_ASSERT(gen->state == JSGEN_CLOSED);
} else if (gen->state == JSGEN_CLOSED) {
closed_generator:
switch (op) {
case JSGENOP_NEXT: