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

git-svn-id: svn://10.0.0.236/trunk@230096 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
igor%mir2.org 2007-07-17 06:41:20 +00:00
parent 36391ed96f
commit 1b3cd5ca5b

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: