diff options
author | Lars Knoll <lars.knoll@qt.io> | 2016-12-01 15:37:32 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2016-12-09 08:31:01 +0000 |
commit | deec039008c4df5ec2686459ee8c00801ee9d852 (patch) | |
tree | 0998823cc67809bbdf83424edd07d9175ea6c613 /src/qml/jsruntime/qv4script.cpp | |
parent | e54e4408bd03edc789370dd7670eb6da25e8a9bb (diff) |
Refactor the calling code for (Simple)ScriptFunction
Factor the common code out into separate methods that can
later on be reused by the QQmlJavaScriptExpression.
Also ensure a CallContext is safe to use with a 0
FunctionObject.
Change-Id: I1181a8e320b8c931d9df5b2c91bc143d8587fb60
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4script.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 8c27d36f50..25089855bb 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -72,7 +72,9 @@ struct QmlBindingWrapper : FunctionObject { struct QmlBindingWrapper : FunctionObject { V4_OBJECT2(QmlBindingWrapper, FunctionObject) - static void call(const Managed *that, Scope &scope, CallData *callData); + static void call(const Managed *that, Scope &scope, CallData *callData) { + QV4::ScriptFunction::call(that, scope, callData); + } }; } @@ -94,30 +96,6 @@ void Heap::QmlBindingWrapper::init(QV4::QmlContext *scope, Function *f) function->compilationUnit->addref(); } -void QmlBindingWrapper::call(const Managed *that, Scope &scope, CallData *callData) -{ - const QmlBindingWrapper *This = static_cast<const QmlBindingWrapper *>(that); - ExecutionEngine *v4 = static_cast<const Object *>(that)->engine(); - if (v4->hasException) { - scope.result = Encode::undefined(); - return; - } - CHECK_STACK_LIMITS(v4, scope); - - ExecutionContextSaver ctxSaver(scope); - - QV4::Function *f = This->function(); - if (!f) { - scope.result = QV4::Encode::undefined(); - return; - } - - Scoped<CallContext> ctx(scope, v4->currentContext->newCallContext(This, callData)); - v4->pushContext(ctx); - - scope.result = Q_V4_PROFILE(v4, f); -} - Script::Script(ExecutionEngine *v4, QmlContext *qml, CompiledData::CompilationUnit *compilationUnit) : line(0), column(0), scope(v4->rootContext()), strictMode(false), inheritContext(true), parsed(false) , compilationUnit(compilationUnit), vmFunction(0), parseAsBinding(true) @@ -228,10 +206,12 @@ ReturnedValue Script::run() return Q_V4_PROFILE(engine, vmFunction); } else { Scoped<QmlContext> qml(valueScope, qmlContext.value()); - ScopedFunctionObject f(valueScope, engine->memoryManager->allocObject<QmlBindingWrapper>(qml, vmFunction)); ScopedCallData callData(valueScope); callData->thisObject = Primitive::undefinedValue(); - f->call(valueScope, callData); + if (vmFunction->canUseSimpleFunction()) + qml->simpleCall(valueScope, callData, vmFunction); + else + qml->call(valueScope, callData, vmFunction); return valueScope.result.asReturnedValue(); } } |