aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-02-15 15:16:01 +0100
committerErik Verbruggen <erik.verbruggen@qt.io>2018-02-20 08:44:07 +0000
commit2f784a544ec4dccaa70ee1bcec71c8e6c2bd5d99 (patch)
treefebaa003be903df7dfc9af2c8c3a442a60ba2557 /src/qml/jsruntime
parentb8dbe476f01a38afc921f9693d89f3c72396651a (diff)
Correctly set this object when calling scope/context functions
When a function is called that is in a QML scope or a QML context, set the 'this' object to the QML scope. This is done by introducing two new interpreter instructions, which get the context passed in. Note: this patch is 5.11 specific. 5.9 had a similair issue, but the implementation is quite different, so that was fixed separately. Task-number: QTBUG-66432 Change-Id: Ie43150cdd26360025895df28d31264985abf1c15 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp31
-rw-r--r--src/qml/jsruntime/qv4runtimeapi_p.h2
-rw-r--r--src/qml/jsruntime/qv4vme_moth.cpp12
3 files changed, 45 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index e7a104af66..eb4f6a21fc 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -1098,6 +1098,37 @@ ReturnedValue Runtime::method_callValue(ExecutionEngine *engine, const Value &fu
return static_cast<const FunctionObject &>(func).call(nullptr, argv, argc);
}
+ReturnedValue Runtime::method_callQmlScopeObjectProperty(ExecutionEngine *engine, Value *base,
+ int propertyIndex, Value *argv, int argc)
+{
+ Scope scope(engine);
+ ScopedFunctionObject fo(scope, method_loadQmlScopeObjectProperty(engine, *base, propertyIndex,
+ /*captureRequired*/true));
+ if (!fo) {
+ QString error = QStringLiteral("Property '%1' of scope object is not a function").arg(propertyIndex);
+ return engine->throwTypeError(error);
+ }
+
+ QObject *qmlScopeObj = static_cast<QmlContext *>(base)->d()->qml()->scopeObject;
+ ScopedValue qmlScopeValue(scope, QObjectWrapper::wrap(engine, qmlScopeObj));
+ return fo->call(qmlScopeValue, argv, argc);
+}
+
+ReturnedValue Runtime::method_callQmlContextObjectProperty(ExecutionEngine *engine, Value *base,
+ int propertyIndex, Value *argv, int argc)
+{
+ Scope scope(engine);
+ ScopedFunctionObject fo(scope, method_loadQmlContextObjectProperty(engine, *base, propertyIndex,
+ /*captureRequired*/true));
+ if (!fo) {
+ QString error = QStringLiteral("Property '%1' of context object is not a function").arg(propertyIndex);
+ return engine->throwTypeError(error);
+ }
+
+ QObject *qmlContextObj = static_cast<QmlContext *>(base)->d()->qml()->context->contextData()->contextObject;
+ ScopedValue qmlContextValue(scope, QObjectWrapper::wrap(engine, qmlContextObj));
+ return fo->call(qmlContextValue, argv, argc);
+}
ReturnedValue Runtime::method_construct(ExecutionEngine *engine, const Value &function, Value *argv, int argc)
{
diff --git a/src/qml/jsruntime/qv4runtimeapi_p.h b/src/qml/jsruntime/qv4runtimeapi_p.h
index ea31dfd08b..2956a4a463 100644
--- a/src/qml/jsruntime/qv4runtimeapi_p.h
+++ b/src/qml/jsruntime/qv4runtimeapi_p.h
@@ -188,6 +188,8 @@ struct ExceptionCheck<void (*)(QV4::NoThrowEngine *, A, B, C)> {
F(ReturnedValue, loadQmlScopeObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, bool captureRequired)) \
F(ReturnedValue, loadQmlContextObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, bool captureRequired)) \
F(ReturnedValue, loadQmlIdObject, (ExecutionEngine *engine, const Value &context, uint index)) \
+ F(ReturnedValue, callQmlScopeObjectProperty, (ExecutionEngine *engine, Value *base, int propertyIndex, Value *argv, int argc)) \
+ F(ReturnedValue, callQmlContextObjectProperty, (ExecutionEngine *engine, Value *base, int propertyIndex, Value *argv, int argc)) \
\
F(void, storeQmlScopeObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, const Value &value)) \
F(void, storeQmlContextObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, const Value &value)) \
diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp
index e248d590f7..d44c219d18 100644
--- a/src/qml/jsruntime/qv4vme_moth.cpp
+++ b/src/qml/jsruntime/qv4vme_moth.cpp
@@ -840,6 +840,18 @@ QV4::ReturnedValue VME::exec(const FunctionObject *fo, const Value *thisObject,
CHECK_EXCEPTION;
MOTH_END_INSTR(CallGlobalLookup)
+ MOTH_BEGIN_INSTR(CallScopeObjectProperty)
+ STORE_IP();
+ acc = Runtime::method_callQmlScopeObjectProperty(engine, stack + base, name, stack + argv, argc);
+ CHECK_EXCEPTION;
+ MOTH_END_INSTR(CallScopeObjectProperty)
+
+ MOTH_BEGIN_INSTR(CallContextObjectProperty)
+ STORE_IP();
+ acc = Runtime::method_callQmlContextObjectProperty(engine, stack + base, name, stack + argv, argc);
+ CHECK_EXCEPTION;
+ MOTH_END_INSTR(CallContextObjectProperty)
+
MOTH_BEGIN_INSTR(SetExceptionHandler)
exceptionHandler = offset ? code + offset : nullptr;
MOTH_END_INSTR(SetExceptionHandler)