aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlcontextwrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/qml/qqmlcontextwrapper.cpp')
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp203
1 files changed, 19 insertions, 184 deletions
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp
index 5844eab54f..0d84c3bb64 100644
--- a/src/qml/qml/qqmlcontextwrapper.cpp
+++ b/src/qml/qml/qqmlcontextwrapper.cpp
@@ -38,13 +38,14 @@
#include <private/qqmlcontext_p.h>
#include <private/qv4engine_p.h>
-#include <private/qv4value_inl_p.h>
+#include <private/qv4value_p.h>
#include <private/qv4objectproto_p.h>
#include <private/qv4mm_p.h>
#include <private/qv4function_p.h>
#include <private/qv4compileddata_p.h>
#include <private/qqmltypewrapper_p.h>
#include <private/qqmllistwrapper_p.h>
+#include <private/qqmljavascriptexpression_p.h>
#include <private/qjsvalue_p.h>
QT_BEGIN_NAMESPACE
@@ -53,14 +54,12 @@ using namespace QV4;
DEFINE_OBJECT_VTABLE(QmlContextWrapper);
-Heap::QmlContextWrapper::QmlContextWrapper(QV4::ExecutionEngine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext)
- : Heap::Object(engine)
- , readOnly(true)
+Heap::QmlContextWrapper::QmlContextWrapper(QQmlContextData *context, QObject *scopeObject, bool ownsContext)
+ : readOnly(true)
, ownsContext(ownsContext)
, isNullWrapper(false)
, context(context)
, scopeObject(scopeObject)
- , idObjectsWrapper(Q_NULLPTR)
{
}
@@ -74,7 +73,7 @@ ReturnedValue QmlContextWrapper::qmlScope(ExecutionEngine *v4, QQmlContextData *
{
Scope valueScope(v4);
- Scoped<QmlContextWrapper> w(valueScope, v4->memoryManager->alloc<QmlContextWrapper>(v4, ctxt, scope));
+ Scoped<QmlContextWrapper> w(valueScope, v4->memoryManager->allocObject<QmlContextWrapper>(ctxt, scope));
return w.asReturnedValue();
}
@@ -88,67 +87,26 @@ ReturnedValue QmlContextWrapper::urlScope(ExecutionEngine *v4, const QUrl &url)
context->isInternal = true;
context->isJSContext = true;
- Scoped<QmlContextWrapper> w(scope, v4->memoryManager->alloc<QmlContextWrapper>(v4, context, (QObject*)0, true));
+ Scoped<QmlContextWrapper> w(scope, v4->memoryManager->allocObject<QmlContextWrapper>(context, (QObject*)0, true));
w->d()->isNullWrapper = true;
return w.asReturnedValue();
}
-QQmlContextData *QmlContextWrapper::callingContext(ExecutionEngine *v4)
-{
- Scope scope(v4);
- QV4::Scoped<QmlContextWrapper> c(scope, v4->qmlContextObject());
-
- return !!c ? c->getContext() : 0;
-}
-
-QQmlContextData *QmlContextWrapper::getContext(const Value &value)
-{
- if (!value.isObject())
- return 0;
-
- QV4::ExecutionEngine *v4 = value.asObject()->engine();
- Scope scope(v4);
- QV4::Scoped<QmlContextWrapper> c(scope, value);
-
- return c ? c->getContext() : 0;
-}
-
-void QmlContextWrapper::takeContextOwnership(const Value &qmlglobal)
-{
- Q_ASSERT(qmlglobal.isObject());
-
- QV4::ExecutionEngine *v4 = qmlglobal.asObject()->engine();
- Scope scope(v4);
- QV4::Scoped<QmlContextWrapper> c(scope, qmlglobal);
- Q_ASSERT(c);
- c->d()->ownsContext = true;
-}
-
-
-ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty)
+ReturnedValue QmlContextWrapper::get(const Managed *m, String *name, bool *hasProperty)
{
Q_ASSERT(m->as<QmlContextWrapper>());
- QmlContextWrapper *resource = static_cast<QmlContextWrapper *>(m);
+ const QmlContextWrapper *resource = static_cast<const QmlContextWrapper *>(m);
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 (QV4::QmlContextWrapper::callingContext(v4) != resource->d()->context)
+ if (v4->callingQmlContext() != resource->d()->context)
return Object::get(m, name, hasProperty);
- result = Object::get(m, name, &hasProp);
+ bool hasProp;
+ QV4::ScopedValue result(scope, Object::get(m, name, &hasProp));
if (hasProp) {
if (hasProperty)
*hasProperty = hasProp;
@@ -209,7 +167,8 @@ ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty
if (propertyIdx < context->idValueCount) {
- ep->captureProperty(&context->idValues[propertyIdx].bindings);
+ if (ep->propertyCapture)
+ ep->propertyCapture->captureProperty(&context->idValues[propertyIdx].bindings);
if (hasProperty)
*hasProperty = true;
return QV4::QObjectWrapper::wrap(v4, context->idValues[propertyIdx]);
@@ -217,8 +176,8 @@ ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty
QQmlContextPrivate *cp = context->asQQmlContextPrivate();
- ep->captureProperty(context->asQQmlContext(), -1,
- propertyIdx + cp->notifyIndex);
+ if (ep->propertyCapture)
+ ep->propertyCapture->captureProperty(context->asQQmlContext(), -1, propertyIdx + cp->notifyIndex);
const QVariant &value = cp->propertyValues.at(propertyIdx);
if (hasProperty)
@@ -278,10 +237,9 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value)
return;
QV4::Scoped<QmlContextWrapper> wrapper(scope, resource);
- PropertyAttributes attrs;
- Property *pd = wrapper->__getOwnProperty__(name, &attrs);
- if (pd) {
- wrapper->putValue(pd, attrs, value);
+ uint member = wrapper->internalClass()->find(name);
+ if (member < UINT_MAX) {
+ wrapper->putValue(member, value);
return;
}
@@ -289,7 +247,7 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value)
if (wrapper && wrapper->d()->readOnly) {
QString error = QLatin1String("Invalid write to global property \"") + name->toQString() +
QLatin1Char('"');
- ScopedString e(scope, v4->currentContext()->engine->newString(error));
+ ScopedString e(scope, v4->newString(error));
v4->throwError(e);
return;
}
@@ -342,127 +300,4 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value)
Object::put(m, name, value);
}
-void QmlContextWrapper::markObjects(Heap::Base *m, ExecutionEngine *engine)
-{
- QmlContextWrapper::Data *This = static_cast<QmlContextWrapper::Data *>(m);
- if (This->idObjectsWrapper)
- This->idObjectsWrapper->mark(engine);
- Object::markObjects(m, engine);
-}
-
-void QmlContextWrapper::registerQmlDependencies(ExecutionEngine *engine, const CompiledData::Function *compiledFunction)
-{
- // Let the caller check and avoid the function call :)
- Q_ASSERT(compiledFunction->hasQmlDependencies());
-
- QQmlEnginePrivate *ep = engine->qmlEngine() ? QQmlEnginePrivate::get(engine->qmlEngine()) : 0;
- if (!ep)
- return;
- QQmlEnginePrivate::PropertyCapture *capture = ep->propertyCapture;
- if (!capture)
- return;
-
- QV4::Scope scope(engine);
- QV4::Scoped<QmlContextWrapper> contextWrapper(scope, engine->qmlContextObject());
- QQmlContextData *qmlContext = contextWrapper->getContext();
-
- const quint32 *idObjectDependency = compiledFunction->qmlIdObjectDependencyTable();
- const int idObjectDependencyCount = compiledFunction->nDependingIdObjects;
- for (int i = 0; i < idObjectDependencyCount; ++i, ++idObjectDependency) {
- Q_ASSERT(int(*idObjectDependency) < qmlContext->idValueCount);
- capture->captureProperty(&qmlContext->idValues[*idObjectDependency].bindings);
- }
-
- Q_ASSERT(qmlContext->contextObject);
- const quint32 *contextPropertyDependency = compiledFunction->qmlContextPropertiesDependencyTable();
- const int contextPropertyDependencyCount = compiledFunction->nDependingContextProperties;
- for (int i = 0; i < contextPropertyDependencyCount; ++i) {
- const int propertyIndex = *contextPropertyDependency++;
- const int notifyIndex = *contextPropertyDependency++;
- capture->captureProperty(qmlContext->contextObject, propertyIndex, notifyIndex);
- }
-
- QObject *scopeObject = contextWrapper->getScopeObject();
- const quint32 *scopePropertyDependency = compiledFunction->qmlScopePropertiesDependencyTable();
- const int scopePropertyDependencyCount = compiledFunction->nDependingScopeProperties;
- for (int i = 0; i < scopePropertyDependencyCount; ++i) {
- const int propertyIndex = *scopePropertyDependency++;
- const int notifyIndex = *scopePropertyDependency++;
- capture->captureProperty(scopeObject, propertyIndex, notifyIndex);
- }
-
-}
-
-ReturnedValue QmlContextWrapper::idObjectsArray()
-{
- if (!d()->idObjectsWrapper) {
- ExecutionEngine *v4 = engine();
- d()->idObjectsWrapper = v4->memoryManager->alloc<QQmlIdObjectsArray>(v4, this);
- }
- return d()->idObjectsWrapper->asReturnedValue();
-}
-
-ReturnedValue QmlContextWrapper::qmlSingletonWrapper(ExecutionEngine *v4, String *name)
-{
- if (!d()->context->imports)
- return Encode::undefined();
- // Search for attached properties, enums and imported scripts
- QQmlTypeNameCache::Result r = d()->context->imports->query(name);
-
- Q_ASSERT(r.isValid());
- Q_ASSERT(r.type);
- Q_ASSERT(r.type->isSingleton());
- Q_ASSERT(v4);
-
- QQmlEngine *e = v4->qmlEngine();
- QQmlType::SingletonInstanceInfo *siinfo = r.type->singletonInstanceInfo();
- siinfo->init(e);
-
- if (QObject *qobjectSingleton = siinfo->qobjectApi(e))
- return QV4::QObjectWrapper::wrap(engine(), qobjectSingleton);
- return QJSValuePrivate::convertedToValue(engine(), siinfo->scriptApi(e));
-}
-
-DEFINE_OBJECT_VTABLE(QQmlIdObjectsArray);
-
-Heap::QQmlIdObjectsArray::QQmlIdObjectsArray(ExecutionEngine *engine, QV4::QmlContextWrapper *contextWrapper)
- : Heap::Object(engine)
- , contextWrapper(contextWrapper->d())
-{
-}
-
-ReturnedValue QQmlIdObjectsArray::getIndexed(Managed *m, uint index, bool *hasProperty)
-{
- Scope scope(static_cast<QV4::QQmlIdObjectsArray*>(m)->engine());
- Scoped<QQmlIdObjectsArray> This(scope, static_cast<QV4::QQmlIdObjectsArray*>(m));
- Scoped<QmlContextWrapper> contextWrapper(scope, This->d()->contextWrapper);
- QQmlContextData *context = contextWrapper->getContext();
- if (!context) {
- if (hasProperty)
- *hasProperty = false;
- return Encode::undefined();
- }
- if (index >= (uint)context->idValueCount) {
- if (hasProperty)
- *hasProperty = false;
- return Encode::undefined();
- }
-
- if (hasProperty)
- *hasProperty = true;
-
- QQmlEnginePrivate *ep = scope.engine->qmlEngine() ? QQmlEnginePrivate::get(scope.engine->qmlEngine()) : 0;
- if (ep)
- ep->captureProperty(&context->idValues[index].bindings);
-
- return QObjectWrapper::wrap(This->engine(), context->idValues[index].data());
-}
-
-void QQmlIdObjectsArray::markObjects(Heap::Base *that, ExecutionEngine *engine)
-{
- QQmlIdObjectsArray::Data *This = static_cast<QQmlIdObjectsArray::Data *>(that);
- This->contextWrapper->mark(engine);
- Object::markObjects(that, engine);
-}
-
QT_END_NAMESPACE