Bug 656462, part 2 - Merge ContextStack::get* and push* operations (r=waldo)
This commit is contained in:
@@ -1150,7 +1150,8 @@ js_NewGenerator(JSContext *cx)
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
StackFrame *stackfp = cx->fp();
|
||||
FrameRegs &stackRegs = cx->regs();
|
||||
StackFrame *stackfp = stackRegs.fp();
|
||||
JS_ASSERT(stackfp->base() == cx->regs().sp);
|
||||
JS_ASSERT(stackfp->actualArgs() <= stackfp->formalArgs());
|
||||
|
||||
@@ -1179,12 +1180,9 @@ js_NewGenerator(JSContext *cx)
|
||||
gen->enumerators = NULL;
|
||||
gen->floating = genfp;
|
||||
|
||||
/* Initialize regs stored in generator. */
|
||||
gen->regs = cx->regs();
|
||||
gen->regs.rebaseFromTo(stackfp, genfp);
|
||||
|
||||
/* Copy frame off the stack. */
|
||||
genfp->stealFrameAndSlots(genvp, stackfp, stackvp, cx->regs().sp);
|
||||
/* Copy from the stack to the generator's floating frame. */
|
||||
gen->regs.rebaseFromTo(stackRegs, genfp);
|
||||
genfp->stealFrameAndSlots(genvp, stackfp, stackvp, stackRegs.sp);
|
||||
genfp->initFloatingGenerator();
|
||||
|
||||
obj->setPrivate(gen);
|
||||
@@ -1253,54 +1251,29 @@ SendToGenerator(JSContext *cx, JSGeneratorOp op, JSObject *obj,
|
||||
}
|
||||
|
||||
StackFrame *genfp = gen->floatingFrame();
|
||||
Value *genvp = gen->floatingStack;
|
||||
uintN vplen = genfp->formalArgsEnd() - genvp;
|
||||
|
||||
StackFrame *stackfp;
|
||||
Value *stackvp;
|
||||
JSBool ok;
|
||||
{
|
||||
/*
|
||||
* Get a pointer to new frame/slots. This memory is not "claimed", so
|
||||
* the code before pushExecuteFrame must not reenter the interpreter.
|
||||
*/
|
||||
GeneratorFrameGuard frame;
|
||||
if (!cx->stack.getGeneratorFrame(cx, vplen, genfp->numSlots(), &frame)) {
|
||||
GeneratorFrameGuard gfg;
|
||||
if (!cx->stack.pushGeneratorFrame(cx, gen, &gfg)) {
|
||||
gen->state = JSGEN_CLOSED;
|
||||
return JS_FALSE;
|
||||
}
|
||||
stackfp = frame.fp();
|
||||
stackvp = frame.vp();
|
||||
|
||||
/* Copy frame onto the stack. */
|
||||
stackfp->stealFrameAndSlots(stackvp, genfp, genvp, gen->regs.sp);
|
||||
stackfp->resetGeneratorPrev(cx);
|
||||
stackfp->unsetFloatingGenerator();
|
||||
gen->regs.rebaseFromTo(genfp, stackfp);
|
||||
MUST_FLOW_THROUGH("restore");
|
||||
|
||||
/* Officially push frame. frame's destructor pops. */
|
||||
cx->stack.pushGeneratorFrame(gen->regs, &frame);
|
||||
StackFrame *fp = gfg.fp();
|
||||
gen->regs = cx->regs();
|
||||
JS_ASSERT(gen->liveFrame() == fp);
|
||||
|
||||
cx->enterGenerator(gen); /* OOM check above. */
|
||||
JSObject *enumerators = cx->enumerators;
|
||||
cx->enumerators = gen->enumerators;
|
||||
|
||||
ok = RunScript(cx, stackfp->script(), stackfp);
|
||||
ok = RunScript(cx, fp->script(), fp);
|
||||
|
||||
gen->enumerators = cx->enumerators;
|
||||
cx->enumerators = enumerators;
|
||||
cx->leaveGenerator(gen);
|
||||
|
||||
/*
|
||||
* Copy the stack frame and rebase the regs, but not before popping
|
||||
* the stack, since cx->regs == &gen->regs.
|
||||
*/
|
||||
genfp->stealFrameAndSlots(genvp, stackfp, stackvp, gen->regs.sp);
|
||||
genfp->setFloatingGenerator();
|
||||
}
|
||||
MUST_FLOW_LABEL(restore)
|
||||
gen->regs.rebaseFromTo(stackfp, genfp);
|
||||
|
||||
if (gen->floatingFrame()->isYielding()) {
|
||||
/* Yield cannot fail, throw or be called on closing. */
|
||||
|
||||
Reference in New Issue
Block a user