diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-03-09 15:24:49 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-06-17 20:06:16 +0000 |
commit | 9333ea8649838d7e0400b0e94c8cbd4fa5d216b0 (patch) | |
tree | 08a750b6afa315ac16ea855a87a1d1d18afe30e3 /src/qml/jsruntime/qv4qmlcontext.cpp | |
parent | 6b77f0eb99a33b46000ac66ec297082527009d5d (diff) |
Ensure we read context properties before the global object
Also global variables declared in a .pragma library script
should not be saved in the global object, as the script has
it's on context where those variables live.
[ChangeLog][QtQml] Properties of the JS global object will now
be looked up after local properties in the QML object. This
can lead to runtime incompatibilities if your qml file is named
the same as a property of the global object (e.g. Date.qml).
Task-number: QTBUG-51581
Change-Id: I108aea4c76d088ca8c2124700f91e8eac3fc19f3
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4qmlcontext.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4qmlcontext.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/qml/jsruntime/qv4qmlcontext.cpp b/src/qml/jsruntime/qv4qmlcontext.cpp index 8f87f24745..4226bf7972 100644 --- a/src/qml/jsruntime/qv4qmlcontext.cpp +++ b/src/qml/jsruntime/qv4qmlcontext.cpp @@ -90,23 +90,14 @@ ReturnedValue QQmlContextWrapper::get(const Managed *m, StringOrSymbol *n, bool QV4::ExecutionEngine *v4 = resource->engine(); QV4::Scope scope(v4); - // In V8 the JS global object would come _before_ the QML global object, - // so simulate that here. - bool hasProp; - QV4::ScopedValue result(scope, v4->globalObject->get(name, &hasProp)); - if (hasProp) { - if (hasProperty) - *hasProperty = hasProp; - return result->asReturnedValue(); - } - if (resource->d()->isNullWrapper) return Object::get(m, name, hasProperty); if (v4->callingQmlContext() != *resource->d()->context) return Object::get(m, name, hasProperty); - result = Object::get(m, name, &hasProp); + bool hasProp = false; + ScopedValue result(scope, Object::get(m, name, &hasProp)); if (hasProp) { if (hasProperty) *hasProperty = hasProp; @@ -224,6 +215,15 @@ ReturnedValue QQmlContextWrapper::get(const Managed *m, StringOrSymbol *n, bool context = context->parent; } + // Do a lookup in the global object here to avoid expressionContext->unresolvedNames becoming + // true if we access properties of the global object. + result = v4->globalObject->get(name, &hasProp); + if (hasProp) { + if (hasProperty) + *hasProperty = hasProp; + return result->asReturnedValue(); + } + expressionContext->unresolvedNames = true; return Encode::undefined(); |