diff options
Diffstat (limited to 'src/qml/qml/qqmlvmemetaobject.cpp')
-rw-r--r-- | src/qml/qml/qqmlvmemetaobject.cpp | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 0079b9580f..6739143979 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -911,8 +911,10 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) QQmlEnginePrivate *ep = QQmlEnginePrivate::get(ctxt->engine); ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation. + QV4::Scope scope(ep->v4engine()); - QV4::FunctionObject *function = method(id).asFunctionObject(); + + QV4::Scoped<QV4::FunctionObject> function(scope, method(id)); if (!function) { // The function was not compiled. There are some exceptional cases which the // expression rewriter does not rewrite properly (e.g., \r-terminated lines @@ -927,13 +929,13 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) QQmlVMEMetaData::MethodData *data = metaData->methodData() + id; - QV4::ScopedCallData callData(function->engine(), data->parameterCount); + QV4::ScopedCallData callData(scope, data->parameterCount); callData->thisObject = ep->v8engine()->global(); for (int ii = 0; ii < data->parameterCount; ++ii) - callData->args[ii] = ep->v8engine()->fromVariant(*(QVariant *)a[ii + 1]); + callData->args[ii] = QV4::Value::fromReturnedValue(ep->v8engine()->fromVariant(*(QVariant *)a[ii + 1])); - QV4::Value result = QV4::Value::undefinedValue(); + QV4::ScopedValue result(scope); QV4::ExecutionContext *ctx = function->engine()->current; try { result = function->call(callData); @@ -960,11 +962,11 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) return object->qt_metacall(c, _id, a); } -QV4::Value QQmlVMEMetaObject::method(int index) +QV4::ReturnedValue QQmlVMEMetaObject::method(int index) { if (!ctxt || !ctxt->isValid()) { qWarning("QQmlVMEMetaObject: Internal error - attempted to evaluate a function in an invalid context"); - return QV4::Value::emptyValue(); + return QV4::Value::emptyValue().asReturnedValue(); } if (!v8methods) @@ -983,16 +985,16 @@ QV4::Value QQmlVMEMetaObject::method(int index) ctxt->urlString, data->lineNumber); } - return v8methods[index]; + return v8methods[index].value().asReturnedValue(); } -QV4::Value QQmlVMEMetaObject::readVarProperty(int id) +QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id) { Q_ASSERT(id >= firstVarPropertyIndex); if (ensureVarPropertiesAllocated()) return varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex); - return QV4::Value::emptyValue(); + return QV4::Value::emptyValue().asReturnedValue(); } QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) @@ -1000,7 +1002,7 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) if (id >= firstVarPropertyIndex) { if (ensureVarPropertiesAllocated()) return QQmlEnginePrivate::get(ctxt->engine)->v8engine()->toVariant( - varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex), -1); + QV4::Value::fromReturnedValue(varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex)), -1); return QVariant(); } else { if (data[id].dataType() == QMetaType::QObjectStar) { @@ -1017,11 +1019,12 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) if (!ensureVarPropertiesAllocated()) return; + QV4::Scope scope(varProperties.engine()); // Importantly, if the current value is a scarce resource, we need to ensure that it // gets automatically released by the engine if no other references to it exist. - QV4::Value oldv = varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex); - if (QV4::VariantObject *v = oldv.as<QV4::VariantObject>()) - v->removeVmePropertyReference(); + QV4::Scoped<QV4::VariantObject> oldv(scope, varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex)); + if (!!oldv) + oldv->removeVmePropertyReference(); QObject *valueObject = 0; QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id); @@ -1058,16 +1061,18 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) if (!ensureVarPropertiesAllocated()) return; + QV4::Scope scope(varProperties.engine()); + // Importantly, if the current value is a scarce resource, we need to ensure that it // gets automatically released by the engine if no other references to it exist. - QV4::Value oldv = varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex); - if (QV4::VariantObject *v = oldv.as<QV4::VariantObject>()) - v->removeVmePropertyReference(); + QV4::Scoped<QV4::VariantObject> oldv(scope, varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex)); + if (!!oldv) + oldv->removeVmePropertyReference(); // And, if the new value is a scarce resource, we need to ensure that it does not get // automatically released by the engine until no other references to it exist. - QV4::Value newv = QQmlEnginePrivate::get(ctxt->engine)->v8engine()->fromVariant(value); - if (QV4::VariantObject *v = newv.as<QV4::VariantObject>()) + QV4::ScopedValue newv(scope, QQmlEnginePrivate::get(ctxt->engine)->v8engine()->fromVariant(value)); + if (QV4::VariantObject *v = newv->as<QV4::VariantObject>()) v->addVmePropertyReference(); // Write the value and emit change signal as appropriate. @@ -1146,7 +1151,7 @@ quint16 QQmlVMEMetaObject::vmeMethodLineNumber(int index) return data->lineNumber; } -QV4::Value QQmlVMEMetaObject::vmeMethod(int index) +QV4::ReturnedValue QQmlVMEMetaObject::vmeMethod(int index) { if (index < methodOffset()) { Q_ASSERT(parentVMEMetaObject()); @@ -1174,7 +1179,7 @@ void QQmlVMEMetaObject::setVmeMethod(int index, QV4::PersistentValue function) v8methods[methodIndex] = function; } -QV4::Value QQmlVMEMetaObject::vmeProperty(int index) +QV4::ReturnedValue QQmlVMEMetaObject::vmeProperty(int index) { if (index < propOffset()) { Q_ASSERT(parentVMEMetaObject()); @@ -1240,7 +1245,8 @@ void QQmlVMEMetaObject::allocateVarPropertiesArray() QQmlEngine *qml = qmlEngine(object); assert(qml); QV4::ExecutionEngine *v4 = QV8Engine::getV4(qml->handle()); - varProperties = QV4::Value::fromObject(v4->newArrayObject(metaData->varPropertyCount)); + QV4::Scope scope(v4); + varProperties = QV4::ScopedValue(scope, v4->newArrayObject(metaData->varPropertyCount)); varPropertiesInitialized = true; } |