From 316e54c9dc18e2406f156160d90b98f74cf976bb Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Fri, 13 Jul 2007 21:23:39 +0000 Subject: [PATCH] Bug 387909: make sure that [generator] is the first bytecode. r=brendan --- js/src/jsemit.c | 6 +++++- js/src/jsobj.c | 19 ++++++++++++------- js/src/jsxdrapi.h | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/js/src/jsemit.c b/js/src/jsemit.c index 72cfdd32018..0f35436f1df 100644 --- a/js/src/jsemit.c +++ b/js/src/jsemit.c @@ -3187,8 +3187,12 @@ JSBool js_EmitFunctionBytecode(JSContext *cx, JSCodeGenerator *cg, JSParseNode *body) { if (cg->treeContext.flags & TCF_FUN_IS_GENERATOR) { + /* JSOP_GENERATOR must be the first instruction. */ + CG_SWITCH_TO_PROLOG(cg); + JS_ASSERT(CG_NEXT(cg) == CG_BASE(cg)); if (js_Emit1(cx, cg, JSOP_GENERATOR) < 0) return JS_FALSE; + CG_SWITCH_TO_MAIN(cg); } return js_EmitTree(cx, cg, body) && @@ -6782,7 +6786,7 @@ js_FinishTakingSrcNotes(JSContext *cx, JSCodeGenerator *cg, jssrcnote *notes) */ offset = CG_PROLOG_OFFSET(cg) - cg->prolog.lastNoteOffset; JS_ASSERT(offset >= 0); - if (offset > 0) { + if (offset > 0 && cg->main.noteCount != 0) { /* NB: Use as much of the first main note's delta as we can. */ sn = cg->main.notes; delta = SN_IS_XDELTA(sn) diff --git a/js/src/jsobj.c b/js/src/jsobj.c index 6324a21ae20..71767cda593 100644 --- a/js/src/jsobj.c +++ b/js/src/jsobj.c @@ -863,7 +863,7 @@ js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, } *rval = STRING_TO_JSVAL(idstr); /* local root */ idIsLexicalIdentifier = js_IsIdentifier(idstr); - needOldStyleGetterSetter = + needOldStyleGetterSetter = !idIsLexicalIdentifier || js_CheckKeyword(JSSTRING_CHARS(idstr), JSSTRING_LENGTH(idstr)) != TOK_EOF; @@ -1287,7 +1287,7 @@ obj_eval(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) JS_ASSERT(!caller || caller->pc); indirectCall = (caller && *caller->pc != JSOP_EVAL); - /* + /* * Ban all indirect uses of eval (global.foo = eval; global.foo(...)) and * calls that attempt to use a non-global object as the "with" object in * the former indirect case. @@ -1970,17 +1970,22 @@ js_CloneBlockObject(JSContext *cx, JSObject *proto, JSObject *parent, JSBool js_PutBlockObject(JSContext *cx, JSObject *obj) { + JSStackFrame *fp; + uintN depth, slot; JSScopeProperty *sprop; - jsval v; + fp = (JSStackFrame *) JS_GetPrivate(cx, obj); + JS_ASSERT(fp); + depth = OBJ_BLOCK_DEPTH(cx, obj); for (sprop = OBJ_SCOPE(obj)->lastProp; sprop; sprop = sprop->parent) { if (sprop->getter != js_BlockClass.getProperty) continue; if (!(sprop->flags & SPROP_HAS_SHORTID)) continue; - if (!sprop->getter(cx, obj, INT_TO_JSVAL(sprop->shortid), &v) || - !js_DefineNativeProperty(cx, obj, sprop->id, - v, NULL, NULL, + slot = depth + (uintN)sprop->shortid; + JS_ASSERT(slot < fp->script->depth); + if (!js_DefineNativeProperty(cx, obj, sprop->id, + fp->spbase[slot], NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT, SPROP_HAS_SHORTID, sprop->shortid, NULL)) { @@ -2806,7 +2811,7 @@ js_AllocSlot(JSContext *cx, JSObject *obj, uint32 *slotp) return JS_FALSE; } - /* ReallocSlots or js_FreeSlot should set the free slots to void. */ + /* ReallocSlots or js_FreeSlot should set the free slots to void. */ JS_ASSERT(STOBJ_GET_SLOT(obj, map->freeslot) == JSVAL_VOID); *slotp = map->freeslot++; return JS_TRUE; diff --git a/js/src/jsxdrapi.h b/js/src/jsxdrapi.h index cf0e6c5e0bf..8e589964ccb 100644 --- a/js/src/jsxdrapi.h +++ b/js/src/jsxdrapi.h @@ -201,7 +201,7 @@ JS_XDRFindClassById(JSXDRState *xdr, uint32 id); * before deserialization of bytecode. If the saved version does not match * the current version, abort deserialization and invalidate the file. */ -#define JSXDR_BYTECODE_VERSION (0xb973c0de - 14) +#define JSXDR_BYTECODE_VERSION (0xb973c0de - 15) /* * Library-private functions.