From 1b3cd5ca5b6d00a5226dd7c3b90a2fe4b8386dcd Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Tue, 17 Jul 2007 06:41:20 +0000 Subject: [PATCH] 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 --- mozilla/js/src/jsiter.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/mozilla/js/src/jsiter.c b/mozilla/js/src/jsiter.c index 987e9cab465..9d09ad48487 100644 --- a/mozilla/js/src/jsiter.c +++ b/mozilla/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: