diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 367fea8ca5e0..155f8ed1805d 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -5138,8 +5138,9 @@ EmitFunc(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) return false; if (pn->pn_cookie.isFree()) { bce->switchToProlog(); - JSOp op = fun->isFlatClosure() ? JSOP_DEFFUN_FC : JSOP_DEFFUN; - if (!EmitFunctionOp(cx, op, index, bce)) + MOZ_ASSERT(!fun->isFlatClosure(), + "global functions can't have upvars, so they are never flat"); + if (!EmitFunctionOp(cx, JSOP_DEFFUN, index, bce)) return false; bce->switchToMain(); } diff --git a/js/src/frontend/SemanticAnalysis.cpp b/js/src/frontend/SemanticAnalysis.cpp index 09c6a0651307..afbba44a0cb4 100644 --- a/js/src/frontend/SemanticAnalysis.cpp +++ b/js/src/frontend/SemanticAnalysis.cpp @@ -570,15 +570,20 @@ SetFunctionKinds(FunctionBox *funbox, uint32_t *tcflags, bool isDirectEval) } } + /* + * Top-level functions, and (extension) functions not at top level + * which are also not directly within other functions, aren't + * flattened. + */ + if (fn->isOp(JSOP_DEFFUN)) + canFlatten = false; + if (!hasUpvars) { /* No lexical dependencies => null closure, for best performance. */ fun->setKind(JSFUN_NULL_CLOSURE); } else if (canFlatten) { fun->setKind(JSFUN_FLAT_CLOSURE); switch (fn->getOp()) { - case JSOP_DEFFUN: - fn->setOp(JSOP_DEFFUN_FC); - break; case JSOP_DEFLOCALFUN: fn->setOp(JSOP_DEFLOCALFUN_FC); break; diff --git a/js/src/jsinfer.cpp b/js/src/jsinfer.cpp index aefc1887bdc9..6c49497da9e1 100644 --- a/js/src/jsinfer.cpp +++ b/js/src/jsinfer.cpp @@ -3822,7 +3822,6 @@ ScriptAnalysis::analyzeTypesBytecode(JSContext *cx, unsigned offset, case JSOP_LAMBDA: case JSOP_LAMBDA_FC: case JSOP_DEFFUN: - case JSOP_DEFFUN_FC: case JSOP_DEFLOCALFUN: case JSOP_DEFLOCALFUN_FC: { unsigned off = (op == JSOP_DEFLOCALFUN || op == JSOP_DEFLOCALFUN_FC) ? SLOTNO_LEN : 0; diff --git a/js/src/jsinterp.cpp b/js/src/jsinterp.cpp index f87c8ddc075a..d2334ca7ee4f 100644 --- a/js/src/jsinterp.cpp +++ b/js/src/jsinterp.cpp @@ -1744,6 +1744,7 @@ ADD_EMPTY_CASE(JSOP_UNUSED13) ADD_EMPTY_CASE(JSOP_UNUSED14) ADD_EMPTY_CASE(JSOP_UNUSED15) ADD_EMPTY_CASE(JSOP_UNUSED16) +ADD_EMPTY_CASE(JSOP_UNUSED17) ADD_EMPTY_CASE(JSOP_CONDSWITCH) ADD_EMPTY_CASE(JSOP_TRY) #if JS_HAS_XML_SUPPORT @@ -3268,35 +3269,6 @@ BEGIN_CASE(JSOP_DEFFUN) } END_CASE(JSOP_DEFFUN) -BEGIN_CASE(JSOP_DEFFUN_FC) -{ - JSFunction *fun = script->getFunction(GET_UINT32_INDEX(regs.pc)); - - JSObject *obj = js_NewFlatClosure(cx, fun); - if (!obj) - goto error; - - Value rval = ObjectValue(*obj); - - uintN attrs = regs.fp()->isEvalFrame() - ? JSPROP_ENUMERATE - : JSPROP_ENUMERATE | JSPROP_PERMANENT; - - JSObject &parent = regs.fp()->varObj(); - - PropertyName *name = fun->atom->asPropertyName(); - if (!CheckRedeclaration(cx, &parent, name, attrs)) - goto error; - - if ((attrs == JSPROP_ENUMERATE) - ? !parent.setProperty(cx, name, &rval, script->strictModeCode) - : !parent.defineProperty(cx, name, rval, JS_PropertyStub, JS_StrictPropertyStub, attrs)) - { - goto error; - } -} -END_CASE(JSOP_DEFFUN_FC) - BEGIN_CASE(JSOP_DEFLOCALFUN) { /* diff --git a/js/src/jsopcode.cpp b/js/src/jsopcode.cpp index ba32fb133e8c..dcd05a1511b7 100644 --- a/js/src/jsopcode.cpp +++ b/js/src/jsopcode.cpp @@ -5133,11 +5133,9 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb) } case JSOP_DEFFUN: - case JSOP_DEFFUN_FC: fun = jp->script->getFunction(GET_UINT32_INDEX(pc)); todo = -2; goto do_function; - break; case JSOP_HOLE: todo = SprintPut(&ss->sprinter, "", 0); diff --git a/js/src/jsopcode.tbl b/js/src/jsopcode.tbl index 6e24ac30408b..534e59f226fd 100644 --- a/js/src/jsopcode.tbl +++ b/js/src/jsopcode.tbl @@ -552,10 +552,11 @@ OPDEF(JSOP_LENGTH, 217, "length", NULL, 3, 1, 1, 18, JOF_ATOM|J */ OPDEF(JSOP_HOLE, 218, "hole", NULL, 1, 0, 1, 0, JOF_BYTE) +OPDEF(JSOP_UNUSED17, 219,"unused17", NULL, 1, 0, 0, 0, JOF_BYTE) + /* - * Variants of JSOP_{DEF{,LOCAL}FUN,LAMBDA} optimized for the flat closure case. + * Variants of JSOP_{DEFLOCALFUN,LAMBDA} optimized for the flat closure case. */ -OPDEF(JSOP_DEFFUN_FC, 219,"deffun_fc", NULL, 5, 0, 0, 0, JOF_OBJECT|JOF_DECLARING) OPDEF(JSOP_DEFLOCALFUN_FC,220,"deflocalfun_fc",NULL, 7, 0, 0, 0, JOF_SLOTOBJECT|JOF_DECLARING|JOF_TMPSLOT) OPDEF(JSOP_LAMBDA_FC, 221,"lambda_fc", NULL, 5, 0, 1, 19, JOF_OBJECT)