diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-06-27 17:23:39 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-07-03 08:08:53 +0000 |
commit | deaa99f66ddedc2ea79e6902c665925b04665e68 (patch) | |
tree | af0cb554eb40d9138f9cf723f0aa982991205635 /src/qml/jsruntime/qv4functionobject.cpp | |
parent | 2666fe4a1440cc798b9db68fcc807450d46069c2 (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/qv4functionobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 27bdc7dd44..e88b81bd29 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -58,6 +58,7 @@ #include "private/qlocale_tools_p.h" #include "private/qqmlbuiltinfunctions_p.h" #include <private/qv4jscall_p.h> +#include <private/qv4vme_moth_p.h> #include <QtCore/QDebug> #include <algorithm> @@ -458,7 +459,18 @@ ReturnedValue ScriptFunction::virtualCallAsConstructor(const FunctionObject *fo, Scope scope(v4); ScopedValue thisObject(scope, v4->memoryManager->allocObject<Object>(f->classForConstructor())); - ReturnedValue result = Moth::VME::exec(fo, thisObject, argv, argc, newTarget); + CppStackFrame frame; + frame.init(v4, f->function(), argv, argc); + frame.setupJSFrame(v4->jsStackTop, *f, f->scope(), + thisObject, + newTarget ? *newTarget : Primitive::undefinedValue()); + + frame.push(); + v4->jsStackTop += frame.requiredJSStackFrameSize(); + + ReturnedValue result = Moth::VME::exec(&frame, v4); + + frame.pop(); if (Q_UNLIKELY(v4->hasException)) return Encode::undefined(); @@ -469,7 +481,21 @@ ReturnedValue ScriptFunction::virtualCallAsConstructor(const FunctionObject *fo, ReturnedValue ScriptFunction::virtualCall(const FunctionObject *fo, const Value *thisObject, const Value *argv, int argc) { - return Moth::VME::exec(fo, thisObject, argv, argc); + ExecutionEngine *engine = fo->engine(); + CppStackFrame frame; + frame.init(engine, fo->function(), argv, argc); + frame.setupJSFrame(engine->jsStackTop, *fo, fo->scope(), + thisObject ? *thisObject : Primitive::undefinedValue(), + Primitive::undefinedValue()); + + frame.push(); + engine->jsStackTop += frame.requiredJSStackFrameSize(); + + ReturnedValue result = Moth::VME::exec(&frame, engine); + + frame.pop(); + + return result; } void Heap::ScriptFunction::init(QV4::ExecutionContext *scope, Function *function) |