aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4generatorobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-06-27 17:23:39 +0200
committerLars Knoll <lars.knoll@qt.io>2018-07-03 08:08:53 +0000
commitdeaa99f66ddedc2ea79e6902c665925b04665e68 (patch)
treeaf0cb554eb40d9138f9cf723f0aa982991205635 /src/qml/jsruntime/qv4generatorobject.cpp
parent2666fe4a1440cc798b9db68fcc807450d46069c2 (diff)
Refactor initialization code for JS stack frames
Move code into qv4stackframe_p.h, so that it can be re-used from different places. Clean up VME::exec and the generatorfunctions using this. Change-Id: Ib4f7eceeb5f55d98dd6ccf2584d13a3b864caea1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4generatorobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4generatorobject.cpp32
1 files changed, 9 insertions, 23 deletions
diff --git a/src/qml/jsruntime/qv4generatorobject.cpp b/src/qml/jsruntime/qv4generatorobject.cpp
index d5ae863856..bfc27954c4 100644
--- a/src/qml/jsruntime/qv4generatorobject.cpp
+++ b/src/qml/jsruntime/qv4generatorobject.cpp
@@ -96,9 +96,8 @@ ReturnedValue GeneratorFunction::virtualCall(const FunctionObject *f, const Valu
ExecutionEngine *engine = gf->engine();
// We need to set up a separate stack for the generator, as it's being re-entered
- uint stackSize = argc; // space for the original arguments
- int jsStackFrameSize = offsetof(CallData, args)/sizeof(Value) + function->compiledFunction->nRegisters;
- stackSize += jsStackFrameSize;
+ uint stackSize = argc // space for the original arguments
+ + CppStackFrame::requiredJSStackFrameSize(function); // space for the JS stack frame
size_t requiredMemory = sizeof(GeneratorObject::Data) - sizeof(Value) + sizeof(Value) * stackSize;
@@ -112,30 +111,17 @@ ReturnedValue GeneratorFunction::virtualCall(const FunctionObject *f, const Valu
// copy original arguments
memcpy(gp->stack.values, argv, argc*sizeof(Value));
- gp->cppFrame.originalArguments = gp->stack.values;
- gp->cppFrame.originalArgumentsCount = argc;
-
- // setup JS stack frame
- CallData *callData = reinterpret_cast<CallData *>(&gp->stack.values[argc]);
- callData->function = *gf;
- callData->context = gf->scope();
- callData->accumulator = Encode::undefined();
- callData->thisObject = thisObject ? *thisObject : Primitive::undefinedValue();
- if (argc > int(function->nFormals))
- argc = int(function->nFormals);
- callData->setArgc(argc);
- memcpy(callData->args, argv, argc*sizeof(Value));
-
- gp->cppFrame.v4Function = function;
- gp->cppFrame.instructionPointer = 0;
- gp->cppFrame.jsFrame = callData;
- gp->cppFrame.parent = engine->currentStackFrame;
- engine->currentStackFrame = &gp->cppFrame;
+ gp->cppFrame.init(engine, function, gp->stack.values, argc);
+ gp->cppFrame.setupJSFrame(&gp->stack.values[argc], *gf, gf->scope(),
+ thisObject ? *thisObject : Primitive::undefinedValue(),
+ Primitive::undefinedValue());
+
+ gp->cppFrame.push();
Moth::VME::interpret(&gp->cppFrame, engine, function->codeData);
gp->state = GeneratorState::SuspendedStart;
- engine->currentStackFrame = gp->cppFrame.parent;
+ gp->cppFrame.pop();
return g->asReturnedValue();
}