From 0e36db9f1179d1bdf0710494e98ff7aee1a2d836 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 27 Sep 2013 09:45:55 +0200 Subject: Remove most uses of Value from qml/qml Change-Id: I409a8505a9e01f86d777bc694d24516d1c8f0c4d Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4qobjectwrapper.cpp | 4 +- src/qml/jsruntime/qv4scopedvalue_p.h | 2 + src/qml/qml/qqmlboundsignal.cpp | 22 ++++------ src/qml/qml/qqmlcomponent.cpp | 19 ++++---- src/qml/qml/qqmlcomponent_p.h | 2 +- src/qml/qml/qqmlcontextwrapper.cpp | 19 ++++---- src/qml/qml/qqmlcontextwrapper_p.h | 4 +- src/qml/qml/qqmljavascriptexpression.cpp | 20 +++++---- src/qml/qml/qqmljavascriptexpression_p.h | 7 +-- src/qml/qml/qqmllistwrapper.cpp | 2 +- src/qml/qml/qqmllocale.cpp | 4 +- src/qml/qml/qqmlobjectcreator.cpp | 2 +- src/qml/qml/qqmlproperty.cpp | 2 +- src/qml/qml/qqmlvme.cpp | 11 +++-- src/qml/qml/qqmlvmemetaobject.cpp | 11 +++-- src/qml/qml/qqmlvmemetaobject_p.h | 4 +- src/qml/qml/qqmlxmlhttprequest.cpp | 6 +-- src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 52 +++++++++++----------- src/qml/qml/v8/qv8engine.cpp | 10 ++--- src/qml/types/qqmldelegatemodel.cpp | 74 +++++++++++++++++++------------- src/qml/types/qqmldelegatemodel_p_p.h | 12 +++--- 21 files changed, 153 insertions(+), 136 deletions(-) (limited to 'src') diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index d28514f0c8..53e915c1a4 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -473,7 +473,7 @@ bool QObjectWrapper::setQmlProperty(ExecutionContext *ctx, QQmlContextData *qmlC // allow assignment of "special" values (null, undefined, function) to var properties QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(object); Q_ASSERT(vmemo); - vmemo->setVMEProperty(result->coreIndex, *value); + vmemo->setVMEProperty(result->coreIndex, value); return true; } @@ -517,7 +517,7 @@ bool QObjectWrapper::setQmlProperty(ExecutionContext *ctx, QQmlContextData *qmlC } else if (result->isVarProperty()) { QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(object); Q_ASSERT(vmemo); - vmemo->setVMEProperty(result->coreIndex, *value); + vmemo->setVMEProperty(result->coreIndex, value); } else { QVariant v; if (result->isQList()) diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index b32aed12d9..3a7526197e 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -370,6 +370,8 @@ struct ScopedCallData { ptr->argc = argc; #ifndef QT_NO_DEBUG scope.size += size; + for (int ii = 0; ii < qMax(argc, (int)QV4::Global::ReservedArgumentCount); ++ii) + ptr->args[ii] = QV4::Primitive::undefinedValue(); #endif } diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index 76825edd94..11dc873dd4 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -199,35 +199,31 @@ void QQmlBoundSignalExpression::evaluate(void **a) int *argsTypes = QQmlPropertyCache::methodParameterTypes(m_target, methodIndex, dummy, 0); int argCount = argsTypes ? *argsTypes : 0; - QV4::Value *args = (QV4::Value *)alloca(qMax(argCount, (int)QV4::Global::ReservedArgumentCount)*sizeof(QV4::Value)); -#ifndef QT_NO_DEBUG - for (int ii = 0; ii < qMax(argCount, (int)QV4::Global::ReservedArgumentCount); ++ii) - args[ii] = QV4::Primitive::undefinedValue(); -#endif + QV4::ScopedValue f(scope, m_v8function.value()); + QV4::ScopedCallData callData(scope, argCount); for (int ii = 0; ii < argCount; ++ii) { int type = argsTypes[ii + 1]; //### ideally we would use metaTypeToJS, however it currently gives different results // for several cases (such as QVariant type and QObject-derived types) //args[ii] = engine->metaTypeToJS(type, a[ii + 1]); if (type == QMetaType::QVariant) { - args[ii] = QV4::Value::fromReturnedValue(engine->fromVariant(*((QVariant *)a[ii + 1]))); + callData->args[ii] = engine->fromVariant(*((QVariant *)a[ii + 1])); } else if (type == QMetaType::Int) { //### optimization. Can go away if we switch to metaTypeToJS, or be expanded otherwise - args[ii] = QV4::Primitive::fromInt32(*reinterpret_cast(a[ii + 1])); + callData->args[ii] = QV4::Primitive::fromInt32(*reinterpret_cast(a[ii + 1])); } else if (type == qMetaTypeId()) { - args[ii] = QV4::Value::fromReturnedValue(*reinterpret_cast(a[ii + 1])); + callData->args[ii] = *reinterpret_cast(a[ii + 1]); } else if (ep->isQObject(type)) { if (!*reinterpret_cast(a[ii + 1])) - args[ii] = QV4::Primitive::nullValue(); + callData->args[ii] = QV4::Primitive::nullValue(); else - args[ii] = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(ep->v4engine(), *reinterpret_cast(a[ii + 1]))); + callData->args[ii] = QV4::QObjectWrapper::wrap(ep->v4engine(), *reinterpret_cast(a[ii + 1])); } else { - args[ii] = QV4::Value::fromReturnedValue(engine->fromVariant(QVariant(type, a[ii + 1]))); + callData->args[ii] = engine->fromVariant(QVariant(type, a[ii + 1])); } } - QV4::ScopedValue f(scope, m_v8function.value()); - QQmlJavaScriptExpression::evaluate(context(), f, argCount, args, 0); + QQmlJavaScriptExpression::evaluate(context(), f, callData, 0); } ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete. } diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 0b5e8cff0a..b83d901da5 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -1122,9 +1122,9 @@ public: QV8Engine *v8; QPointer parent; - QV4::Value valuemap; + QV4::SafeValue valuemap; QV4::SafeValue qmlGlobal; - QV4::Value m_statusChanged; + QV4::SafeValue m_statusChanged; protected: virtual void statusChanged(Status); virtual void setInitialState(QObject *); @@ -1385,7 +1385,7 @@ void QQmlComponent::incubateObject(QQmlV4Function *args) } // XXX used by QSGLoader -void QQmlComponentPrivate::initializeObjectWithInitialProperties(const QV4::ValueRef qmlGlobal, const QV4::Value &valuemap, QObject *toCreate) +void QQmlComponentPrivate::initializeObjectWithInitialProperties(const QV4::ValueRef qmlGlobal, const QV4::ValueRef valuemap, QObject *toCreate) { QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); QV8Engine *v8engine = ep->v8engine(); @@ -1395,7 +1395,7 @@ void QQmlComponentPrivate::initializeObjectWithInitialProperties(const QV4::Valu QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate)); Q_ASSERT(object->asObject()); - if (!valuemap.isUndefined()) { + if (!valuemap->isUndefined()) { QQmlComponentExtension *e = componentExtension(v8engine); QV4::ScopedObject qmlGlobalObj(scope, qmlGlobal); QV4::Scoped f(scope, QV4::Script::evaluate(QV8Engine::getV4(v8engine), @@ -1503,7 +1503,7 @@ void QmlIncubatorObject::setInitialState(QObject *o) QV4::Scoped f(scope, QV4::Script::evaluate(v4, QString::fromLatin1(INITIALPROPERTIES_SOURCE), qmlGlobal)); QV4::ScopedCallData callData(scope, 2); callData->thisObject = v4->globalObject; - callData->args[0] = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(v4, o)); + callData->args[0] = QV4::QObjectWrapper::wrap(v4, o); callData->args[1] = valuemap; f->call(callData); } @@ -1533,11 +1533,10 @@ void QmlIncubatorObject::statusChanged(Status s) QQmlData::get(object())->indestructible = false; } - QV4::Value callback = m_statusChanged; - - if (QV4::FunctionObject *f = callback.asFunctionObject()) { - QV4::ExecutionContext *ctx = f->engine()->current; - QV4::Scope scope(ctx); + QV4::Scope scope(QV8Engine::getV4(v8)); + QV4::ScopedFunctionObject f(scope, m_statusChanged); + if (f) { + QV4::ExecutionContext *ctx = scope.engine->current; try { QV4::ScopedCallData callData(scope, 1); callData->thisObject = this; diff --git a/src/qml/qml/qqmlcomponent_p.h b/src/qml/qml/qqmlcomponent_p.h index f2f81c8ab2..d9a2427cd5 100644 --- a/src/qml/qml/qqmlcomponent_p.h +++ b/src/qml/qml/qqmlcomponent_p.h @@ -91,7 +91,7 @@ public: QObject *beginCreate(QQmlContextData *); void completeCreate(); - void initializeObjectWithInitialProperties(const QV4::ValueRef qmlGlobal, const QV4::Value &valuemap, QObject *toCreate); + void initializeObjectWithInitialProperties(const QV4::ValueRef qmlGlobal, const QV4::ValueRef valuemap, QObject *toCreate); QQmlTypeData *typeData; virtual void typeDataReady(QQmlTypeData *); diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 15974b07fa..c867b6e126 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -105,23 +105,26 @@ QQmlContextData *QmlContextWrapper::callingContext(ExecutionEngine *v4) return !!c ? c->getContext() : 0; } -QQmlContextData *QmlContextWrapper::getContext(const Value &value) +QQmlContextData *QmlContextWrapper::getContext(const ValueRef value) { - QV4::ExecutionEngine *v4 = value.engine(); + QV4::ExecutionEngine *v4 = value->engine(); if (!v4) return 0; Scope scope(v4); - QV4::Scoped c(scope, value.as()); + QV4::Scoped c(scope, value); - return !!c ? c->getContext():0; + return c ? c->getContext() : 0; } -void QmlContextWrapper::takeContextOwnership(const Value &qmlglobal) +void QmlContextWrapper::takeContextOwnership(const ValueRef qmlglobal) { - Object *o = qmlglobal.asObject(); - QmlContextWrapper *c = o ? o->as() : 0; - assert(c); + QV4::ExecutionEngine *v4 = qmlglobal->engine(); + Q_ASSERT(v4); + + Scope scope(v4); + QV4::Scoped c(scope, qmlglobal); + Q_ASSERT(c); c->ownsContext = true; } diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index 6660e1ab29..86ad4e5616 100644 --- a/src/qml/qml/qqmlcontextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -74,11 +74,11 @@ struct Q_QML_EXPORT QmlContextWrapper : Object static ReturnedValue urlScope(QV8Engine *e, const QUrl &); static QQmlContextData *callingContext(ExecutionEngine *v4); - static void takeContextOwnership(const QV4::Value &qmlglobal); + static void takeContextOwnership(const ValueRef qmlglobal); inline QObject *getScopeObject() const { return scopeObject; } inline QQmlContextData *getContext() const { return context; } - static QQmlContextData *getContext(const Value &value); + static QQmlContextData *getContext(const ValueRef value); void setReadOnly(bool b) { readOnly = b; } diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index 788d3e241c..938b14a15f 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -123,22 +123,26 @@ void QQmlJavaScriptExpression::resetNotifyOnValueChanged() } QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context, - const QV4::Value &function, bool *isUndefined) + const QV4::ValueRef function, bool *isUndefined) { - return evaluate(context, function, 0, 0, isUndefined); + QV4::ExecutionEngine *v4 = QV8Engine::getV4(context->engine); + QV4::Scope scope(v4); + QV4::ScopedCallData callData(scope, 0); + + return evaluate(context, function, callData, isUndefined); } QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context, - const QV4::Value &function, - int argc, QV4::Value *args, + const QV4::ValueRef function, + QV4::CallData *callData, bool *isUndefined) { Q_ASSERT(context && context->engine); - if (function.isUndefined()) { + if (function->isUndefined()) { if (isUndefined) *isUndefined = true; - return QV4::Primitive::undefinedValue().asReturnedValue(); + return QV4::Encode::undefined(); } QQmlEnginePrivate *ep = QQmlEnginePrivate::get(context->engine); @@ -165,7 +169,6 @@ QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context, QV4::ScopedValue result(scope, QV4::Primitive::undefinedValue()); QV4::ExecutionContext *ctx = v4->current; try { - QV4::ScopedCallData callData(scope, argc); callData->thisObject = ep->v8engine()->global(); if (scopeObject() && requiresThisObject()) { QV4::ScopedValue value(scope, QV4::QObjectWrapper::wrap(ctx->engine, scopeObject())); @@ -173,8 +176,7 @@ QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context, callData->thisObject = value; } - memcpy(callData->args, args, argc*sizeof(QV4::Value)); - result = function.asFunctionObject()->call(callData); + result = function->asFunctionObject()->call(callData); if (isUndefined) *isUndefined = result->isUndefined(); diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h index c13e191216..031cc2d2c1 100644 --- a/src/qml/qml/qqmljavascriptexpression_p.h +++ b/src/qml/qml/qqmljavascriptexpression_p.h @@ -110,11 +110,8 @@ public: QQmlJavaScriptExpression(VTable *vtable); - QV4::ReturnedValue evaluate(QQmlContextData *, const QV4::Value &function, - bool *isUndefined); - QV4::ReturnedValue evaluate(QQmlContextData *, const QV4::Value &function, - int argc, QV4::Value *args, - bool *isUndefined); + QV4::ReturnedValue evaluate(QQmlContextData *, const QV4::ValueRef function, bool *isUndefined); + QV4::ReturnedValue evaluate(QQmlContextData *, const QV4::ValueRef function, QV4::CallData *callData, bool *isUndefined); inline bool requiresThisObject() const; inline void setRequiresThisObject(bool v); diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp index 3746d58d77..523b7cc5de 100644 --- a/src/qml/qml/qqmllistwrapper.cpp +++ b/src/qml/qml/qqmllistwrapper.cpp @@ -158,7 +158,7 @@ Property *QmlListWrapper::advanceIterator(Managed *m, ObjectIterator *it, String *attrs = QV4::Attr_Data; *index = it->arrayIndex; ++it->arrayIndex; - it->tmpDynamicProperty.value = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(w->engine(), w->property.at(&w->property, *index))); + it->tmpDynamicProperty.value = QV4::QObjectWrapper::wrap(w->engine(), w->property.at(&w->property, *index)); return &it->tmpDynamicProperty; } return QV4::Object::advanceIterator(m, it, name, index, attrs); diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp index e79f1582d9..9c09960e93 100644 --- a/src/qml/qml/qqmllocale.cpp +++ b/src/qml/qml/qqmllocale.cpp @@ -116,9 +116,9 @@ DEFINE_MANAGED_VTABLE(QQmlLocaleData); if (!r) \ V4THROW_ERROR("Not a valid Locale object") -static bool isLocaleObject(const QV4::Value &val) +static bool isLocaleObject(const QV4::ValueRef val) { - return val.as(); + return val->as(); } //-------------- diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 3ea40bd24c..65fc2a40d5 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -586,7 +586,7 @@ void QmlObjectCreator::setPropertyValue(QQmlPropertyData *property, const QV4::C QString stringValue = binding->valueAsString(&qmlUnit->header); if (property->isVarProperty()) { QV4::ScopedString s(scope, v4->newString(stringValue)); - _vmeMetaObject->setVMEProperty(property->coreIndex, s.asValue()); + _vmeMetaObject->setVMEProperty(property->coreIndex, s); } else { QVariant value = QQmlStringConverters::variantFromString(stringValue); argv[0] = &value; diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index a0fd98483b..7723404831 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -1537,7 +1537,7 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object, QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(object); Q_ASSERT(vmemo); - vmemo->setVMEProperty(core.coreIndex, *result); + vmemo->setVMEProperty(core.coreIndex, result); } else if (isUndefined && core.isResettable()) { void *args[] = { 0 }; QMetaObject::metacall(object, QMetaObject::ResetProperty, core.coreIndex, args); diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp index 512b9b4674..f256f3a1ce 100644 --- a/src/qml/qml/qqmlvme.cpp +++ b/src/qml/qml/qqmlvme.cpp @@ -296,12 +296,12 @@ static QVariant variantFromString(const QString &string) #define QML_STORE_VAR(name, value) \ QML_BEGIN_INSTR(name) \ - QV4::Value v4value = value; \ + QV4::ValueRef valueref = value; \ QObject *target = objects.top(); \ CLEAN_PROPERTY(target, instr.propertyIndex); \ QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(target); \ Q_ASSERT(vmemo); \ - vmemo->setVMEProperty(instr.propertyIndex, v4value); \ + vmemo->setVMEProperty(instr.propertyIndex, valueref); \ QML_END_INSTR(name) #define QML_STORE_POINTER(name, value) \ @@ -339,6 +339,9 @@ QObject *QQmlVME::run(QList *errors, QQmlEngine *engine = states.at(0).context->engine; QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); + QV4::ExecutionEngine *v4 = ep->v4engine(); + QV4::Scope valueScope(v4); + QV4::ScopedValue tmpValue(valueScope); int status = -1; // needed for dbus QQmlPropertyPrivate::WriteFlags flags = QQmlPropertyPrivate::BypassInterceptor | @@ -372,7 +375,7 @@ QObject *QQmlVME::run(QList *errors, // Store a created object in a property. These all pop from the objects stack. QML_STORE_VALUE(StoreObject, QObject *, objects.pop()); QML_STORE_VALUE(StoreVariantObject, QVariant, QVariant::fromValue(objects.pop())); - QML_STORE_VAR(StoreVarObject, QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(ep->v4engine(), objects.pop()))); + QML_STORE_VAR(StoreVarObject, (tmpValue = QV4::QObjectWrapper::wrap(ep->v4engine(), objects.pop()))); // Store a literal value in a corresponding property QML_STORE_VALUE(StoreFloat, float, instr.value); @@ -420,7 +423,7 @@ QObject *QQmlVME::run(QList *errors, // Store a literal value in a var property. // We deliberately do not use string converters here - QML_STORE_VAR(StoreVar, QV4::Value::fromReturnedValue(ep->v8engine()->fromVariant(PRIMITIVES.at(instr.value)))); + QML_STORE_VAR(StoreVar, (tmpValue = ep->v8engine()->fromVariant(PRIMITIVES.at(instr.value)))); QML_STORE_VAR(StoreVarInteger, QV4::Primitive::fromInt32(instr.value)); QML_STORE_VAR(StoreVarDouble, QV4::Primitive::fromDouble(instr.value)); QML_STORE_VAR(StoreVarBool, QV4::Primitive::fromBoolean(instr.value)); diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index e8960eb328..dfba6bb3b6 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -937,7 +937,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) callData->thisObject = ep->v8engine()->global(); for (int ii = 0; ii < data->parameterCount; ++ii) - callData->args[ii] = QV4::Value::fromReturnedValue(ep->v8engine()->fromVariant(*(QVariant *)a[ii + 1])); + callData->args[ii] = ep->v8engine()->fromVariant(*(QVariant *)a[ii + 1]); QV4::ScopedValue result(scope); QV4::ExecutionContext *ctx = function->engine()->current; @@ -1023,7 +1023,7 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) } } -void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) +void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::ValueRef value) { Q_ASSERT(id >= firstVarPropertyIndex); if (!ensureVarPropertiesAllocated()) @@ -1040,8 +1040,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) QObject *valueObject = 0; QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id); - QV4::ScopedValue v(scope, value); - QV4::ScopedObject o(scope, v); + QV4::ScopedObject o(scope, value); if (o) { // 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. @@ -1064,7 +1063,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) } // Write the value and emit change signal as appropriate. - vp->putIndexed(id - firstVarPropertyIndex, v); + vp->putIndexed(id - firstVarPropertyIndex, value); activate(object, methodOffset() + id, 0); } @@ -1202,7 +1201,7 @@ QV4::ReturnedValue QQmlVMEMetaObject::vmeProperty(int index) return readVarProperty(index - propOffset()); } -void QQmlVMEMetaObject::setVMEProperty(int index, const QV4::Value &v) +void QQmlVMEMetaObject::setVMEProperty(int index, const QV4::ValueRef v) { if (index < propOffset()) { Q_ASSERT(parentVMEMetaObject()); diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index c9babc0492..056139114c 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -168,7 +168,7 @@ public: quint16 vmeMethodLineNumber(int index); void setVmeMethod(int index, QV4::ValueRef function); QV4::ReturnedValue vmeProperty(int index); - void setVMEProperty(int index, const QV4::Value &v); + void setVMEProperty(int index, const QV4::ValueRef v); void connectAliasSignal(int index, bool indexInSignalRange); @@ -220,7 +220,7 @@ public: QV4::ReturnedValue method(int); QV4::ReturnedValue readVarProperty(int); - void writeVarProperty(int, const QV4::Value &); + void writeVarProperty(int, const QV4::ValueRef); QVariant readPropertyAsVariant(int); void writeProperty(int, const QVariant &); diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 84e99e6846..066a266991 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -100,12 +100,12 @@ static inline QQmlXMLHttpRequestData *xhrdata(QV8Engine *engine) return (QQmlXMLHttpRequestData *)engine->xmlHttpRequestData(); } -static ReturnedValue constructMeObject(const Value &thisObj, QV8Engine *e) +static ReturnedValue constructMeObject(const ValueRef thisObj, QV8Engine *e) { ExecutionEngine *v4 = QV8Engine::getV4(e); Scope scope(v4); Scoped meObj(scope, v4->newObject()); - meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ThisObject"))), ScopedValue(scope, thisObj)); + meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ThisObject"))), thisObj); ScopedValue v(scope, QmlContextWrapper::qmlScope(e, e->callingContext(), 0)); meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ActivationObject"))), v); return meObj.asReturnedValue(); @@ -1557,7 +1557,7 @@ void QQmlXMLHttpRequest::dispatchCallback(const ValueRef me) if (!activationObject) v4->current->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ActivationObject")); - QQmlContextData *callingContext = QmlContextWrapper::getContext(activationObject.asValue()); + QQmlContextData *callingContext = QmlContextWrapper::getContext(activationObject); if (callingContext) { QV4::ScopedCallData callData(scope, 0); callData->thisObject = activationObject.asValue(); diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 926b5c34d8..e92eb40037 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -1072,10 +1072,10 @@ use \l{QtQml2::Qt::createQmlObject()}{Qt.createQmlObject()}. */ ReturnedValue QtObject::method_createComponent(SimpleCallContext *ctx) { - const QString invalidArgs = QStringLiteral("Qt.createComponent(): Invalid arguments"); - const QString invalidParent = QStringLiteral("Qt.createComponent(): Invalid parent object"); if (ctx->callData->argc < 1 || ctx->callData->argc > 3) - ctx->throwError(invalidArgs); + ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments")); + + Scope scope(ctx); QV8Engine *v8engine = ctx->engine->v8Engine; QQmlEngine *engine = v8engine->engine(); @@ -1095,31 +1095,32 @@ ReturnedValue QtObject::method_createComponent(SimpleCallContext *ctx) int consumedCount = 1; if (ctx->callData->argc > 1) { - Value lastArg = ctx->callData->args[ctx->callData->argc-1]; + ScopedValue lastArg(scope, ctx->callData->args[ctx->callData->argc-1]); // The second argument could be the mode enum if (ctx->callData->args[1].isInteger()) { int mode = ctx->callData->args[1].integerValue(); if (mode != int(QQmlComponent::PreferSynchronous) && mode != int(QQmlComponent::Asynchronous)) - ctx->throwError(invalidArgs); + ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments")); compileMode = QQmlComponent::CompilationMode(mode); consumedCount += 1; } else { // The second argument could be the parent only if there are exactly two args - if ((ctx->callData->argc != 2) || !(lastArg.isObject() || lastArg.isNull())) - ctx->throwError(invalidArgs); + if ((ctx->callData->argc != 2) || !(lastArg->isObject() || lastArg->isNull())) + ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments")); } if (consumedCount < ctx->callData->argc) { - if (lastArg.isObject()) { - if (QV4::QObjectWrapper *qobjectWrapper = lastArg.as()) + if (lastArg->isObject()) { + Scoped qobjectWrapper(scope, lastArg); + if (qobjectWrapper) parentArg = qobjectWrapper->object(); if (!parentArg) - ctx->throwError(invalidParent); - } else if (lastArg.isNull()) { + ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid parent object")); + } else if (lastArg->isNull()) { parentArg = 0; } else { - ctx->throwError(invalidParent); + ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid parent object")); } } } @@ -1365,11 +1366,10 @@ static QV4::ReturnedValue writeToConsole(ConsoleLogTypes logType, SimpleCallCont if (i != 0) result.append(QLatin1Char(' ')); - QV4::Value value = ctx->callData->args[i]; - if (value.asArrayObject()) - result.append(QStringLiteral("[") + value.toQStringNoThrow() + QStringLiteral("]")); + if (ctx->callData->args[i].asArrayObject()) + result.append(QStringLiteral("[") + ctx->callData->args[i].toQStringNoThrow() + QStringLiteral("]")); else - result.append(value.toQStringNoThrow()); + result.append(ctx->callData->args[i].toQStringNoThrow()); } if (printStack) { @@ -1836,19 +1836,21 @@ QV4::ReturnedValue GlobalExtensions::method_gc(SimpleCallContext *ctx) ReturnedValue GlobalExtensions::method_string_arg(SimpleCallContext *ctx) { - QString value = ctx->callData->thisObject.toQStringNoThrow(); if (ctx->callData->argc != 1) V4THROW_ERROR("String.arg(): Invalid arguments"); - QV4::Value arg = ctx->callData->args[0]; - if (arg.isInteger()) - return ctx->engine->newString(value.arg(arg.integerValue()))->asReturnedValue(); - else if (arg.isDouble()) - return ctx->engine->newString(value.arg(arg.doubleValue()))->asReturnedValue(); - else if (arg.isBoolean()) - return ctx->engine->newString(value.arg(arg.booleanValue()))->asReturnedValue(); + QString value = ctx->callData->thisObject.toQString(); + + QV4::Scope scope(ctx); + QV4::ScopedValue arg(scope, ctx->callData->args[0]); + if (arg->isInteger()) + return ctx->engine->newString(value.arg(arg->integerValue()))->asReturnedValue(); + else if (arg->isDouble()) + return ctx->engine->newString(value.arg(arg->doubleValue()))->asReturnedValue(); + else if (arg->isBoolean()) + return ctx->engine->newString(value.arg(arg->booleanValue()))->asReturnedValue(); - return ctx->engine->newString(value.arg(arg.toQStringNoThrow()))->asReturnedValue(); + return ctx->engine->newString(value.arg(arg->toQString()))->asReturnedValue(); } diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 20d81c2ac0..9211ffd484 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -205,7 +205,7 @@ static QV4::ReturnedValue arrayFromVariantList(QV8Engine *engine, const QVariant int len = list.count(); a->arrayReserve(len); for (int ii = 0; ii < len; ++ii) { - a->arrayData[ii].value = QV4::Value::fromReturnedValue(engine->fromVariant(list.at(ii))); + a->arrayData[ii].value = engine->fromVariant(list.at(ii)); a->arrayDataLen = ii + 1; } a->setArrayLengthUnchecked(len); @@ -319,7 +319,7 @@ QV4::ReturnedValue QV8Engine::fromVariant(const QVariant &variant) QV4::Scoped a(scope, m_v4Engine->newArrayObject()); a->arrayReserve(list.count()); for (int ii = 0; ii < list.count(); ++ii) { - a->arrayData[ii].value = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(m_v4Engine, list.at(ii))); + a->arrayData[ii].value = QV4::QObjectWrapper::wrap(m_v4Engine, list.at(ii)); a->arrayDataLen = ii + 1; } a->setArrayLengthUnchecked(list.count()); @@ -467,7 +467,7 @@ void QV8Engine::freezeObject(const QV4::ValueRef value) QV4::ScopedFunctionObject f(scope, m_freezeObject.value()); QV4::ScopedCallData callData(scope, 1); callData->args[0] = value; - callData->thisObject = QV4::Value::fromObject(m_v4Engine->globalObject); + callData->thisObject = m_v4Engine->globalObject; f->call(callData); } @@ -535,7 +535,7 @@ QV4::ReturnedValue QV8Engine::variantListToJS(const QVariantList &lst) QV4::Scoped a(scope, m_v4Engine->newArrayObject()); a->arrayReserve(lst.size()); for (int i = 0; i < lst.size(); i++) { - a->arrayData[i].value = QV4::Value::fromReturnedValue(variantToJS(lst.at(i))); + a->arrayData[i].value = variantToJS(lst.at(i)); a->arrayDataLen = i + 1; } a->setArrayLengthUnchecked(lst.size()); @@ -586,7 +586,7 @@ QV4::ReturnedValue QV8Engine::variantMapToJS(const QVariantMap &vmap) for (it = vmap.constBegin(); it != vmap.constEnd(); ++it) { s = m_v4Engine->newIdentifier(it.key()); QV4::Property *p = o->insertMember(s, QV4::Attr_Data); - p->value = QV4::Value::fromReturnedValue(variantToJS(it.value())); + p->value = variantToJS(it.value()); } return o.asReturnedValue(); } diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 8f56ba968e..32d6505eff 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -63,10 +63,10 @@ struct DelegateModelGroupFunction: QV4::FunctionObject { Q_MANAGED - QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg); + QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::ValueRef arg); uint flag; - DelegateModelGroupFunction(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg)) + DelegateModelGroupFunction(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::ValueRef arg)) : FunctionObject(scope, /*name*/0) , code(code) , flag(flag) @@ -105,8 +105,8 @@ public: QQmlDelegateModelEngineData(QV8Engine *engine); ~QQmlDelegateModelEngineData(); - QV4::Value array(QV8Engine *engine, const QVector &changes); - QV4::Value array(QV8Engine *engine, const QVector &changes); + QV4::ReturnedValue array(QV8Engine *engine, const QVector &changes); + QV4::ReturnedValue array(QV8Engine *engine, const QVector &changes); QV4::PersistentValue changeProto; }; @@ -1540,7 +1540,7 @@ QQmlDelegateModelAttached *QQmlDelegateModel::qmlAttachedProperties(QObject *obj return new QQmlDelegateModelAttached(obj); } -bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const QV4::Value &object, int groups) +bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const QV4::ValueRef object, int groups) { if (!m_context->isValid()) return false; @@ -1548,13 +1548,16 @@ bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const QQmlDelegateModelItem *cacheItem = m_adaptorModel.createItem(m_cacheMetaType, m_context->engine(), -1); if (!cacheItem) return false; - QV4::Object *o = object.asObject(); - if (!o) + QV4::ExecutionEngine *v4 = object->engine(); + if (!v4) return false; - QV4::Scope scope(o->engine()); + QV4::Scope scope(v4); + QV4::ScopedObject o(scope, object); + if (!o) + return false; - QV4::ObjectIterator it(o, QV4::ObjectIterator::EnumerableOnly|QV4::ObjectIterator::WithProtoChain); + QV4::ObjectIterator it(o.getPointer(), QV4::ObjectIterator::EnumerableOnly|QV4::ObjectIterator::WithProtoChain); QV4::ScopedValue propertyName(scope); while (1) { QV4::Value value; @@ -1677,21 +1680,27 @@ int QQmlDelegateModelItemMetaType::parseGroups(const QStringList &groups) const return groupFlags; } -int QQmlDelegateModelItemMetaType::parseGroups(const QV4::Value &groups) const +int QQmlDelegateModelItemMetaType::parseGroups(const QV4::ValueRef groups) const { int groupFlags = 0; - if (QV4::String *s = groups.asString()) { + QV4::Scope scope(QV8Engine::getV4(v8Engine)); + + QV4::ScopedString s(scope, groups); + if (s) { const QString groupName = s->toQString(); int index = groupNames.indexOf(groupName); if (index != -1) groupFlags |= 2 << index; - } else if (QV4::ArrayObject *array = groups.asArrayObject()) { - QV4::Scope scope(array->engine()); + return groupFlags; + } + + QV4::ScopedArrayObject array(scope, groups); + if (array) { QV4::ScopedValue v(scope); uint arrayLength = array->arrayLength(); for (uint i = 0; i < arrayLength; ++i) { v = array->getIndexed(i); - const QString groupName = v->toQStringNoThrow(); + const QString groupName = v->toQString(); int index = groupNames.indexOf(groupName); if (index != -1) groupFlags |= 2 << index; @@ -1748,19 +1757,19 @@ QV4::ReturnedValue QQmlDelegateModelItem::set_groups(QV4::SimpleCallContext *ctx return QV4::Encode::undefined(); } -QV4::ReturnedValue QQmlDelegateModelItem::get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &) +QV4::ReturnedValue QQmlDelegateModelItem::get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef) { return QV4::Encode(bool(thisItem->groups & (1 << flag))); } -QV4::ReturnedValue QQmlDelegateModelItem::set_member(QQmlDelegateModelItem *cacheItem, uint flag, const QV4::Value &arg) +QV4::ReturnedValue QQmlDelegateModelItem::set_member(QQmlDelegateModelItem *cacheItem, uint flag, const QV4::ValueRef arg) { if (!cacheItem->metaType->model) return QV4::Encode::undefined(); QQmlDelegateModelPrivate *model = QQmlDelegateModelPrivate::get(cacheItem->metaType->model); - bool member = arg.toBoolean(); + bool member = arg->toBoolean(); uint groupFlag = (1 << flag); if (member == ((cacheItem->groups & groupFlag) != 0)) return QV4::Encode::undefined(); @@ -1774,7 +1783,7 @@ QV4::ReturnedValue QQmlDelegateModelItem::set_member(QQmlDelegateModelItem *cach return QV4::Encode::undefined(); } -QV4::ReturnedValue QQmlDelegateModelItem::get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &) +QV4::ReturnedValue QQmlDelegateModelItem::get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef) { return QV4::Encode((int)thisItem->groupIndex(Compositor::Group(flag))); } @@ -2404,12 +2413,21 @@ QQmlV4Handle QQmlDelegateModelGroup::get(int index) return QQmlV4Handle(o); } -bool QQmlDelegateModelGroupPrivate::parseIndex(const QV4::Value &value, int *index, Compositor::Group *group) const +bool QQmlDelegateModelGroupPrivate::parseIndex(const QV4::ValueRef value, int *index, Compositor::Group *group) const { - if (value.isNumber()) { - *index = value.toInt32(); + if (value->isNumber()) { + *index = value->toInt32(); return true; - } else if (QQmlDelegateModelItemObject *object = value.as()) { + } + + QV4::ExecutionEngine *v4 = value->engine(); + if (!v4) + return false; + + QV4::Scope scope(v4); + QV4::Scoped object(scope, value); + + if (object) { QQmlDelegateModelItem * const cacheItem = object->item; if (QQmlDelegateModelPrivate *model = cacheItem->metaType->model ? QQmlDelegateModelPrivate::get(cacheItem->metaType->model) @@ -3275,20 +3293,16 @@ QQmlDelegateModelEngineData::~QQmlDelegateModelEngineData() { } -QV4::Value QQmlDelegateModelEngineData::array( - QV8Engine *engine, const QVector &changes) +QV4::ReturnedValue QQmlDelegateModelEngineData::array(QV8Engine *engine, const QVector &changes) { QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine); - QV4::Object *array = new (v4->memoryManager) QQmlDelegateModelGroupRemoveArray(v4, changes); - return QV4::Value::fromObject(array); + return (new (v4->memoryManager) QQmlDelegateModelGroupRemoveArray(v4, changes))->asReturnedValue(); } -QV4::Value QQmlDelegateModelEngineData::array( - QV8Engine *engine, const QVector &changes) +QV4::ReturnedValue QQmlDelegateModelEngineData::array(QV8Engine *engine, const QVector &changes) { QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine); - QV4::Object *array = new (v4->memoryManager) QQmlDelegateModelGroupInsertArray(v4, changes); - return QV4::Value::fromObject(array); + return (new (v4->memoryManager) QQmlDelegateModelGroupInsertArray(v4, changes))->asReturnedValue(); } QT_END_NAMESPACE diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h index aa4e0c30e2..8205b5350f 100644 --- a/src/qml/types/qqmldelegatemodel_p_p.h +++ b/src/qml/types/qqmldelegatemodel_p_p.h @@ -78,7 +78,7 @@ public: void initializePrototype(); int parseGroups(const QStringList &groupNames) const; - int parseGroups(const QV4::Value &groupNames) const; + int parseGroups(const QV4::ValueRef groupNames) const; QPointer model; const int groupCount; @@ -136,9 +136,9 @@ public: static QV4::ReturnedValue get_model(QV4::SimpleCallContext *ctx); static QV4::ReturnedValue get_groups(QV4::SimpleCallContext *ctx); static QV4::ReturnedValue set_groups(QV4::SimpleCallContext *ctx); - static QV4::ReturnedValue get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &); - static QV4::ReturnedValue set_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &arg); - static QV4::ReturnedValue get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &arg); + static QV4::ReturnedValue get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef); + static QV4::ReturnedValue set_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef arg); + static QV4::ReturnedValue get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef arg); QV4::ExecutionEngine *v4; QQmlDelegateModelItemMetaType * const metaType; @@ -226,7 +226,7 @@ public: void initPackage(int index, QQuickPackage *package); void destroyingPackage(QQuickPackage *package); - bool parseIndex(const QV4::Value &value, int *index, Compositor::Group *group) const; + bool parseIndex(const QV4::ValueRef value, int *index, Compositor::Group *group) const; bool parseGroupArgs( QQmlV4Function *args, Compositor::Group *group, int *index, int *count, int *groups) const; @@ -289,7 +289,7 @@ public: void emitChanges(); void emitModelUpdated(const QQmlChangeSet &changeSet, bool reset); - bool insert(Compositor::insert_iterator &before, const QV4::Value &object, int groups); + bool insert(Compositor::insert_iterator &before, const QV4::ValueRef object, int groups); static void group_append(QQmlListProperty *property, QQmlDelegateModelGroup *group); static int group_count(QQmlListProperty *property); -- cgit v1.2.3