diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-12 22:37:41 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-18 13:13:55 +0200 |
commit | a2d115fbaffee282a1d32ed92c6700e6c3dd811b (patch) | |
tree | 7694e53751edd605d99d1d8eb19c9cd5d6d8188a /src/qml/qml | |
parent | 399f88f6b75bb842be8e9d3671ace5114e115542 (diff) |
Convert most remaining return values from Value to ReturnedValue
Change-Id: If8b0c3b91be50678693868c10fefc3678008834d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml')
24 files changed, 228 insertions, 223 deletions
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index eff17ddd9a..a5e281dc56 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -244,12 +244,13 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags) } else { QQmlEnginePrivate *ep = QQmlEnginePrivate::get(context()->engine); + QV4::Scope scope(ep->v4engine()); + ep->referenceScarceResources(); bool isUndefined = false; - QV4::Value result = - QQmlJavaScriptExpression::evaluate(context(), v4function.value(), &isUndefined); + QV4::ScopedValue result(scope, QQmlJavaScriptExpression::evaluate(context(), v4function.value(), &isUndefined)); trace.event("writing binding result"); @@ -285,12 +286,12 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags) QVariant QQmlBinding::evaluate() { QQmlEnginePrivate *ep = QQmlEnginePrivate::get(context()->engine); + QV4::Scope scope(ep->v4engine()); ep->referenceScarceResources(); bool isUndefined = false; - QV4::Value result = - QQmlJavaScriptExpression::evaluate(context(), v4function.value(), &isUndefined); + QV4::ScopedValue result(scope, QQmlJavaScriptExpression::evaluate(context(), v4function.value(), &isUndefined)); ep->dereferenceScarceResources(); diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index b7cb52bdbc..deb93b990d 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -194,7 +194,7 @@ void QQmlBoundSignalExpression::evaluate(void **a) // 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] = engine->fromVariant(*((QVariant *)a[ii + 1])); + args[ii] = QV4::Value::fromReturnedValue(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::Value::fromInt32(*reinterpret_cast<const int*>(a[ii + 1])); @@ -204,9 +204,9 @@ void QQmlBoundSignalExpression::evaluate(void **a) if (!*reinterpret_cast<void* const *>(a[ii + 1])) args[ii] = QV4::Value::nullValue(); else - args[ii] = QV4::QObjectWrapper::wrap(ep->v4engine(), *reinterpret_cast<QObject* const *>(a[ii + 1])); + args[ii] = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(ep->v4engine(), *reinterpret_cast<QObject* const *>(a[ii + 1]))); } else { - args[ii] = engine->fromVariant(QVariant(type, a[ii + 1])); + args[ii] = QV4::Value::fromReturnedValue(engine->fromVariant(QVariant(type, a[ii + 1]))); } } diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index eb5e314ead..f822728f08 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -1221,8 +1221,8 @@ void QQmlComponent::createObject(QQmlV4Function *args) QQmlComponent_setQmlParent(rv, parent); - QV4::Value object = QV4::QObjectWrapper::wrap(v4engine, rv); - Q_ASSERT(object.asObject()); + QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, rv)); + Q_ASSERT(object->isObject()); if (!valuemap.isEmpty()) { QQmlComponentExtension *e = componentExtension(v8engine); @@ -1369,8 +1369,8 @@ void QQmlComponentPrivate::initializeObjectWithInitialProperties(const QV4::Valu QV4::ExecutionEngine *v4engine = QV8Engine::getV4(v8engine); QV4::Scope scope(v4engine); - QV4::Value object = QV4::QObjectWrapper::wrap(v4engine, toCreate); - Q_ASSERT(object.asObject()); + QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate)); + Q_ASSERT(object->asObject()); if (!valuemap.isEmpty()) { QQmlComponentExtension *e = componentExtension(v8engine); @@ -1412,7 +1412,7 @@ QV4::ReturnedValue QmlIncubatorObject::method_get_object(QV4::SimpleCallContext if (!o) ctx->throwTypeError(); - return QV4::QObjectWrapper::wrap(ctx->engine, o->object()).asReturnedValue(); + return QV4::QObjectWrapper::wrap(ctx->engine, o->object()); } QV4::ReturnedValue QmlIncubatorObject::method_forceCompletion(QV4::SimpleCallContext *ctx) @@ -1478,7 +1478,7 @@ void QmlIncubatorObject::setInitialState(QObject *o) QV4::Scoped<QV4::FunctionObject> f(scope, QV4::Script::evaluate(v4, QString::fromLatin1(INITIALPROPERTIES_SOURCE), qmlGlobal.asObject())); QV4::ScopedCallData callData(scope, 2); callData->thisObject = QV4::Value::fromObject(v4->globalObject); - callData->args[0] = QV4::QObjectWrapper::wrap(v4, o); + callData->args[0] = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(v4, o)); callData->args[1] = valuemap; f->call(callData); } diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index f84f288770..50d1f32c10 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -73,15 +73,15 @@ QmlContextWrapper::~QmlContextWrapper() context->destroy(); } -QV4::Value QmlContextWrapper::qmlScope(QV8Engine *v8, QQmlContextData *ctxt, QObject *scope) +ReturnedValue QmlContextWrapper::qmlScope(QV8Engine *v8, QQmlContextData *ctxt, QObject *scope) { ExecutionEngine *v4 = QV8Engine::getV4(v8); QmlContextWrapper *w = new (v4->memoryManager) QmlContextWrapper(v8, ctxt, scope); - return Value::fromObject(w); + return Value::fromObject(w).asReturnedValue(); } -QV4::Value QmlContextWrapper::urlScope(QV8Engine *v8, const QUrl &url) +ReturnedValue QmlContextWrapper::urlScope(QV8Engine *v8, const QUrl &url) { ExecutionEngine *v4 = QV8Engine::getV4(v8); @@ -92,7 +92,7 @@ QV4::Value QmlContextWrapper::urlScope(QV8Engine *v8, const QUrl &url) QmlContextWrapper *w = new (v4->memoryManager) QmlContextWrapper(v8, context, 0); w->isNullWrapper = true; - return Value::fromObject(w); + return Value::fromObject(w).asReturnedValue(); } QQmlContextData *QmlContextWrapper::callingContext(ExecutionEngine *v4) @@ -192,9 +192,9 @@ ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty else return QV4::Value::undefinedValue().asReturnedValue(); } else if (r.type) { - return QmlTypeWrapper::create(engine, scopeObject, r.type).asReturnedValue(); + return QmlTypeWrapper::create(engine, scopeObject, r.type); } else if (r.importNamespace) { - return QmlTypeWrapper::create(engine, scopeObject, context->imports, r.importNamespace).asReturnedValue(); + return QmlTypeWrapper::create(engine, scopeObject, context->imports, r.importNamespace); } Q_ASSERT(!"Unreachable"); } @@ -216,7 +216,7 @@ ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty ep->captureProperty(&context->idValues[propertyIdx].bindings); if (hasProperty) *hasProperty = true; - return QV4::QObjectWrapper::wrap(v4, context->idValues[propertyIdx]).asReturnedValue(); + return QV4::QObjectWrapper::wrap(v4, context->idValues[propertyIdx]); } else { QQmlContextPrivate *cp = context->asQQmlContextPrivate(); @@ -231,9 +231,9 @@ ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty QQmlListProperty<QObject> prop(context->asQQmlContext(), (void*) qintptr(propertyIdx), QQmlContextPrivate::context_count, QQmlContextPrivate::context_at); - return QmlListWrapper::create(engine, prop, qMetaTypeId<QQmlListProperty<QObject> >()).asReturnedValue(); + return QmlListWrapper::create(engine, prop, qMetaTypeId<QQmlListProperty<QObject> >()); } else { - return engine->fromVariant(cp->propertyValues.at(propertyIdx)).asReturnedValue(); + return engine->fromVariant(cp->propertyValues.at(propertyIdx)); } } } @@ -242,7 +242,8 @@ ReturnedValue QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty // Search scope object if (scopeObject) { bool hasProp = false; - QV4::Value result = QV4::QObjectWrapper::getQmlProperty(v4->current, context, scopeObject, name, QV4::QObjectWrapper::CheckRevision, &hasProp); + QV4::ScopedValue result(scope, QV4::QObjectWrapper::getQmlProperty(v4->current, context, scopeObject, + name, QV4::QObjectWrapper::CheckRevision, &hasProp)); if (hasProp) { if (hasProperty) *hasProperty = true; diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index 0ed933014b..c5f7f251c1 100644 --- a/src/qml/qml/qqmlcontextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -70,8 +70,8 @@ struct Q_QML_EXPORT QmlContextWrapper : Object QmlContextWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext = false); ~QmlContextWrapper(); - static QV4::Value qmlScope(QV8Engine *e, QQmlContextData *ctxt, QObject *scope); - static QV4::Value urlScope(QV8Engine *e, const QUrl &); + static ReturnedValue qmlScope(QV8Engine *e, QQmlContextData *ctxt, QObject *scope); + static ReturnedValue urlScope(QV8Engine *e, const QUrl &); static QQmlContextData *callingContext(ExecutionEngine *v4); static void takeContextOwnership(const QV4::Value &qmlglobal); diff --git a/src/qml/qml/qqmlexpression.cpp b/src/qml/qml/qqmlexpression.cpp index ddebf02c6c..76214c17a4 100644 --- a/src/qml/qml/qqmlexpression.cpp +++ b/src/qml/qml/qqmlexpression.cpp @@ -260,7 +260,7 @@ void QQmlExpression::setExpression(const QString &expression) } // Must be called with a valid handle scope -QV4::Value QQmlExpressionPrivate::v4value(bool *isUndefined) +QV4::ReturnedValue QQmlExpressionPrivate::v4value(bool *isUndefined) { if (!expressionFunctionValid) { function = qmlBinding(context(), scopeObject(), expression, url, line, &qmlscope); @@ -285,7 +285,8 @@ QVariant QQmlExpressionPrivate::value(bool *isUndefined) ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation. { - QV4::Value result = v4value(isUndefined); + QV4::Scope scope(QV8Engine::getV4(ep->v8engine())); + QV4::ScopedValue result(scope, v4value(isUndefined)); rv = ep->v8engine()->toVariant(result, -1); } diff --git a/src/qml/qml/qqmlexpression_p.h b/src/qml/qml/qqmlexpression_p.h index 9cc5a326f8..e84d193837 100644 --- a/src/qml/qml/qqmlexpression_p.h +++ b/src/qml/qml/qqmlexpression_p.h @@ -81,7 +81,7 @@ public: QVariant value(bool *isUndefined = 0); - QV4::Value v4value(bool *isUndefined = 0); + QV4::ReturnedValue v4value(bool *isUndefined = 0); static inline QQmlExpressionPrivate *get(QQmlExpression *expr); static inline QQmlExpression *get(QQmlExpressionPrivate *expr); diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index 322100f47e..d16d421ed2 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -122,15 +122,13 @@ void QQmlJavaScriptExpression::resetNotifyOnValueChanged() clearGuards(); } -QV4::Value -QQmlJavaScriptExpression::evaluate(QQmlContextData *context, +QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context, const QV4::Value &function, bool *isUndefined) { return evaluate(context, function, 0, 0, isUndefined); } -QV4::Value -QQmlJavaScriptExpression::evaluate(QQmlContextData *context, +QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context, const QV4::Value &function, int argc, QV4::Value *args, bool *isUndefined) @@ -140,7 +138,7 @@ QQmlJavaScriptExpression::evaluate(QQmlContextData *context, if (function.isEmpty() || function.isUndefined()) { if (isUndefined) *isUndefined = true; - return QV4::Value::emptyValue(); + return QV4::Value::emptyValue().asReturnedValue(); } QQmlEnginePrivate *ep = QQmlEnginePrivate::get(context->engine); @@ -167,15 +165,14 @@ QQmlJavaScriptExpression::evaluate(QQmlContextData *context, QV4::ScopedValue result(scope, QV4::Value::undefinedValue()); QV4::ExecutionContext *ctx = v4->current; try { - QV4::Value This = ep->v8engine()->global(); + QV4::ScopedCallData callData(scope, argc); + callData->thisObject = ep->v8engine()->global(); if (scopeObject() && requiresThisObject()) { - QV4::Value value = QV4::QObjectWrapper::wrap(ctx->engine, scopeObject()); - if (value.isObject()) - This = value; + QV4::ScopedValue value(scope, QV4::QObjectWrapper::wrap(ctx->engine, scopeObject())); + if (value->isObject()) + callData->thisObject = value; } - QV4::ScopedCallData callData(scope, argc); - callData->thisObject = This; memcpy(callData->args, args, argc*sizeof(QV4::Value)); result = function.asFunctionObject()->call(callData); @@ -211,7 +208,7 @@ QQmlJavaScriptExpression::evaluate(QQmlContextData *context, ep->propertyCapture = lastPropertyCapture; - return result; + return result.asReturnedValue(); } void QQmlJavaScriptExpression::GuardCapture::captureProperty(QQmlNotifier *n) @@ -360,7 +357,7 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scopeObje return result.asReturnedValue(); } -QV4::PersistentValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt, QObject *scope, +QV4::PersistentValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt, QObject *qmlScope, const QString &code, const QString &filename, quint16 line, QV4::PersistentValue *qmlscope) { @@ -369,10 +366,11 @@ QV4::PersistentValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt, QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); QV4::ExecutionContext *ctx = v4->current; + QV4::Scope scope(v4); - QV4::Value scopeObject = QV4::QmlContextWrapper::qmlScope(ep->v8engine(), ctxt, scope); - QV4::Script script(v4, scopeObject.asObject(), code, filename, line); - QV4::Value result; + QV4::ScopedValue qmlScopeObject(scope, QV4::QmlContextWrapper::qmlScope(ep->v8engine(), ctxt, qmlScope)); + QV4::Script script(v4, qmlScopeObject->asObject(), code, filename, line); + QV4::ScopedValue result(scope); try { script.parse(); result = script.qmlBinding(); @@ -386,13 +384,13 @@ QV4::PersistentValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt, error.setLine(line); if (error.url().isEmpty()) error.setUrl(QUrl::fromLocalFile(filename)); - error.setObject(scope); + error.setObject(qmlScope); ep->warning(error); return QV4::PersistentValue(); } if (qmlscope) - *qmlscope = scopeObject; - return result; + *qmlscope = qmlScopeObject; + return result.asReturnedValue(); } diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h index ef36a2f91a..f08b3af6cf 100644 --- a/src/qml/qml/qqmljavascriptexpression_p.h +++ b/src/qml/qml/qqmljavascriptexpression_p.h @@ -110,9 +110,9 @@ public: QQmlJavaScriptExpression(VTable *vtable); - QV4::Value evaluate(QQmlContextData *, const QV4::Value &function, + QV4::ReturnedValue evaluate(QQmlContextData *, const QV4::Value &function, bool *isUndefined); - QV4::Value evaluate(QQmlContextData *, const QV4::Value &function, + QV4::ReturnedValue evaluate(QQmlContextData *, const QV4::Value &function, int argc, QV4::Value *args, bool *isUndefined); diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp index e8f01bbc08..23aca851a6 100644 --- a/src/qml/qml/qqmllistwrapper.cpp +++ b/src/qml/qml/qqmllistwrapper.cpp @@ -63,10 +63,10 @@ QmlListWrapper::~QmlListWrapper() { } -Value QmlListWrapper::create(QV8Engine *v8, QObject *object, int propId, int propType) +ReturnedValue QmlListWrapper::create(QV8Engine *v8, QObject *object, int propId, int propType) { if (!object || propId == -1) - return Value::nullValue(); + return Encode::null(); ExecutionEngine *v4 = QV8Engine::getV4(v8); @@ -75,10 +75,10 @@ Value QmlListWrapper::create(QV8Engine *v8, QObject *object, int propId, int pro r->propertyType = propType; void *args[] = { &r->property, 0 }; QMetaObject::metacall(object, QMetaObject::ReadProperty, propId, args); - return Value::fromObject(r); + return Value::fromObject(r).asReturnedValue(); } -Value QmlListWrapper::create(QV8Engine *v8, const QQmlListProperty<QObject> &prop, int propType) +ReturnedValue QmlListWrapper::create(QV8Engine *v8, const QQmlListProperty<QObject> &prop, int propType) { ExecutionEngine *v4 = QV8Engine::getV4(v8); @@ -86,7 +86,7 @@ Value QmlListWrapper::create(QV8Engine *v8, const QQmlListProperty<QObject> &pro r->object = prop.object; r->property = prop; r->propertyType = propType; - return Value::fromObject(r); + return Value::fromObject(r).asReturnedValue(); } QVariant QmlListWrapper::toVariant() const @@ -126,7 +126,7 @@ ReturnedValue QmlListWrapper::getIndexed(Managed *m, uint index, bool *hasProper quint32 count = w->property.count ? w->property.count(&w->property) : 0; if (index < count && w->property.at) - return QV4::QObjectWrapper::wrap(e, w->property.at(&w->property, index)).asReturnedValue(); + return QV4::QObjectWrapper::wrap(e, w->property.at(&w->property, index)); return Value::undefinedValue().asReturnedValue(); } @@ -156,7 +156,7 @@ Property *QmlListWrapper::advanceIterator(Managed *m, ObjectIterator *it, String *attrs = QV4::Attr_Data; *index = it->arrayIndex; ++it->arrayIndex; - it->tmpDynamicProperty.value = QV4::QObjectWrapper::wrap(w->engine(), w->property.at(&w->property, *index)); + it->tmpDynamicProperty.value = QV4::Value::fromReturnedValue(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/qqmllistwrapper_p.h b/src/qml/qml/qqmllistwrapper_p.h index 4778443d6b..0de028a35b 100644 --- a/src/qml/qml/qqmllistwrapper_p.h +++ b/src/qml/qml/qqmllistwrapper_p.h @@ -76,8 +76,8 @@ protected: public: - static Value create(QV8Engine *v8, QObject *object, int propId, int propType); - static Value create(QV8Engine *v8, const QQmlListProperty<QObject> &prop, int propType); + static ReturnedValue create(QV8Engine *v8, QObject *object, int propId, int propType); + static ReturnedValue create(QV8Engine *v8, const QQmlListProperty<QObject> &prop, int propType); QVariant toVariant() const; diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp index 27c8dff598..38ffc5386d 100644 --- a/src/qml/qml/qqmllocale.cpp +++ b/src/qml/qml/qqmllocale.cpp @@ -807,7 +807,7 @@ QQmlLocale::~QQmlLocale() { } -QV4::Value QQmlLocale::locale(QV8Engine *v8engine, const QString &locale) +QV4::ReturnedValue QQmlLocale::locale(QV8Engine *v8engine, const QString &locale) { QV8LocaleDataDeletable *d = localeV8Data(v8engine); QV4::ExecutionEngine *engine = QV8Engine::getV4(v8engine); @@ -815,7 +815,7 @@ QV4::Value QQmlLocale::locale(QV8Engine *v8engine, const QString &locale) if (!locale.isEmpty()) wrapper->locale = QLocale(locale); wrapper->setPrototype(d->prototype.value().asObject()); - return QV4::Value::fromObject(wrapper); + return QV4::Value::fromObject(wrapper).asReturnedValue(); } void QQmlLocale::registerStringLocaleCompare(QV4::ExecutionEngine *engine) diff --git a/src/qml/qml/qqmllocale_p.h b/src/qml/qml/qqmllocale_p.h index 5088693269..8075bd462f 100644 --- a/src/qml/qml/qqmllocale_p.h +++ b/src/qml/qml/qqmllocale_p.h @@ -118,7 +118,7 @@ public: Saturday = Qt::Saturday }; - static QV4::Value locale(QV8Engine *v8engine, const QString &lang); + static QV4::ReturnedValue locale(QV8Engine *v8engine, const QString &lang); static void registerStringLocaleCompare(QV4::ExecutionEngine *engine); diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 8f05a877ef..09ef732e2d 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -87,19 +87,19 @@ QVariant QmlTypeWrapper::toVariant() const // Returns a type wrapper for type t on o. This allows access of enums, and attached properties. -Value QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlType *t, TypeNameMode mode) +ReturnedValue QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlType *t, TypeNameMode mode) { Q_ASSERT(t); ExecutionEngine *v4 = QV8Engine::getV4(v8); QmlTypeWrapper *w = new (v4->memoryManager) QmlTypeWrapper(v8); w->mode = mode; w->object = o; w->type = t; - return Value::fromObject(w); + return Value::fromObject(w).asReturnedValue(); } // Returns a type wrapper for importNamespace (of t) on o. This allows nested resolution of a type in a // namespace. -Value QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlTypeNameCache *t, const void *importNamespace, TypeNameMode mode) +ReturnedValue QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlTypeNameCache *t, const void *importNamespace, TypeNameMode mode) { Q_ASSERT(t); Q_ASSERT(importNamespace); @@ -108,17 +108,20 @@ Value QmlTypeWrapper::create(QV8Engine *v8, QObject *o, QQmlTypeNameCache *t, co QmlTypeWrapper *w = new (v4->memoryManager) QmlTypeWrapper(v8); w->mode = mode; w->object = o; w->typeNamespace = t; w->importNamespace = importNamespace; t->addref(); - return Value::fromObject(w); + return Value::fromObject(w).asReturnedValue(); } ReturnedValue QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty) { - QmlTypeWrapper *w = m->as<QmlTypeWrapper>(); QV4::ExecutionEngine *v4 = m->engine(); + QV4::Scope scope(v4); + + QmlTypeWrapper *w = m->as<QmlTypeWrapper>(); if (!w) v4->current->throwTypeError(); + if (hasProperty) *hasProperty = true; @@ -155,12 +158,12 @@ ReturnedValue QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty) } // check for property. - return QV4::QObjectWrapper::getQmlProperty(v4->current, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty).asReturnedValue(); + return QV4::QObjectWrapper::getQmlProperty(v4->current, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty); } else if (!siinfo->scriptApi(e).isUndefined()) { QV4::ExecutionEngine *engine = QV8Engine::getV4(v8engine); // NOTE: if used in a binding, changes will not trigger re-evaluation since non-NOTIFYable. - QV4::Object *o = QJSValuePrivate::get(siinfo->scriptApi(e))->getValue(engine).asObject(); - if (o) + QV4::Scoped<Object> o(scope, QJSValuePrivate::get(siinfo->scriptApi(e))->getValue(engine)); + if (!!o) return o->get(name); } @@ -179,7 +182,7 @@ ReturnedValue QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty) } else if (w->object) { QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object); if (ao) - return QV4::QObjectWrapper::getQmlProperty(v4->current, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty).asReturnedValue(); + return QV4::QObjectWrapper::getQmlProperty(v4->current, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty); // Fall through to base implementation } @@ -196,16 +199,16 @@ ReturnedValue QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty) if (r.isValid()) { QQmlContextData *context = v8engine->callingContext(); if (r.type) { - return create(w->v8, object, r.type, w->mode).asReturnedValue(); + return create(w->v8, object, r.type, w->mode); } else if (r.scriptIndex != -1) { int index = r.scriptIndex; if (index < context->importedScripts.count()) return context->importedScripts.at(index).value().asReturnedValue(); } else if (r.importNamespace) { - return create(w->v8, object, context->imports, r.importNamespace).asReturnedValue(); + return create(w->v8, object, context->imports, r.importNamespace); } - return QV4::Value::undefinedValue().asReturnedValue(); + return QV4::Encode::undefined(); } diff --git a/src/qml/qml/qqmltypewrapper_p.h b/src/qml/qml/qqmltypewrapper_p.h index c545e1cc3b..acf6845736 100644 --- a/src/qml/qml/qqmltypewrapper_p.h +++ b/src/qml/qml/qqmltypewrapper_p.h @@ -78,8 +78,8 @@ public: QVariant toVariant() const; - static QV4::Value create(QV8Engine *, QObject *, QQmlType *, TypeNameMode = IncludeEnums); - static QV4::Value create(QV8Engine *, QObject *, QQmlTypeNameCache *, const void *, TypeNameMode = IncludeEnums); + static ReturnedValue create(QV8Engine *, QObject *, QQmlType *, TypeNameMode = IncludeEnums); + static ReturnedValue create(QV8Engine *, QObject *, QQmlTypeNameCache *, const void *, TypeNameMode = IncludeEnums); static ReturnedValue get(Managed *m, String *name, bool *hasProperty); diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index d9ee928858..88704d58b3 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -139,7 +139,7 @@ void QmlValueTypeWrapper::initProto(ExecutionEngine *v4) v4->qmlExtensions()->valueTypeWrapperPrototype = o; } -Value QmlValueTypeWrapper::create(QV8Engine *v8, QObject *object, int property, QQmlValueType *type) +ReturnedValue QmlValueTypeWrapper::create(QV8Engine *v8, QObject *object, int property, QQmlValueType *type) { ExecutionEngine *v4 = QV8Engine::getV4(v8); initProto(v4); @@ -147,10 +147,10 @@ Value QmlValueTypeWrapper::create(QV8Engine *v8, QObject *object, int property, QmlValueTypeReference *r = new (v4->memoryManager) QmlValueTypeReference(v8); r->setPrototype(v4->qmlExtensions()->valueTypeWrapperPrototype); r->type = type; r->object = object; r->property = property; - return Value::fromObject(r); + return Value::fromObject(r).asReturnedValue(); } -Value QmlValueTypeWrapper::create(QV8Engine *v8, const QVariant &value, QQmlValueType *type) +ReturnedValue QmlValueTypeWrapper::create(QV8Engine *v8, const QVariant &value, QQmlValueType *type) { ExecutionEngine *v4 = QV8Engine::getV4(v8); initProto(v4); @@ -158,7 +158,7 @@ Value QmlValueTypeWrapper::create(QV8Engine *v8, const QVariant &value, QQmlValu QmlValueTypeCopy *r = new (v4->memoryManager) QmlValueTypeCopy(v8); r->setPrototype(v4->qmlExtensions()->valueTypeWrapperPrototype); r->type = type; r->value = value; - return Value::fromObject(r); + return Value::fromObject(r).asReturnedValue(); } QVariant QmlValueTypeWrapper::toVariant() const @@ -301,7 +301,7 @@ ReturnedValue QmlValueTypeWrapper::get(Managed *m, String *name, bool *hasProper if (result->isFunction()) { // calling a Q_INVOKABLE function of a value type QQmlContextData *qmlContext = QV4::QmlContextWrapper::callingContext(v4); - return QV4::QObjectWrapper::getQmlProperty(v4->current, qmlContext, r->type, name, QV4::QObjectWrapper::IgnoreRevision).asReturnedValue(); + return QV4::QObjectWrapper::getQmlProperty(v4->current, qmlContext, r->type, name, QV4::QObjectWrapper::IgnoreRevision); } #define VALUE_TYPE_LOAD(metatype, cpptype, constructor) \ @@ -321,7 +321,7 @@ ReturnedValue QmlValueTypeWrapper::get(Managed *m, String *name, bool *hasProper QVariant v(result->propType, (void *)0); void *args[] = { v.data(), 0 }; r->type->qt_metacall(QMetaObject::ReadProperty, result->coreIndex, args); - return r->v8->fromVariant(v).asReturnedValue(); + return r->v8->fromVariant(v); #undef VALUE_TYPE_ACCESSOR } diff --git a/src/qml/qml/qqmlvaluetypewrapper_p.h b/src/qml/qml/qqmlvaluetypewrapper_p.h index 2483b8e26b..355000bb39 100644 --- a/src/qml/qml/qqmlvaluetypewrapper_p.h +++ b/src/qml/qml/qqmlvaluetypewrapper_p.h @@ -76,8 +76,8 @@ protected: public: - static Value create(QV8Engine *v8, QObject *, int, QQmlValueType *); - static Value create(QV8Engine *v8, const QVariant &, QQmlValueType *); + static ReturnedValue create(QV8Engine *v8, QObject *, int, QQmlValueType *); + static ReturnedValue create(QV8Engine *v8, const QVariant &, QQmlValueType *); QVariant toVariant() const; bool isEqual(const QVariant& value); diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp index e32193e6f6..1a6577d7ad 100644 --- a/src/qml/qml/qqmlvme.cpp +++ b/src/qml/qml/qqmlvme.cpp @@ -372,7 +372,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::QObjectWrapper::wrap(ep->v4engine(), objects.pop())); + QML_STORE_VAR(StoreVarObject, QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(ep->v4engine(), objects.pop()))); // Store a literal value in a corresponding property QML_STORE_VALUE(StoreFloat, float, instr.value); @@ -420,7 +420,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, ep->v8engine()->fromVariant(PRIMITIVES.at(instr.value))); + QML_STORE_VAR(StoreVar, QV4::Value::fromReturnedValue(ep->v8engine()->fromVariant(PRIMITIVES.at(instr.value)))); QML_STORE_VAR(StoreVarInteger, QV4::Value::fromInt32(instr.value)); QML_STORE_VAR(StoreVarDouble, QV4::Value::fromDouble(instr.value)); QML_STORE_VAR(StoreVarBool, QV4::Value::fromBoolean(instr.value)); @@ -1113,6 +1113,8 @@ QV4::PersistentValue QQmlVME::run(QQmlContextData *parentCtxt, QQmlScriptData *s Q_ASSERT(parentCtxt && parentCtxt->engine); QQmlEnginePrivate *ep = QQmlEnginePrivate::get(parentCtxt->engine); QV8Engine *v8engine = ep->v8engine(); + QV4::ExecutionEngine *v4 = QV8Engine::getV4(parentCtxt->engine); + QV4::Scope scope(v4); if (script->hasError()) { ep->warning(script->error()); @@ -1178,7 +1180,7 @@ QV4::PersistentValue QQmlVME::run(QQmlContextData *parentCtxt, QQmlScriptData *s return QV4::PersistentValue(); } - QV4::Value qmlglobal = QV4::QmlContextWrapper::qmlScope(v8engine, ctxt, 0); + QV4::ScopedValue qmlglobal(scope, QV4::QmlContextWrapper::qmlScope(v8engine, ctxt, 0)); QV4::QmlContextWrapper::takeContextOwnership(qmlglobal); QV4::ExecutionContext *ctx = QV8Engine::getV4(v8engine)->current; diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 360528ea7a..488b4a0adf 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,12 +929,11 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) QQmlVMEMetaData::MethodData *data = metaData->methodData() + id; - QV4::Scope scope(function->engine()); 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::ScopedValue result(scope); QV4::ExecutionContext *ctx = function->engine()->current; @@ -961,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) @@ -984,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 QV4::Value::fromReturnedValue(varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex)); - return QV4::Value::emptyValue(); + return varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex); + return QV4::Value::emptyValue().asReturnedValue(); } QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) @@ -1070,8 +1071,8 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) // 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. @@ -1150,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()); @@ -1178,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()); diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index 9824e0d54b..35592c4906 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -164,10 +164,10 @@ public: bool aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const; void registerInterceptor(int index, int valueIndex, QQmlPropertyValueInterceptor *interceptor); - QV4::Value vmeMethod(int index); + QV4::ReturnedValue vmeMethod(int index); quint16 vmeMethodLineNumber(int index); void setVmeMethod(int index, QV4::PersistentValue function); - QV4::Value vmeProperty(int index); + QV4::ReturnedValue vmeProperty(int index); void setVMEProperty(int index, const QV4::Value &v); void connectAliasSignal(int index, bool indexInSignalRange); @@ -217,9 +217,9 @@ public: QQmlPropertyValueInterceptor *interceptors; QV4::PersistentValue *v8methods; - QV4::Value method(int); + QV4::ReturnedValue method(int); - QV4::Value readVarProperty(int); + QV4::ReturnedValue readVarProperty(int); void writeVarProperty(int, const QV4::Value &); QVariant readPropertyAsVariant(int); void writeProperty(int, const QVariant &); diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 651a2703f3..b7447aee07 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -100,9 +100,11 @@ static inline QQmlXMLHttpRequestData *xhrdata(QV8Engine *engine) static Value constructMeObject(const Value &thisObj, QV8Engine *e) { ExecutionEngine *v4 = QV8Engine::getV4(e); + Scope scope(v4); Object *meObj = v4->newObject(); meObj->put(v4->newString(QStringLiteral("ThisObject")), thisObj); - meObj->put(v4->newString(QStringLiteral("ActivationObject")), QmlContextWrapper::qmlScope(e, e->callingContext(), 0)); + ScopedValue v(scope, QmlContextWrapper::qmlScope(e, e->callingContext(), 0)); + meObj->put(v4->newString(QStringLiteral("ActivationObject")), v); return Value::fromObject(meObj); } diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 59457df30c..2a75bf9834 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -202,7 +202,7 @@ ReturnedValue QtObject::method_rgba(QV4::SimpleCallContext *ctx) if (a < 0.0) a=0.0; if (a > 1.0) a=1.0; - return ctx->engine->v8Engine->fromVariant(QQml_colorProvider()->fromRgbF(r, g, b, a)).asReturnedValue(); + return ctx->engine->v8Engine->fromVariant(QQml_colorProvider()->fromRgbF(r, g, b, a)); } /*! @@ -231,7 +231,7 @@ ReturnedValue QtObject::method_hsla(QV4::SimpleCallContext *ctx) if (a < 0.0) a=0.0; if (a > 1.0) a=1.0; - return ctx->engine->v8Engine->fromVariant(QQml_colorProvider()->fromHslF(h, s, l, a)).asReturnedValue(); + return ctx->engine->v8Engine->fromVariant(QQml_colorProvider()->fromHslF(h, s, l, a)); } /*! @@ -292,7 +292,7 @@ ReturnedValue QtObject::method_rect(QV4::SimpleCallContext *ctx) double w = ctx->arguments[2].toNumber(); double h = ctx->arguments[3].toNumber(); - return ctx->engine->v8Engine->fromVariant(QVariant::fromValue(QRectF(x, y, w, h))).asReturnedValue(); + return ctx->engine->v8Engine->fromVariant(QVariant::fromValue(QRectF(x, y, w, h))); } /*! @@ -307,7 +307,7 @@ ReturnedValue QtObject::method_point(QV4::SimpleCallContext *ctx) double x = ctx->arguments[0].toNumber(); double y = ctx->arguments[1].toNumber(); - return ctx->engine->v8Engine->fromVariant(QVariant::fromValue(QPointF(x, y))).asReturnedValue(); + return ctx->engine->v8Engine->fromVariant(QVariant::fromValue(QPointF(x, y))); } /*! @@ -322,7 +322,7 @@ ReturnedValue QtObject::method_size(QV4::SimpleCallContext *ctx) double w = ctx->arguments[0].toNumber(); double h = ctx->arguments[1].toNumber(); - return ctx->engine->v8Engine->fromVariant(QVariant::fromValue(QSizeF(w, h))).asReturnedValue(); + return ctx->engine->v8Engine->fromVariant(QVariant::fromValue(QSizeF(w, h))); } /*! @@ -343,7 +343,7 @@ ReturnedValue QtObject::method_font(QV4::SimpleCallContext *ctx) QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QFont, QQmlV4Handle(ctx->arguments[0]), v8engine, &ok); if (!ok) V4THROW_ERROR("Qt.font(): Invalid argument: no valid font subproperties specified"); - return v8engine->fromVariant(v).asReturnedValue(); + return v8engine->fromVariant(v); } @@ -363,7 +363,7 @@ ReturnedValue QtObject::method_vector2d(QV4::SimpleCallContext *ctx) const void *params[] = { xy }; QV8Engine *v8engine = ctx->engine->v8Engine; - return v8engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector2D, 1, params)).asReturnedValue(); + return v8engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector2D, 1, params)); } /*! @@ -382,7 +382,7 @@ ReturnedValue QtObject::method_vector3d(QV4::SimpleCallContext *ctx) const void *params[] = { xyz }; QV8Engine *v8engine = ctx->engine->v8Engine; - return v8engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector3D, 1, params)).asReturnedValue(); + return v8engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector3D, 1, params)); } /*! @@ -402,7 +402,7 @@ ReturnedValue QtObject::method_vector4d(QV4::SimpleCallContext *ctx) const void *params[] = { xyzw }; QV8Engine *v8engine = ctx->engine->v8Engine; - return v8engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector4D, 1, params)).asReturnedValue(); + return v8engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector4D, 1, params)); } /*! @@ -422,7 +422,7 @@ ReturnedValue QtObject::method_quaternion(QV4::SimpleCallContext *ctx) const void *params[] = { sxyz }; QV8Engine *v8engine = ctx->engine->v8Engine; - return v8engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QQuaternion, 1, params)).asReturnedValue(); + return v8engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QQuaternion, 1, params)); } /*! @@ -441,7 +441,7 @@ ReturnedValue QtObject::method_matrix4x4(QV4::SimpleCallContext *ctx) QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QMatrix4x4, QQmlV4Handle(ctx->arguments[0]), v8engine, &ok); if (!ok) V4THROW_ERROR("Qt.matrix4x4(): Invalid argument: not a valid matrix4x4 values array"); - return v8engine->fromVariant(v).asReturnedValue(); + return v8engine->fromVariant(v); } if (ctx->argumentCount != 16) @@ -466,7 +466,7 @@ ReturnedValue QtObject::method_matrix4x4(QV4::SimpleCallContext *ctx) vals[15] = ctx->arguments[15].toNumber(); const void *params[] = { vals }; - return v8engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QMatrix4x4, 1, params)).asReturnedValue(); + return v8engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QMatrix4x4, 1, params)); } /*! @@ -504,7 +504,7 @@ ReturnedValue QtObject::method_lighter(QV4::SimpleCallContext *ctx) if (ctx->argumentCount == 2) factor = ctx->arguments[1].toNumber(); - return v8engine->fromVariant(QQml_colorProvider()->lighter(v, factor)).asReturnedValue(); + return v8engine->fromVariant(QQml_colorProvider()->lighter(v, factor)); } /*! @@ -543,7 +543,7 @@ ReturnedValue QtObject::method_darker(QV4::SimpleCallContext *ctx) if (ctx->argumentCount == 2) factor = ctx->arguments[1].toNumber(); - return v8engine->fromVariant(QQml_colorProvider()->darker(v, factor)).asReturnedValue(); + return v8engine->fromVariant(QQml_colorProvider()->darker(v, factor)); } /*! @@ -601,7 +601,7 @@ ReturnedValue QtObject::method_tint(QV4::SimpleCallContext *ctx) return QV4::Encode::null(); } - return v8engine->fromVariant(QQml_colorProvider()->tint(v1, v2)).asReturnedValue(); + return v8engine->fromVariant(QQml_colorProvider()->tint(v1, v2)); } /*! @@ -645,7 +645,7 @@ ReturnedValue QtObject::method_formatDate(QV4::SimpleCallContext *ctx) formattedDate = date.toString(enumFormat); } - return v8engine->fromVariant(QVariant::fromValue(formattedDate)).asReturnedValue(); + return v8engine->fromVariant(QVariant::fromValue(formattedDate)); } /*! @@ -694,7 +694,7 @@ ReturnedValue QtObject::method_formatTime(QV4::SimpleCallContext *ctx) formattedTime = time.toString(enumFormat); } - return v8engine->fromVariant(QVariant::fromValue(formattedTime)).asReturnedValue(); + return v8engine->fromVariant(QVariant::fromValue(formattedTime)); } /*! @@ -812,7 +812,7 @@ ReturnedValue QtObject::method_formatDateTime(QV4::SimpleCallContext *ctx) formattedDt = dt.toString(enumFormat); } - return v8engine->fromVariant(QVariant::fromValue(formattedDt)).asReturnedValue(); + return v8engine->fromVariant(QVariant::fromValue(formattedDt)); } /*! @@ -827,7 +827,7 @@ ReturnedValue QtObject::method_openUrlExternally(QV4::SimpleCallContext *ctx) QV8Engine *v8engine = ctx->engine->v8Engine; QUrl url(Value::fromReturnedValue(method_resolvedUrl(ctx)).toQStringNoThrow()); - return v8engine->fromVariant(QQml_guiProvider()->openUrlExternally(url)).asReturnedValue(); + return v8engine->fromVariant(QQml_guiProvider()->openUrlExternally(url)); } /*! @@ -863,7 +863,7 @@ ReturnedValue QtObject::method_fontFamilies(SimpleCallContext *ctx) V4THROW_ERROR("Qt.fontFamilies(): Invalid arguments"); QV8Engine *v8engine = ctx->engine->v8Engine; - return v8engine->fromVariant(QVariant(QQml_guiProvider()->fontFamilies())).asReturnedValue(); + return v8engine->fromVariant(QVariant(QQml_guiProvider()->fontFamilies())); } /*! @@ -1039,7 +1039,7 @@ ReturnedValue QtObject::method_createQmlObject(SimpleCallContext *ctx) Q_ASSERT(obj); - return QV4::QObjectWrapper::wrap(ctx->engine, obj).asReturnedValue(); + return QV4::QObjectWrapper::wrap(ctx->engine, obj); } /*! @@ -1133,7 +1133,7 @@ ReturnedValue QtObject::method_createComponent(SimpleCallContext *ctx) QQmlData::get(c, true)->explicitIndestructibleSet = false; QQmlData::get(c)->indestructible = false; - return QV4::QObjectWrapper::wrap(ctx->engine, c).asReturnedValue(); + return QV4::QObjectWrapper::wrap(ctx->engine, c); } /*! @@ -1168,7 +1168,7 @@ ReturnedValue QtObject::method_locale(SimpleCallContext *ctx) if (ctx->argumentCount == 1) code = ctx->arguments[0].toQStringNoThrow(); - return QQmlLocale::locale(v8engine, code).asReturnedValue(); + return QQmlLocale::locale(v8engine, code); } namespace { @@ -1276,7 +1276,7 @@ ReturnedValue QtObject::method_get_platform(SimpleCallContext *ctx) // Only allocate a platform object once qt->m_platform = new QQmlPlatform(ctx->engine->v8Engine->publicEngine()); - return QV4::QObjectWrapper::wrap(ctx->engine, qt->m_platform).asReturnedValue(); + return QV4::QObjectWrapper::wrap(ctx->engine, qt->m_platform); } ReturnedValue QtObject::method_get_application(SimpleCallContext *ctx) @@ -1293,7 +1293,7 @@ ReturnedValue QtObject::method_get_application(SimpleCallContext *ctx) // Only allocate an application object once qt->m_application = QQml_guiProvider()->application(ctx->engine->v8Engine->publicEngine()); - return QV4::QObjectWrapper::wrap(ctx->engine, qt->m_application).asReturnedValue(); + return QV4::QObjectWrapper::wrap(ctx->engine, qt->m_application); } #ifndef QT_NO_IM @@ -1301,7 +1301,7 @@ ReturnedValue QtObject::method_get_inputMethod(SimpleCallContext *ctx) { QObject *o = QQml_guiProvider()->inputMethod(); QQmlEngine::setObjectOwnership(o, QQmlEngine::CppOwnership); - return QV4::QObjectWrapper::wrap(ctx->engine, o).asReturnedValue(); + return QV4::QObjectWrapper::wrap(ctx->engine, o); } #endif diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index c377608341..63ab33a457 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -181,7 +181,7 @@ QVariant QV8Engine::toVariant(const QV4::Value &value, int typeHint) return toBasicVariant(value); } -static QV4::Value arrayFromStringList(QV8Engine *engine, const QStringList &list) +static QV4::ReturnedValue arrayFromStringList(QV8Engine *engine, const QStringList &list) { QV4::ExecutionEngine *e = QV8Engine::getV4(engine); QV4::ArrayObject *a = e->newArrayObject(); @@ -191,10 +191,10 @@ static QV4::Value arrayFromStringList(QV8Engine *engine, const QStringList &list for (int ii = 0; ii < len; ++ii) a->arrayData[ii].value = QV4::Value::fromString(e->newString(list.at(ii))); a->setArrayLengthUnchecked(len); - return QV4::Value::fromObject(a); + return QV4::Value::fromObject(a).asReturnedValue(); } -static QV4::Value arrayFromVariantList(QV8Engine *engine, const QVariantList &list) +static QV4::ReturnedValue arrayFromVariantList(QV8Engine *engine, const QVariantList &list) { QV4::ExecutionEngine *e = QV8Engine::getV4(engine); QV4::ArrayObject *a = e->newArrayObject(); @@ -202,23 +202,23 @@ static QV4::Value arrayFromVariantList(QV8Engine *engine, const QVariantList &li a->arrayReserve(len); a->arrayDataLen = len; for (int ii = 0; ii < len; ++ii) - a->arrayData[ii].value = engine->fromVariant(list.at(ii)); + a->arrayData[ii].value = QV4::Value::fromReturnedValue(engine->fromVariant(list.at(ii))); a->setArrayLengthUnchecked(len); - return QV4::Value::fromObject(a); + return QV4::Value::fromObject(a).asReturnedValue(); } -static QV4::Value objectFromVariantMap(QV8Engine *engine, const QVariantMap &map) +static QV4::ReturnedValue objectFromVariantMap(QV8Engine *engine, const QVariantMap &map) { QV4::ExecutionEngine *e = QV8Engine::getV4(engine); QV4::Object *o = e->newObject(); for (QVariantMap::ConstIterator iter = map.begin(); iter != map.end(); ++iter) - o->put(e->newString(iter.key()), engine->fromVariant(iter.value())); - return QV4::Value::fromObject(o); + o->put(e->newString(iter.key()), QV4::Value::fromReturnedValue(engine->fromVariant(iter.value()))); + return QV4::Value::fromObject(o).asReturnedValue(); } Q_CORE_EXPORT QString qt_regexp_toCanonical(const QString &, QRegExp::PatternSyntax); -QV4::Value QV8Engine::fromVariant(const QVariant &variant) +QV4::ReturnedValue QV8Engine::fromVariant(const QVariant &variant) { int type = variant.userType(); const void *ptr = variant.constData(); @@ -227,49 +227,50 @@ QV4::Value QV8Engine::fromVariant(const QVariant &variant) switch (QMetaType::Type(type)) { case QMetaType::UnknownType: case QMetaType::Void: - return QV4::Value::undefinedValue(); + return QV4::Encode::undefined(); case QMetaType::Bool: - return QV4::Value::fromBoolean(*reinterpret_cast<const bool*>(ptr)); + return QV4::Encode(*reinterpret_cast<const bool*>(ptr)); case QMetaType::Int: - return QV4::Value::fromInt32(*reinterpret_cast<const int*>(ptr)); + return QV4::Encode(*reinterpret_cast<const int*>(ptr)); case QMetaType::UInt: - return QV4::Value::fromUInt32(*reinterpret_cast<const uint*>(ptr)); + return QV4::Encode(*reinterpret_cast<const uint*>(ptr)); case QMetaType::LongLong: - return QV4::Value::fromDouble(*reinterpret_cast<const qlonglong*>(ptr)); + return QV4::Encode((double)*reinterpret_cast<const qlonglong*>(ptr)); case QMetaType::ULongLong: - return QV4::Value::fromDouble(*reinterpret_cast<const qulonglong*>(ptr)); + return QV4::Encode((double)*reinterpret_cast<const qulonglong*>(ptr)); case QMetaType::Double: - return QV4::Value::fromDouble(*reinterpret_cast<const double*>(ptr)); + return QV4::Encode(*reinterpret_cast<const double*>(ptr)); case QMetaType::QString: - return QV4::Value::fromString(m_v4Engine->current, *reinterpret_cast<const QString*>(ptr)); + return QV4::Value::fromString(m_v4Engine->current, *reinterpret_cast<const QString*>(ptr)).asReturnedValue(); case QMetaType::Float: - return QV4::Value::fromDouble(*reinterpret_cast<const float*>(ptr)); + return QV4::Encode(*reinterpret_cast<const float*>(ptr)); case QMetaType::Short: - return QV4::Value::fromInt32(*reinterpret_cast<const short*>(ptr)); + return QV4::Encode((int)*reinterpret_cast<const short*>(ptr)); case QMetaType::UShort: - return QV4::Value::fromUInt32(*reinterpret_cast<const unsigned short*>(ptr)); + return QV4::Encode((int)*reinterpret_cast<const unsigned short*>(ptr)); case QMetaType::Char: - return QV4::Value::fromInt32(*reinterpret_cast<const char*>(ptr)); + return QV4::Encode((int)*reinterpret_cast<const char*>(ptr)); case QMetaType::UChar: - return QV4::Value::fromUInt32(*reinterpret_cast<const unsigned char*>(ptr)); + return QV4::Encode((int)*reinterpret_cast<const unsigned char*>(ptr)); case QMetaType::QChar: - return QV4::Value::fromInt32((*reinterpret_cast<const QChar*>(ptr)).unicode()); + return QV4::Encode((int)(*reinterpret_cast<const QChar*>(ptr)).unicode()); case QMetaType::QDateTime: - return QV4::Value::fromObject(m_v4Engine->newDateObject(*reinterpret_cast<const QDateTime *>(ptr))); + return QV4::Value::fromObject(m_v4Engine->newDateObject(*reinterpret_cast<const QDateTime *>(ptr))).asReturnedValue(); case QMetaType::QDate: - return QV4::Value::fromObject(m_v4Engine->newDateObject(QDateTime(*reinterpret_cast<const QDate *>(ptr)))); + return QV4::Value::fromObject(m_v4Engine->newDateObject(QDateTime(*reinterpret_cast<const QDate *>(ptr)))).asReturnedValue(); case QMetaType::QTime: - return QV4::Value::fromObject(m_v4Engine->newDateObject(QDateTime(QDate(1970,1,1), *reinterpret_cast<const QTime *>(ptr)))); + return QV4::Value::fromObject(m_v4Engine->newDateObject(QDateTime(QDate(1970,1,1), *reinterpret_cast<const QTime *>(ptr)))).asReturnedValue(); case QMetaType::QRegExp: - return QV4::Value::fromObject(m_v4Engine->newRegExpObject(*reinterpret_cast<const QRegExp *>(ptr))); + return QV4::Value::fromObject(m_v4Engine->newRegExpObject(*reinterpret_cast<const QRegExp *>(ptr))).asReturnedValue(); case QMetaType::QObjectStar: return QV4::QObjectWrapper::wrap(m_v4Engine, *reinterpret_cast<QObject* const *>(ptr)); case QMetaType::QStringList: { bool succeeded = false; - QV4::Value retn = QV4::SequencePrototype::fromVariant(m_v4Engine, variant, &succeeded); + QV4::Scope scope(m_v4Engine); + QV4::ScopedValue retn(scope, QV4::SequencePrototype::fromVariant(m_v4Engine, variant, &succeeded)); if (succeeded) - return retn; + return retn.asReturnedValue(); return arrayFromStringList(this, *reinterpret_cast<const QStringList *>(ptr)); } case QMetaType::QVariantList: @@ -290,13 +291,14 @@ QV4::Value QV8Engine::fromVariant(const QVariant &variant) if (QQmlValueType *vt = QQmlValueTypeFactory::valueType(type)) return QV4::QmlValueTypeWrapper::create(this, variant, vt); } else { + QV4::Scope scope(m_v4Engine); if (type == qMetaTypeId<QQmlListReference>()) { typedef QQmlListReferencePrivate QDLRP; QDLRP *p = QDLRP::get((QQmlListReference*)ptr); if (p->object) { return QV4::QmlListWrapper::create(this, p->property, p->propertyType); } else { - return QV4::Value::nullValue(); + return QV4::Encode::null(); } } else if (type == qMetaTypeId<QJSValue>()) { const QJSValue *value = reinterpret_cast<const QJSValue *>(ptr); @@ -310,9 +312,9 @@ QV4::Value QV8Engine::fromVariant(const QVariant &variant) a->arrayReserve(list.count()); a->arrayDataLen = list.count(); for (int ii = 0; ii < list.count(); ++ii) - a->arrayData[ii].value = QV4::QObjectWrapper::wrap(m_v4Engine, list.at(ii)); + a->arrayData[ii].value = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(m_v4Engine, list.at(ii))); a->setArrayLengthUnchecked(list.count()); - return QV4::Value::fromObject(a); + return QV4::Value::fromObject(a).asReturnedValue(); } else if (QMetaType::typeFlags(type) & QMetaType::PointerToQObject) { return QV4::QObjectWrapper::wrap(m_v4Engine, *reinterpret_cast<QObject* const *>(ptr)); } @@ -323,9 +325,9 @@ QV4::Value QV8Engine::fromVariant(const QVariant &variant) return QV4::QObjectWrapper::wrap(m_v4Engine, obj); bool succeeded = false; - QV4::Value retn = QV4::SequencePrototype::fromVariant(m_v4Engine, variant, &succeeded); + QV4::ScopedValue retn(scope, QV4::SequencePrototype::fromVariant(m_v4Engine, variant, &succeeded)); if (succeeded) - return retn; + return retn.asReturnedValue(); if (QQmlValueType *vt = QQmlValueTypeFactory::valueType(type)) return QV4::QmlValueTypeWrapper::create(this, variant, vt); @@ -335,7 +337,7 @@ QV4::Value QV8Engine::fromVariant(const QVariant &variant) // + QObjectList // + QList<int> - return QV4::Value::fromObject(m_v4Engine->newVariantObject(variant)); + return QV4::Value::fromObject(m_v4Engine->newVariantObject(variant)).asReturnedValue(); } QNetworkAccessManager *QV8Engine::networkAccessManager() @@ -513,15 +515,15 @@ QV4::Value QV8Engine::global() // The result is a new Array object with length equal to the length // of the QVariantList, and the elements being the QVariantList's // elements converted to JS, recursively. -QV4::Value QV8Engine::variantListToJS(const QVariantList &lst) +QV4::ReturnedValue QV8Engine::variantListToJS(const QVariantList &lst) { QV4::ArrayObject *a = m_v4Engine->newArrayObject(); a->arrayReserve(lst.size()); a->arrayDataLen = lst.size(); for (int i = 0; i < lst.size(); i++) - a->arrayData[i].value = variantToJS(lst.at(i)); + a->arrayData[i].value = QV4::Value::fromReturnedValue(variantToJS(lst.at(i))); a->setArrayLengthUnchecked(lst.size()); - return QV4::Value::fromObject(a); + return QV4::Value::fromObject(a).asReturnedValue(); } // Converts a JS Array object to a QVariantList. @@ -559,15 +561,15 @@ QVariantList QV8Engine::variantListFromJS(QV4::ArrayObject *a, // The result is a new Object object with property names being // the keys of the QVariantMap, and values being the values of // the QVariantMap converted to JS, recursively. -QV4::Value QV8Engine::variantMapToJS(const QVariantMap &vmap) +QV4::ReturnedValue QV8Engine::variantMapToJS(const QVariantMap &vmap) { QV4::Object *o = m_v4Engine->newObject(); QVariantMap::const_iterator it; for (it = vmap.constBegin(); it != vmap.constEnd(); ++it) { QV4::Property *p = o->insertMember(m_v4Engine->newIdentifier(it.key()), QV4::Attr_Data); - p->value = variantToJS(it.value()); + p->value = QV4::Value::fromReturnedValue(variantToJS(it.value())); } - return QV4::Value::fromObject(o); + return QV4::Value::fromObject(o).asReturnedValue(); } // Converts a JS Object to a QVariantMap. @@ -588,17 +590,19 @@ QVariantMap QV8Engine::variantMapFromJS(QV4::Object *o, // empty object (and no error is thrown). return result; } + QV4::Scope scope(o->engine()); visitedObjects.insert(o); QV4::ObjectIterator it(o, QV4::ObjectIterator::EnumerableOnly); + QV4::ScopedValue name(scope); while (1) { QV4::Value v; - QV4::Value name = it.nextPropertyNameAsString(&v); - if (name.isNull()) + name = it.nextPropertyNameAsString(&v); + if (name->isNull()) break; - QString key = name.toQStringNoThrow(); + QString key = name->toQStringNoThrow(); result.insert(key, variantFromJS(v, visitedObjects)); } @@ -608,96 +612,85 @@ QVariantMap QV8Engine::variantMapFromJS(QV4::Object *o, // Converts the meta-type defined by the given type and data to JS. // Returns the value if conversion succeeded, an empty handle otherwise. -QV4::Value QV8Engine::metaTypeToJS(int type, const void *data) +QV4::ReturnedValue QV8Engine::metaTypeToJS(int type, const void *data) { Q_ASSERT(data != 0); - QV4::Value result; // check if it's one of the types we know switch (QMetaType::Type(type)) { case QMetaType::UnknownType: case QMetaType::Void: - return QV4::Value::undefinedValue(); + return QV4::Encode::undefined(); case QMetaType::Bool: - return QV4::Value::fromBoolean(*reinterpret_cast<const bool*>(data)); + return QV4::Encode(*reinterpret_cast<const bool*>(data)); case QMetaType::Int: - return QV4::Value::fromInt32(*reinterpret_cast<const int*>(data)); + return QV4::Encode(*reinterpret_cast<const int*>(data)); case QMetaType::UInt: - return QV4::Value::fromUInt32(*reinterpret_cast<const uint*>(data)); + return QV4::Encode(*reinterpret_cast<const uint*>(data)); case QMetaType::LongLong: - return QV4::Value::fromDouble(double(*reinterpret_cast<const qlonglong*>(data))); + return QV4::Encode(double(*reinterpret_cast<const qlonglong*>(data))); case QMetaType::ULongLong: #if defined(Q_OS_WIN) && defined(_MSC_FULL_VER) && _MSC_FULL_VER <= 12008804 #pragma message("** NOTE: You need the Visual Studio Processor Pack to compile support for 64bit unsigned integers.") - return QV4::Value::fromDouble(double((qlonglong)*reinterpret_cast<const qulonglong*>(data))); + return QV4::Encode(double((qlonglong)*reinterpret_cast<const qulonglong*>(data))); #elif defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) - return QV4::Value::fromDouble(double((qlonglong)*reinterpret_cast<const qulonglong*>(data))); + return QV4::Encode(double((qlonglong)*reinterpret_cast<const qulonglong*>(data))); #else - return QV4::Value::fromDouble(double(*reinterpret_cast<const qulonglong*>(data))); + return QV4::Encode(double(*reinterpret_cast<const qulonglong*>(data))); #endif case QMetaType::Double: - return QV4::Value::fromDouble(*reinterpret_cast<const double*>(data)); + return QV4::Encode(*reinterpret_cast<const double*>(data)); case QMetaType::QString: - return QV4::Value::fromString(m_v4Engine->current, *reinterpret_cast<const QString*>(data)); + return QV4::Value::fromString(m_v4Engine->current, *reinterpret_cast<const QString*>(data)).asReturnedValue(); case QMetaType::Float: - return QV4::Value::fromDouble(*reinterpret_cast<const float*>(data)); + return QV4::Encode(*reinterpret_cast<const float*>(data)); case QMetaType::Short: - return QV4::Value::fromInt32(*reinterpret_cast<const short*>(data)); + return QV4::Encode((int)*reinterpret_cast<const short*>(data)); case QMetaType::UShort: - return QV4::Value::fromUInt32(*reinterpret_cast<const unsigned short*>(data)); + return QV4::Encode((int)*reinterpret_cast<const unsigned short*>(data)); case QMetaType::Char: - return QV4::Value::fromInt32(*reinterpret_cast<const char*>(data)); + return QV4::Encode((int)*reinterpret_cast<const char*>(data)); case QMetaType::UChar: - return QV4::Value::fromUInt32(*reinterpret_cast<const unsigned char*>(data)); + return QV4::Encode((int)*reinterpret_cast<const unsigned char*>(data)); case QMetaType::QChar: - return QV4::Value::fromUInt32((*reinterpret_cast<const QChar*>(data)).unicode()); + return QV4::Encode((int)(*reinterpret_cast<const QChar*>(data)).unicode()); case QMetaType::QStringList: - result = QV4::Value::fromObject(m_v4Engine->newArrayObject(*reinterpret_cast<const QStringList *>(data))); - break; + return QV4::Value::fromObject(m_v4Engine->newArrayObject(*reinterpret_cast<const QStringList *>(data))).asReturnedValue(); case QMetaType::QVariantList: - result = variantListToJS(*reinterpret_cast<const QVariantList *>(data)); - break; + return variantListToJS(*reinterpret_cast<const QVariantList *>(data)); case QMetaType::QVariantMap: - result = variantMapToJS(*reinterpret_cast<const QVariantMap *>(data)); - break; + return variantMapToJS(*reinterpret_cast<const QVariantMap *>(data)); case QMetaType::QDateTime: - result = QV4::Value::fromObject(m_v4Engine->newDateObject(*reinterpret_cast<const QDateTime *>(data))); - break; + return QV4::Value::fromObject(m_v4Engine->newDateObject(*reinterpret_cast<const QDateTime *>(data))).asReturnedValue(); case QMetaType::QDate: - result = QV4::Value::fromObject(m_v4Engine->newDateObject(QDateTime(*reinterpret_cast<const QDate *>(data)))); - break; + return QV4::Value::fromObject(m_v4Engine->newDateObject(QDateTime(*reinterpret_cast<const QDate *>(data)))).asReturnedValue(); case QMetaType::QRegExp: - result = QV4::Value::fromObject(m_v4Engine->newRegExpObject(*reinterpret_cast<const QRegExp *>(data))); - break; + return QV4::Value::fromObject(m_v4Engine->newRegExpObject(*reinterpret_cast<const QRegExp *>(data))).asReturnedValue(); case QMetaType::QObjectStar: - result = QV4::QObjectWrapper::wrap(m_v4Engine, *reinterpret_cast<QObject* const *>(data)); - break; + return QV4::QObjectWrapper::wrap(m_v4Engine, *reinterpret_cast<QObject* const *>(data)); case QMetaType::QVariant: - result = variantToJS(*reinterpret_cast<const QVariant*>(data)); - break; + return variantToJS(*reinterpret_cast<const QVariant*>(data)); case QMetaType::QJsonValue: - result = QV4::JsonObject::fromJsonValue(m_v4Engine, *reinterpret_cast<const QJsonValue *>(data)); - break; + return QV4::JsonObject::fromJsonValue(m_v4Engine, *reinterpret_cast<const QJsonValue *>(data)); case QMetaType::QJsonObject: - result = QV4::JsonObject::fromJsonObject(m_v4Engine, *reinterpret_cast<const QJsonObject *>(data)); - break; + return QV4::JsonObject::fromJsonObject(m_v4Engine, *reinterpret_cast<const QJsonObject *>(data)); case QMetaType::QJsonArray: - result = QV4::JsonObject::fromJsonArray(m_v4Engine, *reinterpret_cast<const QJsonArray *>(data)); - break; + return QV4::JsonObject::fromJsonArray(m_v4Engine, *reinterpret_cast<const QJsonArray *>(data)); default: if (type == qMetaTypeId<QJSValue>()) { return QJSValuePrivate::get(*reinterpret_cast<const QJSValue*>(data))->getValue(m_v4Engine); } else { QByteArray typeName = QMetaType::typeName(type); if (typeName.endsWith('*') && !*reinterpret_cast<void* const *>(data)) { - return QV4::Value::nullValue(); + return QV4::Encode::null(); } else { // Fall back to wrapping in a QVariant. - result = QV4::Value::fromObject(m_v4Engine->newVariantObject(QVariant(type, data))); + return QV4::Value::fromObject(m_v4Engine->newVariantObject(QVariant(type, data))).asReturnedValue(); } } } - return result; + Q_UNREACHABLE(); + return 0; } // Converts a JS value to a meta-type. @@ -874,7 +867,7 @@ bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) { } // Converts a QVariant to JS. -QV4::Value QV8Engine::variantToJS(const QVariant &value) +QV4::ReturnedValue QV8Engine::variantToJS(const QVariant &value) { return metaTypeToJS(value.userType(), value.constData()); } diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 1296973394..3209e55434 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -121,6 +121,7 @@ namespace QV4 { // valid during the call. If the return value isn't set within myMethod(), the will return // undefined. class QV8Engine; +// ### GC class QQmlV4Function { public: @@ -129,6 +130,7 @@ public: QQmlContextData *context() { return ctx; } QV4::Value qmlGlobal() { return global; } void setReturnValue(const QV4::Value &rv) { *retVal = rv; } + void setReturnValue(QV4::ReturnedValue rv) { *retVal = QV4::Value::fromReturnedValue(rv); } QV8Engine *engine() const { return e; } private: friend struct QV4::QObjectMethod; @@ -149,6 +151,7 @@ private: QV8Engine *e; }; +// ### GC class Q_QML_PRIVATE_EXPORT QQmlV4Handle { public: @@ -210,7 +213,7 @@ public: void freezeObject(const QV4::Value &value); QVariant toVariant(const QV4::Value &value, int typeHint); - QV4::Value fromVariant(const QVariant &); + QV4::ReturnedValue fromVariant(const QVariant &); // Return a JS string for the given QString \a string QV4::Value toString(const QString &string); @@ -232,19 +235,19 @@ public: inline Deletable *extensionData(int) const; void setExtensionData(int, Deletable *); - QV4::Value variantListToJS(const QVariantList &lst); + QV4::ReturnedValue variantListToJS(const QVariantList &lst); inline QVariantList variantListFromJS(QV4::ArrayObject *array) { V8ObjectSet visitedObjects; return variantListFromJS(array, visitedObjects); } - QV4::Value variantMapToJS(const QVariantMap &vmap); + QV4::ReturnedValue variantMapToJS(const QVariantMap &vmap); inline QVariantMap variantMapFromJS(QV4::Object *object) { V8ObjectSet visitedObjects; return variantMapFromJS(object, visitedObjects); } - QV4::Value variantToJS(const QVariant &value); + QV4::ReturnedValue variantToJS(const QVariant &value); inline QVariant variantFromJS(const QV4::Value &value) { V8ObjectSet visitedObjects; return variantFromJS(value, visitedObjects); } - QV4::Value metaTypeToJS(int type, const void *data); + QV4::ReturnedValue metaTypeToJS(int type, const void *data); bool metaTypeFromJS(const QV4::Value &value, int type, void *data); bool convertToNativeQObject(const QV4::Value &value, |