From b2ae154e62d672c23ff83edf45e8983296b0591f Mon Sep 17 00:00:00 2001 From: "igor@mir2.org" Date: Mon, 16 Jul 2007 23:41:20 -0700 Subject: [PATCH] Bug 387871: proper state checks when closing the generator. r=brendan --- js/src/jsiter.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/js/src/jsiter.c b/js/src/jsiter.c index 987e9cab4650..9d09ad48487d 100644 --- a/js/src/jsiter.c +++ b/js/src/jsiter.c @@ -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: