diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-27 09:45:55 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-30 08:05:46 +0200 |
commit | 0e36db9f1179d1bdf0710494e98ff7aee1a2d836 (patch) | |
tree | e9f00fe028ee24b4412e3bb8418a3381e81c772b /src/qml/qml | |
parent | 472c8e6bed0b18c4e853c905ace07a09c64c29d2 (diff) |
Remove most uses of Value from qml/qml
Change-Id: I409a8505a9e01f86d777bc694d24516d1c8f0c4d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlboundsignal.cpp | 22 | ||||
-rw-r--r-- | src/qml/qml/qqmlcomponent.cpp | 19 | ||||
-rw-r--r-- | src/qml/qml/qqmlcomponent_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper.cpp | 19 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper_p.h | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmljavascriptexpression.cpp | 20 | ||||
-rw-r--r-- | src/qml/qml/qqmljavascriptexpression_p.h | 7 | ||||
-rw-r--r-- | src/qml/qml/qqmllistwrapper.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmllocale.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlvme.cpp | 11 | ||||
-rw-r--r-- | src/qml/qml/qqmlvmemetaobject.cpp | 11 | ||||
-rw-r--r-- | src/qml/qml/qqmlvmemetaobject_p.h | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmlxmlhttprequest.cpp | 6 | ||||
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 52 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine.cpp | 10 |
17 files changed, 99 insertions, 98 deletions
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<const int*>(a[ii + 1])); + callData->args[ii] = QV4::Primitive::fromInt32(*reinterpret_cast<const int*>(a[ii + 1])); } else if (type == qMetaTypeId<QQmlV4Handle>()) { - args[ii] = QV4::Value::fromReturnedValue(*reinterpret_cast<QQmlV4Handle *>(a[ii + 1])); + callData->args[ii] = *reinterpret_cast<QQmlV4Handle *>(a[ii + 1]); } else if (ep->isQObject(type)) { if (!*reinterpret_cast<void* const *>(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<QObject* const *>(a[ii + 1]))); + callData->args[ii] = QV4::QObjectWrapper::wrap(ep->v4engine(), *reinterpret_cast<QObject* const *>(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<QObject> 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<QV4::FunctionObject> f(scope, QV4::Script::evaluate(QV8Engine::getV4(v8engine), @@ -1503,7 +1503,7 @@ void QmlIncubatorObject::setInitialState(QObject *o) QV4::Scoped<QV4::FunctionObject> 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<QmlContextWrapper> c(scope, value.as<QmlContextWrapper>()); + QV4::Scoped<QmlContextWrapper> 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<QmlContextWrapper>() : 0; - assert(c); + QV4::ExecutionEngine *v4 = qmlglobal->engine(); + Q_ASSERT(v4); + + Scope scope(v4); + QV4::Scoped<QmlContextWrapper> 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<QQmlLocaleData>(); + return val->as<QQmlLocaleData>(); } //-------------- 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<QQmlError> *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<QQmlError> *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<QQmlError> *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<Object> 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<QV4::QObjectWrapper>()) + if (lastArg->isObject()) { + Scoped<QObjectWrapper> 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<QV4::ArrayObject> 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<QV4::ArrayObject> 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(); } |