diff --git a/js/src/jsemit.c b/js/src/jsemit.c index fb5815fd63e..9cb39561ce2 100644 --- a/js/src/jsemit.c +++ b/js/src/jsemit.c @@ -3078,6 +3078,21 @@ bad: goto out; } +JSBool +js_EmitFunctionBytecode(JSContext *cx, JSCodeGenerator *cg, JSParseNode *body) +{ + if (!js_AllocTryNotes(cx, cg)) + return JS_FALSE; + + if (cg->treeContext.flags & TCF_FUN_IS_GENERATOR) { + if (js_Emit1(cx, cg, JSOP_GENERATOR) < 0) + return JS_FALSE; + } + + return js_EmitTree(cx, cg, body) && + js_Emit1(cx, cg, JSOP_STOP) >= 0; +} + JSBool js_EmitFunctionBody(JSContext *cx, JSCodeGenerator *cg, JSParseNode *body, JSFunction *fun) @@ -3086,9 +3101,6 @@ js_EmitFunctionBody(JSContext *cx, JSCodeGenerator *cg, JSParseNode *body, JSObject *funobj; JSBool ok; - if (!js_AllocTryNotes(cx, cg)) - return JS_FALSE; - fp = cx->fp; funobj = fun->object; JS_ASSERT(!fp || (fp->fun != fun && fp->varobj != funobj && @@ -3101,10 +3113,7 @@ js_EmitFunctionBody(JSContext *cx, JSCodeGenerator *cg, JSParseNode *body, ? JSFRAME_COMPILING | JSFRAME_COMPILE_N_GO : JSFRAME_COMPILING; cx->fp = &frame; - ok = (!(cg->treeContext.flags & TCF_FUN_IS_GENERATOR) || - js_Emit1(cx, cg, JSOP_GENERATOR) >= 0) && - js_EmitTree(cx, cg, body) && - js_Emit1(cx, cg, JSOP_STOP) >= 0; + ok = js_EmitFunctionBytecode(cx, cg, body); cx->fp = fp; if (!ok) return JS_FALSE; diff --git a/js/src/jsemit.h b/js/src/jsemit.h index 585784b3625..90709c22ae9 100644 --- a/js/src/jsemit.h +++ b/js/src/jsemit.h @@ -478,6 +478,12 @@ js_LexicalLookup(JSTreeContext *tc, JSAtom *atom, jsint *slotp, extern JSBool js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn); +/* + * Emit function code into cg for the tree rooted at body. + */ +extern JSBool +js_EmitFunctionBytecode(JSContext *cx, JSCodeGenerator *cg, JSParseNode *body); + /* * Emit code into cg for the tree rooted at body, then create a persistent * script for fun from cg. diff --git a/js/src/jsparse.c b/js/src/jsparse.c index 46eca539a29..8a69887bb40 100644 --- a/js/src/jsparse.c +++ b/js/src/jsparse.c @@ -756,9 +756,7 @@ FunctionBody(JSContext *cx, JSTokenStream *ts, JSFunction *fun, JSCodeGenerator *cg = (JSCodeGenerator *) tc; if (!js_FoldConstants(cx, pn, tc) || - !js_AllocTryNotes(cx, cg) || - !js_EmitTree(cx, cg, pn) || - js_Emit1(cx, cg, JSOP_STOP) < 0) { + !js_EmitFunctionBytecode(cx, cg, pn)) { pn = NULL; } }