aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-09-23 15:52:10 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-26 09:05:16 +0200
commit12fd2ccd3fa2dc0133b5a3fb89f9fdf5cf721232 (patch)
tree880acb9c7c0d8289185b6aebe4339f439c707a0e /src/qml/qml
parent2e4f66caa8a5f9e887dbdb4e3f2ae5c9be9a7005 (diff)
Fix Persistent/WeakValue API
Don't use unprotected Values in the API anymore. Change-Id: I8851628227fca374de24701bc8ee0908b5ae3923 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r--src/qml/qml/qqmlbinding.cpp8
-rw-r--r--src/qml/qml/qqmlbinding_p.h2
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp12
-rw-r--r--src/qml/qml/qqmlboundsignal_p.h2
-rw-r--r--src/qml/qml/qqmlcomponent.cpp34
-rw-r--r--src/qml/qml/qqmlcomponent_p.h2
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp6
-rw-r--r--src/qml/qml/qqmlengine.cpp2
-rw-r--r--src/qml/qml/qqmlexpression.cpp7
-rw-r--r--src/qml/qml/qqmljavascriptexpression.cpp18
-rw-r--r--src/qml/qml/qqmljavascriptexpression_p.h4
-rw-r--r--src/qml/qml/qqmllocale.cpp8
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp10
-rw-r--r--src/qml/qml/qqmlproperty.cpp38
-rw-r--r--src/qml/qml/qqmlproperty_p.h2
-rw-r--r--src/qml/qml/qqmltypewrapper.cpp12
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper.cpp2
-rw-r--r--src/qml/qml/qqmlvme.cpp2
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp30
-rw-r--r--src/qml/qml/qqmlvmemetaobject_p.h2
-rw-r--r--src/qml/qml/qqmlxmlhttprequest.cpp35
-rw-r--r--src/qml/qml/v8/qv8engine.cpp15
22 files changed, 144 insertions, 109 deletions
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp
index a5e281dc56..a388178952 100644
--- a/src/qml/qml/qqmlbinding.cpp
+++ b/src/qml/qml/qqmlbinding.cpp
@@ -178,7 +178,7 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj,
v4function = qmlBinding(ctxt, obj, str, url, m_lineNumber);
}
-QQmlBinding::QQmlBinding(const QV4::Value &functionPtr, QObject *obj, QQmlContextData *ctxt,
+QQmlBinding::QQmlBinding(const QV4::ValueRef functionPtr, QObject *obj, QQmlContextData *ctxt,
const QString &url, quint16 lineNumber, quint16 columnNumber)
: QQmlJavaScriptExpression(&QQmlBinding_jsvtable), QQmlAbstractBinding(Binding),
m_url(url), m_lineNumber(lineNumber), m_columnNumber(columnNumber)
@@ -250,7 +250,8 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags)
bool isUndefined = false;
- QV4::ScopedValue result(scope, QQmlJavaScriptExpression::evaluate(context(), v4function.value(), &isUndefined));
+ QV4::ScopedValue f(scope, v4function.value());
+ QV4::ScopedValue result(scope, QQmlJavaScriptExpression::evaluate(context(), f, &isUndefined));
trace.event("writing binding result");
@@ -291,7 +292,8 @@ QVariant QQmlBinding::evaluate()
bool isUndefined = false;
- QV4::ScopedValue result(scope, QQmlJavaScriptExpression::evaluate(context(), v4function.value(), &isUndefined));
+ QV4::ScopedValue f(scope, v4function.value());
+ QV4::ScopedValue result(scope, QQmlJavaScriptExpression::evaluate(context(), f, &isUndefined));
ep->dereferenceScarceResources();
diff --git a/src/qml/qml/qqmlbinding_p.h b/src/qml/qml/qqmlbinding_p.h
index ea703e8d38..e872482373 100644
--- a/src/qml/qml/qqmlbinding_p.h
+++ b/src/qml/qml/qqmlbinding_p.h
@@ -84,7 +84,7 @@ public:
QQmlBinding(const QString &, QObject *, QQmlContextData *);
QQmlBinding(const QString &, QObject *, QQmlContextData *,
const QString &url, quint16 lineNumber, quint16 columnNumber);
- QQmlBinding(const QV4::Value &, QObject *, QQmlContextData *,
+ QQmlBinding(const QV4::ValueRef, QObject *, QQmlContextData *,
const QString &url, quint16 lineNumber, quint16 columnNumber);
void setTarget(const QQmlProperty &);
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index 3a0d58d87c..cc2edb7b19 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -86,7 +86,7 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
m_expression = expression;
}
-QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, QQmlContextData *ctxt, QObject *scope, const QV4::PersistentValue &function)
+QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, QQmlContextData *ctxt, QObject *scope, const QV4::ValueRef &function)
: QQmlJavaScriptExpression(&QQmlBoundSignalExpression_jsvtable),
m_v8function(function),
m_line(-1),
@@ -128,7 +128,9 @@ QString QQmlBoundSignalExpression::expression() const
{
if (m_expressionFunctionValid) {
Q_ASSERT (context() && engine());
- return m_v8function.value().toQStringNoThrow();
+ QV4::Scope scope(QQmlEnginePrivate::get(engine())->v4engine());
+ QV4::ScopedValue v(scope, m_v8function.value());
+ return v->toQStringNoThrow();
} else {
return m_expression;
}
@@ -144,6 +146,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
return;
QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine());
+ QV4::Scope scope(ep->v4engine());
ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation.
{
@@ -181,7 +184,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
m_v8function = evalFunction(context(), scopeObject(), expression,
m_fileName, m_line, &m_v8qmlscope);
- if (m_v8function.isUndefined() || m_v8function.value().isNull()) {
+ if (m_v8function.isNullOrUndefined()) {
ep->dereferenceScarceResources();
return; // could not evaluate function. Not valid.
}
@@ -223,7 +226,8 @@ void QQmlBoundSignalExpression::evaluate(void **a)
}
}
- QQmlJavaScriptExpression::evaluate(context(), m_v8function.value(), argCount, args, 0);
+ QV4::ScopedValue f(scope, m_v8function.value());
+ QQmlJavaScriptExpression::evaluate(context(), f, argCount, args, 0);
}
ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
}
diff --git a/src/qml/qml/qqmlboundsignal_p.h b/src/qml/qml/qqmlboundsignal_p.h
index 86e3dc20ea..feb79d5484 100644
--- a/src/qml/qml/qqmlboundsignal_p.h
+++ b/src/qml/qml/qqmlboundsignal_p.h
@@ -76,7 +76,7 @@ public:
const QString &parameterString = QString());
QQmlBoundSignalExpression(QObject *target, int index,
- QQmlContextData *ctxt, QObject *scope, const QV4::PersistentValue &function);
+ QQmlContextData *ctxt, QObject *scope, const QV4::ValueRef &function);
// "inherited" from QQmlJavaScriptExpression.
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp
index cf3493a590..cfda595438 100644
--- a/src/qml/qml/qqmlcomponent.cpp
+++ b/src/qml/qml/qqmlcomponent.cpp
@@ -1123,7 +1123,7 @@ public:
QV8Engine *v8;
QPointer<QObject> parent;
QV4::Value valuemap;
- QV4::Value qmlGlobal;
+ QV4::SafeValue qmlGlobal;
QV4::Value m_statusChanged;
protected:
virtual void statusChanged(Status);
@@ -1244,7 +1244,8 @@ void QQmlComponent::createObject(QQmlV4Function *args)
if (!valuemap.isUndefined()) {
QQmlComponentExtension *e = componentExtension(v8engine);
- QV4::ScopedValue f(scope, QV4::Script::evaluate(v4engine, QString::fromLatin1(INITIALPROPERTIES_SOURCE), args->qmlGlobal().asObject()));
+ QV4::ScopedObject qmlglobal(scope, args->qmlGlobal());
+ QV4::ScopedValue f(scope, QV4::Script::evaluate(v4engine, QString::fromLatin1(INITIALPROPERTIES_SOURCE), qmlglobal));
Q_ASSERT(f->asFunctionObject());
QV4::ScopedCallData callData(scope, 2);
callData->thisObject = QV4::Value::fromObject(v4engine->globalObject);
@@ -1329,9 +1330,11 @@ void QQmlComponent::incubateObject(QQmlV4Function *args)
Q_ASSERT(d->engine);
Q_UNUSED(d);
Q_ASSERT(args);
+ QV4::ExecutionEngine *v4 = QV8Engine::getV4(args->engine());
+ QV4::Scope scope(v4);
QObject *parent = 0;
- QV4::Value valuemap = QV4::Value::undefinedValue();
+ QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous;
if (args->length() >= 1) {
@@ -1340,9 +1343,9 @@ void QQmlComponent::incubateObject(QQmlV4Function *args)
}
if (args->length() >= 2) {
- QV4::Value v = (*args)[1];
- if (v.isNull()) {
- } else if (!v.asObject() || v.asArrayObject()) {
+ QV4::ScopedValue v(scope, (*args)[1]);
+ if (v->isNull()) {
+ } else if (!v->asObject() || v->asArrayObject()) {
qmlInfo(this) << tr("createObject: value is not an object");
args->setReturnValue(QV4::Value::nullValue());
return;
@@ -1361,27 +1364,27 @@ void QQmlComponent::incubateObject(QQmlV4Function *args)
QQmlComponentExtension *e = componentExtension(args->engine());
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(args->engine());
- QmlIncubatorObject *r = new (v4->memoryManager) QmlIncubatorObject(args->engine(), mode);
- r->setPrototype(e->incubationProto.value().asObject());
+ QV4::Scoped<QmlIncubatorObject> r(scope, new (v4->memoryManager) QmlIncubatorObject(args->engine(), mode));
+ QV4::ScopedObject p(scope, e->incubationProto.value());
+ r->setPrototype(p.getPointer());
- if (!valuemap.isUndefined()) {
+ if (!valuemap->isUndefined()) {
r->valuemap = valuemap;
r->qmlGlobal = args->qmlGlobal();
}
r->parent = parent;
- create(*r, creationContext());
+ create(*r.getPointer(), creationContext());
if (r->status() == QQmlIncubator::Null) {
args->setReturnValue(QV4::Value::nullValue());
} else {
- args->setReturnValue(QV4::Value::fromObject(r));
+ args->setReturnValue(r.asValue());
}
}
// XXX used by QSGLoader
-void QQmlComponentPrivate::initializeObjectWithInitialProperties(const QV4::Value &qmlGlobal, const QV4::Value &valuemap, QObject *toCreate)
+void QQmlComponentPrivate::initializeObjectWithInitialProperties(const QV4::ValueRef qmlGlobal, const QV4::Value &valuemap, QObject *toCreate)
{
QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
QV8Engine *v8engine = ep->v8engine();
@@ -1393,8 +1396,9 @@ void QQmlComponentPrivate::initializeObjectWithInitialProperties(const QV4::Valu
if (!valuemap.isUndefined()) {
QQmlComponentExtension *e = componentExtension(v8engine);
+ QV4::ScopedObject qmlGlobalObj(scope, qmlGlobal);
QV4::Scoped<QV4::FunctionObject> f(scope, QV4::Script::evaluate(QV8Engine::getV4(v8engine),
- QString::fromLatin1(INITIALPROPERTIES_SOURCE), qmlGlobal.asObject()));
+ QString::fromLatin1(INITIALPROPERTIES_SOURCE), qmlGlobalObj));
QV4::ScopedCallData callData(scope, 2);
callData->thisObject = QV4::Value::fromObject(v4engine->globalObject);
callData->args[0] = object;
@@ -1490,7 +1494,7 @@ void QmlIncubatorObject::setInitialState(QObject *o)
QV4::ExecutionEngine *v4 = QV8Engine::getV4(v8);
QV4::Scope scope(v4);
- QV4::Scoped<QV4::FunctionObject> f(scope, QV4::Script::evaluate(v4, QString::fromLatin1(INITIALPROPERTIES_SOURCE), qmlGlobal.asObject()));
+ QV4::Scoped<QV4::FunctionObject> f(scope, QV4::Script::evaluate(v4, QString::fromLatin1(INITIALPROPERTIES_SOURCE), qmlGlobal));
QV4::ScopedCallData callData(scope, 2);
callData->thisObject = QV4::Value::fromObject(v4->globalObject);
callData->args[0] = QV4::Value::fromReturnedValue(QV4::QObjectWrapper::wrap(v4, o));
diff --git a/src/qml/qml/qqmlcomponent_p.h b/src/qml/qml/qqmlcomponent_p.h
index 08e4dcea7d..f2f81c8ab2 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::Value &qmlGlobal, const QV4::Value &valuemap, QObject *toCreate);
+ void initializeObjectWithInitialProperties(const QV4::ValueRef qmlGlobal, const QV4::Value &valuemap, QObject *toCreate);
QQmlTypeData *typeData;
virtual void typeDataReady(QQmlTypeData *);
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp
index 425c19a090..46ff821fff 100644
--- a/src/qml/qml/qqmlcontextwrapper.cpp
+++ b/src/qml/qml/qqmlcontextwrapper.cpp
@@ -188,7 +188,7 @@ ReturnedValue QmlContextWrapper::get(Managed *m, const StringRef name, bool *has
if (r.scriptIndex != -1) {
int index = r.scriptIndex;
if (index < context->importedScripts.count())
- return context->importedScripts.at(index).value().asReturnedValue();
+ return context->importedScripts.at(index).value();
else
return QV4::Value::undefinedValue().asReturnedValue();
} else if (r.type) {
@@ -318,13 +318,13 @@ void QmlContextWrapper::put(Managed *m, const StringRef name, const ValueRef val
// Search scope object
if (scopeObject &&
- QV4::QObjectWrapper::setQmlProperty(v4->current, context, scopeObject, name.getPointer(), QV4::QObjectWrapper::CheckRevision, *value))
+ QV4::QObjectWrapper::setQmlProperty(v4->current, context, scopeObject, name.getPointer(), QV4::QObjectWrapper::CheckRevision, value))
return;
scopeObject = 0;
// Search context object
if (context->contextObject &&
- QV4::QObjectWrapper::setQmlProperty(v4->current, context, context->contextObject, name.getPointer(), QV4::QObjectWrapper::CheckRevision, *value))
+ QV4::QObjectWrapper::setQmlProperty(v4->current, context, context->contextObject, name.getPointer(), QV4::QObjectWrapper::CheckRevision, value))
return;
context = context->parent;
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 2e77d8257b..2f873936e3 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -1654,7 +1654,7 @@ void QQmlData::destroyed(QObject *object)
delete extendedData;
// Dispose the handle.
- jsWrapper = QV4::Value::undefinedValue();
+ jsWrapper.clear();
if (ownMemory)
delete this;
diff --git a/src/qml/qml/qqmlexpression.cpp b/src/qml/qml/qqmlexpression.cpp
index 76214c17a4..cdb5813221 100644
--- a/src/qml/qml/qqmlexpression.cpp
+++ b/src/qml/qml/qqmlexpression.cpp
@@ -262,12 +262,17 @@ void QQmlExpression::setExpression(const QString &expression)
// Must be called with a valid handle scope
QV4::ReturnedValue QQmlExpressionPrivate::v4value(bool *isUndefined)
{
+ Q_Q(QQmlExpression);
+
if (!expressionFunctionValid) {
function = qmlBinding(context(), scopeObject(), expression, url, line, &qmlscope);
expressionFunctionValid = true;
}
- return evaluate(context(), function.value(), isUndefined);
+ QV4::ExecutionEngine *v4 = QQmlEnginePrivate::get(q->engine())->v4engine();
+ QV4::Scope scope(v4);
+ QV4::ScopedValue f(scope, function.value());
+ return evaluate(context(), f, isUndefined);
}
QVariant QQmlExpressionPrivate::value(bool *isUndefined)
diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp
index b1184729d0..e08e8eebb7 100644
--- a/src/qml/qml/qqmljavascriptexpression.cpp
+++ b/src/qml/qml/qqmljavascriptexpression.cpp
@@ -321,7 +321,7 @@ void QQmlJavaScriptExpression::exceptionToError(const QV4::Exception &e, QQmlErr
}
}
-QV4::PersistentValue
+QV4::ReturnedValue
QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scopeObject,
const QString &code, const QString &filename, quint16 line,
QV4::PersistentValue *qmlscope)
@@ -333,8 +333,8 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scopeObje
QV4::ExecutionContext *ctx = v4->current;
QV4::Scope scope(v4);
- QV4::Scoped<QV4::Object> qmlScopeObject(scope, QV4::QmlContextWrapper::qmlScope(ep->v8engine(), ctxt, scopeObject));
- QV4::Script script(v4, qmlScopeObject.getPointer(), code, filename, line);
+ QV4::ScopedObject qmlScopeObject(scope, QV4::QmlContextWrapper::qmlScope(ep->v8engine(), ctxt, scopeObject));
+ QV4::Script script(v4, qmlScopeObject, code, filename, line);
QV4::ScopedValue result(scope);
try {
script.parse();
@@ -351,14 +351,14 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scopeObje
error.setUrl(QUrl::fromLocalFile(filename));
error.setObject(scopeObject);
ep->warning(error);
- return QV4::PersistentValue();
+ return QV4::Encode::undefined();
}
if (qmlscope)
- *qmlscope = qmlScopeObject.asValue();
+ *qmlscope = qmlScopeObject;
return result.asReturnedValue();
}
-QV4::PersistentValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt, QObject *qmlScope,
+QV4::ReturnedValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt, QObject *qmlScope,
const QString &code, const QString &filename, quint16 line,
QV4::PersistentValue *qmlscope)
{
@@ -369,8 +369,8 @@ QV4::PersistentValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt,
QV4::ExecutionContext *ctx = v4->current;
QV4::Scope scope(v4);
- QV4::ScopedValue qmlScopeObject(scope, QV4::QmlContextWrapper::qmlScope(ep->v8engine(), ctxt, qmlScope));
- QV4::Script script(v4, qmlScopeObject->asObject(), code, filename, line);
+ QV4::ScopedObject qmlScopeObject(scope, QV4::QmlContextWrapper::qmlScope(ep->v8engine(), ctxt, qmlScope));
+ QV4::Script script(v4, qmlScopeObject, code, filename, line);
QV4::ScopedValue result(scope);
try {
script.parse();
@@ -387,7 +387,7 @@ QV4::PersistentValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt,
error.setUrl(QUrl::fromLocalFile(filename));
error.setObject(qmlScope);
ep->warning(error);
- return QV4::PersistentValue();
+ return QV4::Encode::undefined();
}
if (qmlscope)
*qmlscope = qmlScopeObject;
diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h
index f08b3af6cf..c13e191216 100644
--- a/src/qml/qml/qqmljavascriptexpression_p.h
+++ b/src/qml/qml/qqmljavascriptexpression_p.h
@@ -146,12 +146,12 @@ public:
QQmlDelayedError *delayedError();
static void exceptionToError(const QV4::Exception &e, QQmlError &);
- static QV4::PersistentValue evalFunction(QQmlContextData *ctxt, QObject *scope,
+ static QV4::ReturnedValue evalFunction(QQmlContextData *ctxt, QObject *scope,
const QString &code, const QString &filename,
quint16 line,
QV4::PersistentValue *qmlscope = 0);
// doesn't require rewriting the expression
- static QV4::PersistentValue qmlBinding(QQmlContextData *ctxt, QObject *scope,
+ static QV4::ReturnedValue qmlBinding(QQmlContextData *ctxt, QObject *scope,
const QString &code,
const QString &filename, quint16 line,
QV4::PersistentValue *qmlscope = 0);
diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp
index c3c7d0282d..db949467d1 100644
--- a/src/qml/qml/qqmllocale.cpp
+++ b/src/qml/qml/qqmllocale.cpp
@@ -835,11 +835,13 @@ QV4::ReturnedValue QQmlLocale::locale(QV8Engine *v8engine, const QString &locale
{
QV8LocaleDataDeletable *d = localeV8Data(v8engine);
QV4::ExecutionEngine *engine = QV8Engine::getV4(v8engine);
- QQmlLocaleData *wrapper = new (engine->memoryManager) QQmlLocaleData(engine);
+ QV4::Scope scope(engine);
+ QV4::Scoped<QQmlLocaleData> wrapper(scope, new (engine->memoryManager) QQmlLocaleData(engine));
if (!locale.isEmpty())
wrapper->locale = QLocale(locale);
- wrapper->setPrototype(d->prototype.value().asObject());
- return QV4::Value::fromObject(wrapper).asReturnedValue();
+ QV4::ScopedObject p(scope, d->prototype.value());
+ wrapper->setPrototype(p.getPointer());
+ return wrapper.asReturnedValue();
}
void QQmlLocale::registerStringLocaleCompare(QV4::ExecutionEngine *engine)
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 601f4dbba0..2f4e782069 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -1080,7 +1080,9 @@ bool QmlObjectCreator::setPropertyValue(QQmlPropertyData *property, int bindingI
if (binding->type == QV4::CompiledData::Binding::Type_Script) {
QV4::Function *runtimeFunction = jsUnit->runtimeFunctions[binding->value.compiledScriptIndex];
- QV4::Value function = QV4::Value::fromObject(QV4::FunctionObject::creatScriptFunction(_qmlContext, runtimeFunction));
+
+ QV4::Scope scope(_qmlContext);
+ QV4::ScopedFunctionObject function(scope, QV4::FunctionObject::creatScriptFunction(_qmlContext, runtimeFunction));
if (binding->flags & QV4::CompiledData::Binding::IsSignalHandlerExpression) {
int signalIndex = _propertyCache->methodIndexToSignalIndex(property->coreIndex);
@@ -1194,6 +1196,8 @@ bool QmlObjectCreator::setPropertyValue(QQmlPropertyData *property, int bindingI
void QmlObjectCreator::setupFunctions()
{
+ QV4::Scope scope(_qmlContext);
+ QV4::ScopedValue function(scope);
QQmlVMEMetaObject *vme = QQmlVMEMetaObject::get(_qobject);
const quint32 *functionIdx = _compiledObject->functionOffsetTable();
@@ -1205,8 +1209,8 @@ void QmlObjectCreator::setupFunctions()
if (!property->isVMEFunction())
continue;
- QV4::FunctionObject *function = QV4::FunctionObject::creatScriptFunction(_qmlContext, runtimeFunction);
- vme->setVmeMethod(property->coreIndex, QV4::Value::fromObject(function));
+ function = QV4::FunctionObject::creatScriptFunction(_qmlContext, runtimeFunction);
+ vme->setVmeMethod(property->coreIndex, function);
}
}
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index f821687f63..bcecda9c57 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -1460,7 +1460,7 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
const QQmlPropertyData &core,
QQmlContextData *context,
QQmlJavaScriptExpression *expression,
- const QV4::Value &result, bool isUndefined,
+ const QV4::ValueRef result, bool isUndefined,
WriteFlags flags)
{
Q_ASSERT(object);
@@ -1482,22 +1482,22 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
if (!isUndefined && !core.isValueTypeVirtual()) {
switch (core.propType) {
case QMetaType::Int:
- if (result.isInteger())
- QUICK_STORE(int, result.integerValue())
- else if (result.isNumber())
- QUICK_STORE(int, qRound(result.doubleValue()))
+ if (result->isInteger())
+ QUICK_STORE(int, result->integerValue())
+ else if (result->isNumber())
+ QUICK_STORE(int, qRound(result->doubleValue()))
break;
case QMetaType::Double:
- if (result.isNumber())
- QUICK_STORE(double, result.asDouble())
+ if (result->isNumber())
+ QUICK_STORE(double, result->asDouble())
break;
case QMetaType::Float:
- if (result.isNumber())
- QUICK_STORE(float, result.asDouble())
+ if (result->isNumber())
+ QUICK_STORE(float, result->asDouble())
break;
case QMetaType::QString:
- if (result.isString())
- QUICK_STORE(QString, result.toQStringNoThrow())
+ if (result->isString())
+ QUICK_STORE(QString, result->toQStringNoThrow())
break;
default:
break;
@@ -1514,19 +1514,19 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
if (isUndefined) {
} else if (core.isQList()) {
- value = v8engine->toVariant(result, qMetaTypeId<QList<QObject *> >());
- } else if (result.isNull() && core.isQObject()) {
+ value = v8engine->toVariant(*result, qMetaTypeId<QList<QObject *> >());
+ } else if (result->isNull() && core.isQObject()) {
value = QVariant::fromValue((QObject *)0);
} else if (core.propType == qMetaTypeId<QList<QUrl> >()) {
- value = resolvedUrlSequence(v8engine->toVariant(result, qMetaTypeId<QList<QUrl> >()), context);
+ value = resolvedUrlSequence(v8engine->toVariant(*result, qMetaTypeId<QList<QUrl> >()), context);
} else if (!isVarProperty && type != qMetaTypeId<QJSValue>()) {
- value = v8engine->toVariant(result, type);
+ value = v8engine->toVariant(*result, type);
}
if (expression->hasError()) {
return false;
} else if (isVarProperty) {
- QV4::FunctionObject *f = result.asFunctionObject();
+ QV4::FunctionObject *f = result->asFunctionObject();
if (f && f->bindingKeyFlag) {
// we explicitly disallow this case to avoid confusion. Users can still store one
// in an array in a var property if they need to, but the common case is user error.
@@ -1537,14 +1537,14 @@ 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);
} else if (isUndefined && type == qMetaTypeId<QVariant>()) {
writeValueProperty(object, core, QVariant(), context, flags);
} else if (type == qMetaTypeId<QJSValue>()) {
- QV4::FunctionObject *f = result.asFunctionObject();
+ QV4::FunctionObject *f = result->asFunctionObject();
if (f && f->bindingKeyFlag) {
expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
expression->delayedError()->setErrorObject(object);
@@ -1562,7 +1562,7 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
expression->delayedError()->setErrorDescription(errorStr);
expression->delayedError()->setErrorObject(object);
return false;
- } else if (QV4::FunctionObject *f = result.asFunctionObject()) {
+ } else if (QV4::FunctionObject *f = result->asFunctionObject()) {
if (f->bindingKeyFlag)
expression->delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
else
diff --git a/src/qml/qml/qqmlproperty_p.h b/src/qml/qml/qqmlproperty_p.h
index 9af091ad46..ce15061ba0 100644
--- a/src/qml/qml/qqmlproperty_p.h
+++ b/src/qml/qml/qqmlproperty_p.h
@@ -148,7 +148,7 @@ public:
static bool writeBinding(QObject *, const QQmlPropertyData &,
QQmlContextData *context,
QQmlJavaScriptExpression *expression,
- const QV4::Value &result, bool isUndefined,
+ const QV4::ValueRef result, bool isUndefined,
WriteFlags flags);
static int valueTypeCoreIndex(const QQmlProperty &that);
static int bindingIndex(const QQmlProperty &that);
diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp
index d5c0ed058c..13dad049c8 100644
--- a/src/qml/qml/qqmltypewrapper.cpp
+++ b/src/qml/qml/qqmltypewrapper.cpp
@@ -160,9 +160,8 @@ ReturnedValue QmlTypeWrapper::get(Managed *m, const StringRef name, bool *hasPro
// check for property.
return QV4::QObjectWrapper::getQmlProperty(v4->current, context, qobjectSingleton, name.getPointer(), 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::Scoped<Object> o(scope, QJSValuePrivate::get(siinfo->scriptApi(e))->getValue(engine));
+ QV4::ScopedObject o(scope, QJSValuePrivate::get(siinfo->scriptApi(e))->getValue(v4));
if (!!o)
return o->get(name);
}
@@ -203,7 +202,7 @@ ReturnedValue QmlTypeWrapper::get(Managed *m, const StringRef name, bool *hasPro
} else if (r.scriptIndex != -1) {
int index = r.scriptIndex;
if (index < context->importedScripts.count())
- return context->importedScripts.at(index).value().asReturnedValue();
+ return context->importedScripts.at(index).value();
} else if (r.importNamespace) {
return create(w->v8, object, context->imports, r.importNamespace);
}
@@ -231,6 +230,7 @@ void QmlTypeWrapper::put(Managed *m, const StringRef name, const ValueRef value)
if (!w)
v4->current->throwTypeError();
+ QV4::Scope scope(v4);
QV8Engine *v8engine = v4->v8Engine;
QQmlContextData *context = v8engine->callingContext();
@@ -239,7 +239,7 @@ void QmlTypeWrapper::put(Managed *m, const StringRef name, const ValueRef value)
QObject *object = w->object;
QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object);
if (ao)
- QV4::QObjectWrapper::setQmlProperty(v4->current, context, ao, name.getPointer(), QV4::QObjectWrapper::IgnoreRevision, *value);
+ QV4::QObjectWrapper::setQmlProperty(v4->current, context, ao, name.getPointer(), QV4::QObjectWrapper::IgnoreRevision, value);
} else if (type && type->isSingleton()) {
QQmlEngine *e = v8engine->engine();
QQmlType::SingletonInstanceInfo *siinfo = type->singletonInstanceInfo();
@@ -247,9 +247,9 @@ void QmlTypeWrapper::put(Managed *m, const StringRef name, const ValueRef value)
QObject *qobjectSingleton = siinfo->qobjectApi(e);
if (qobjectSingleton) {
- QV4::QObjectWrapper::setQmlProperty(v4->current, context, qobjectSingleton, name.getPointer(), QV4::QObjectWrapper::IgnoreRevision, *value);
+ QV4::QObjectWrapper::setQmlProperty(v4->current, context, qobjectSingleton, name.getPointer(), QV4::QObjectWrapper::IgnoreRevision, value);
} else if (!siinfo->scriptApi(e).isUndefined()) {
- QV4::Object *apiprivate = QJSValuePrivate::get(siinfo->scriptApi(e))->value.asObject();
+ QV4::ScopedObject apiprivate(scope, QJSValuePrivate::get(siinfo->scriptApi(e))->value);
if (!apiprivate) {
QString error = QLatin1String("Cannot assign to read-only property \"") + name->toQString() + QLatin1Char('\"');
v4->current->throwError(error);
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index b27d99793f..f1d2f3a85c 100644
--- a/src/qml/qml/qqmlvaluetypewrapper.cpp
+++ b/src/qml/qml/qqmlvaluetypewrapper.cpp
@@ -372,7 +372,7 @@ void QmlValueTypeWrapper::put(Managed *m, const StringRef name, const ValueRef v
QV4::ExecutionEngine::StackFrame frame = v4->currentStackFrame();
- newBinding = new QQmlBinding(*value, reference->object, context,
+ newBinding = new QQmlBinding(value, reference->object, context,
frame.source, qmlSourceCoordinate(frame.line), qmlSourceCoordinate(frame.column));
newBinding->setTarget(reference->object, cacheData, context);
newBinding->setEvaluateFlags(newBinding->evaluateFlags() |
diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp
index 1a6577d7ad..3b88e148c7 100644
--- a/src/qml/qml/qqmlvme.cpp
+++ b/src/qml/qml/qqmlvme.cpp
@@ -1087,7 +1087,7 @@ void QQmlScriptData::initialize(QQmlEngine *engine)
// If compilation throws an error, a surrounding catch will record it.
// pass 0 as the QML object, we set it later before calling run()
- QV4::Script *program = new QV4::Script(v4, 0, m_programSource, urlString, 1);
+ QV4::Script *program = new QV4::Script(v4, QV4::ObjectRef::null(), m_programSource, urlString, 1);
try {
program->parse();
} catch (QV4::Exception &) {
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp
index d70df5175b..18f3dff39d 100644
--- a/src/qml/qml/qqmlvmemetaobject.cpp
+++ b/src/qml/qml/qqmlvmemetaobject.cpp
@@ -76,7 +76,7 @@ void QQmlVMEVariantQObjectPtr::objectDestroyed(QObject *)
QV4::ExecutionEngine *v4 = m_target->varProperties.engine();
if (v4) {
QV4::Scope scope(v4);
- QV4::ScopedArrayObject a(scope, m_target->varProperties.value().asArrayObject());
+ QV4::ScopedArrayObject a(scope, m_target->varProperties.value());
if (a)
a->putIndexed(m_index - m_target->firstVarPropertyIndex, QV4::ScopedValue(scope, QV4::Value::nullValue()));
}
@@ -989,24 +989,30 @@ QV4::ReturnedValue QQmlVMEMetaObject::method(int index)
ctxt->urlString, data->lineNumber);
}
- return v8methods[index].value().asReturnedValue();
+ return v8methods[index].value();
}
QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id)
{
Q_ASSERT(id >= firstVarPropertyIndex);
- if (ensureVarPropertiesAllocated())
- return varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex);
+ if (ensureVarPropertiesAllocated()) {
+ QV4::Scope scope(QQmlEnginePrivate::get(ctxt->engine)->v4engine());
+ QV4::ScopedObject o(scope, varProperties.value());
+ return o->getIndexed(id - firstVarPropertyIndex);
+ }
return QV4::Value::undefinedValue().asReturnedValue();
}
QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id)
{
if (id >= firstVarPropertyIndex) {
- if (ensureVarPropertiesAllocated())
+ if (ensureVarPropertiesAllocated()) {
+ QV4::Scope scope(QQmlEnginePrivate::get(ctxt->engine)->v4engine());
+ QV4::ScopedObject o(scope, varProperties.value());
return QQmlEnginePrivate::get(ctxt->engine)->v8engine()->toVariant(
- QV4::Value::fromReturnedValue(varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex)), -1);
+ QV4::Value::fromReturnedValue(o->getIndexed(id - firstVarPropertyIndex)), -1);
+ }
return QVariant();
} else {
if (data[id].dataType() == QMetaType::QObjectStar) {
@@ -1026,7 +1032,8 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value)
QV4::Scope scope(varProperties.engine());
// Importantly, if the current value is a scarce resource, we need to ensure that it
// gets automatically released by the engine if no other references to it exist.
- QV4::Scoped<QV4::VariantObject> oldv(scope, varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex));
+ QV4::ScopedObject vp(scope, varProperties.value());
+ QV4::Scoped<QV4::VariantObject> oldv(scope, vp->getIndexed(id - firstVarPropertyIndex));
if (!!oldv)
oldv->removeVmePropertyReference();
@@ -1057,7 +1064,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value)
}
// Write the value and emit change signal as appropriate.
- varProperties.value().asObject()->putIndexed(id - firstVarPropertyIndex, v);
+ vp->putIndexed(id - firstVarPropertyIndex, v);
activate(object, methodOffset() + id, 0);
}
@@ -1071,7 +1078,8 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value)
// Importantly, if the current value is a scarce resource, we need to ensure that it
// gets automatically released by the engine if no other references to it exist.
- QV4::Scoped<QV4::VariantObject> oldv(scope, varProperties.value().asObject()->getIndexed(id - firstVarPropertyIndex));
+ QV4::ScopedObject vp(scope, varProperties.value());
+ QV4::Scoped<QV4::VariantObject> oldv(scope, vp->getIndexed(id - firstVarPropertyIndex));
if (!!oldv)
oldv->removeVmePropertyReference();
@@ -1083,7 +1091,7 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value)
// Write the value and emit change signal as appropriate.
QVariant currentValue = readPropertyAsVariant(id);
- varProperties.value().asObject()->putIndexed(id - firstVarPropertyIndex, newv);
+ vp->putIndexed(id - firstVarPropertyIndex, newv);
if ((currentValue.userType() != value.userType() || currentValue != value))
activate(object, methodOffset() + id, 0);
} else {
@@ -1169,7 +1177,7 @@ QV4::ReturnedValue QQmlVMEMetaObject::vmeMethod(int index)
}
// Used by debugger
-void QQmlVMEMetaObject::setVmeMethod(int index, QV4::PersistentValue function)
+void QQmlVMEMetaObject::setVmeMethod(int index, QV4::ValueRef function)
{
if (index < methodOffset()) {
Q_ASSERT(parentVMEMetaObject());
diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h
index 35592c4906..c9babc0492 100644
--- a/src/qml/qml/qqmlvmemetaobject_p.h
+++ b/src/qml/qml/qqmlvmemetaobject_p.h
@@ -166,7 +166,7 @@ public:
void registerInterceptor(int index, int valueIndex, QQmlPropertyValueInterceptor *interceptor);
QV4::ReturnedValue vmeMethod(int index);
quint16 vmeMethodLineNumber(int index);
- void setVmeMethod(int index, QV4::PersistentValue function);
+ void setVmeMethod(int index, QV4::ValueRef function);
QV4::ReturnedValue vmeProperty(int index);
void setVMEProperty(int index, const QV4::Value &v);
diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp
index 48072f53c8..10d407a48d 100644
--- a/src/qml/qml/qqmlxmlhttprequest.cpp
+++ b/src/qml/qml/qqmlxmlhttprequest.cpp
@@ -579,13 +579,14 @@ ReturnedValue NodePrototype::method_get_attributes(SimpleCallContext *ctx)
Value NodePrototype::getProto(ExecutionEngine *v4)
{
+ Scope scope(v4);
QQmlXMLHttpRequestData *d = xhrdata(v4->v8Engine);
if (d->nodePrototype.isUndefined()) {
- Object *p = new (v4->memoryManager) NodePrototype(v4);
- d->nodePrototype = Value::fromObject(p);
- v4->v8Engine->freezeObject(d->nodePrototype.value());
+ ScopedObject p(scope, new (v4->memoryManager) NodePrototype(v4));
+ d->nodePrototype = p;
+ v4->v8Engine->freezeObject(p.asValue());
}
- return d->nodePrototype.value();
+ return Value::fromReturnedValue(d->nodePrototype.value());
}
Value Node::create(QV8Engine *engine, NodeImpl *data)
@@ -631,9 +632,9 @@ Value Element::prototype(ExecutionEngine *engine)
p->setPrototype(NodePrototype::getProto(engine).asObject());
p->defineAccessorProperty(QStringLiteral("tagName"), NodePrototype::method_get_nodeName, 0);
d->elementPrototype = p;
- engine->v8Engine->freezeObject(d->elementPrototype.value());
+ engine->v8Engine->freezeObject(p.asValue());
}
- return d->elementPrototype.value();
+ return Value::fromReturnedValue(d->elementPrototype.value());
}
Value Attr::prototype(ExecutionEngine *engine)
@@ -647,9 +648,9 @@ Value Attr::prototype(ExecutionEngine *engine)
p->defineAccessorProperty(QStringLiteral("value"), method_value, 0);
p->defineAccessorProperty(QStringLiteral("ownerElement"), method_ownerElement, 0);
d->attrPrototype = p;
- engine->v8Engine->freezeObject(d->attrPrototype.value());
+ engine->v8Engine->freezeObject(p.asValue());
}
- return d->attrPrototype.value();
+ return Value::fromReturnedValue(d->attrPrototype.value());
}
ReturnedValue Attr::method_name(SimpleCallContext *ctx)
@@ -702,9 +703,9 @@ Value CharacterData::prototype(ExecutionEngine *v4)
p->defineAccessorProperty(QStringLiteral("data"), NodePrototype::method_get_nodeValue, 0);
p->defineAccessorProperty(QStringLiteral("length"), method_length, 0);
d->characterDataPrototype = p;
- v4->v8Engine->freezeObject(d->characterDataPrototype);
+ v4->v8Engine->freezeObject(p.asValue());
}
- return d->characterDataPrototype.value();
+ return Value::fromReturnedValue(d->characterDataPrototype.value());
}
ReturnedValue Text::method_isElementContentWhitespace(SimpleCallContext *ctx)
@@ -735,9 +736,9 @@ Value Text::prototype(ExecutionEngine *v4)
p->defineAccessorProperty(QStringLiteral("isElementContentWhitespace"), method_isElementContentWhitespace, 0);
p->defineAccessorProperty(QStringLiteral("wholeText"), method_wholeText, 0);
d->textPrototype = p;
- v4->v8Engine->freezeObject(d->textPrototype);
+ v4->v8Engine->freezeObject(p.asValue());
}
- return d->textPrototype.value();
+ return Value::fromReturnedValue(d->textPrototype.value());
}
Value CDATA::prototype(ExecutionEngine *v4)
@@ -749,9 +750,9 @@ Value CDATA::prototype(ExecutionEngine *v4)
Scoped<Object> p(scope, v4->newObject());
p->setPrototype(Text::prototype(v4).asObject());
d->cdataPrototype = p;
- v4->v8Engine->freezeObject(d->cdataPrototype);
+ v4->v8Engine->freezeObject(p.asValue());
}
- return d->cdataPrototype.value();
+ return Value::fromReturnedValue(d->cdataPrototype.value());
}
Value Document::prototype(ExecutionEngine *v4)
@@ -766,9 +767,9 @@ Value Document::prototype(ExecutionEngine *v4)
p->defineAccessorProperty(QStringLiteral("xmlStandalone"), method_xmlStandalone, 0);
p->defineAccessorProperty(QStringLiteral("documentElement"), method_documentElement, 0);
d->documentPrototype = p;
- v4->v8Engine->freezeObject(d->documentPrototype);
+ v4->v8Engine->freezeObject(p.asValue());
}
- return d->documentPrototype.value();
+ return Value::fromReturnedValue(d->documentPrototype.value());
}
ReturnedValue Document::load(QV8Engine *engine, const QByteArray &data)
@@ -1284,7 +1285,7 @@ ReturnedValue QQmlXMLHttpRequest::abort(const ValueRef me)
ReturnedValue QQmlXMLHttpRequest::getMe() const
{
- return m_me.value().asReturnedValue();
+ return m_me.value();
}
void QQmlXMLHttpRequest::setMe(const ValueRef me)
diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp
index b62e2150af..e8c84eee35 100644
--- a/src/qml/qml/v8/qv8engine.cpp
+++ b/src/qml/qml/v8/qv8engine.cpp
@@ -120,6 +120,8 @@ QV8Engine::~QV8Engine()
QVariant QV8Engine::toVariant(const QV4::Value &value, int typeHint)
{
Q_ASSERT (!value.isEmpty());
+ QV4::Scope scope(m_v4Engine);
+ QV4::ScopedValue v(scope, value);
if (QV4::VariantObject *v = value.as<QV4::VariantObject>())
return v->data;
@@ -131,7 +133,7 @@ QVariant QV8Engine::toVariant(const QV4::Value &value, int typeHint)
return QVariant::fromValue(QV4::JsonObject::toJsonValue(value));
if (typeHint == qMetaTypeId<QJSValue>())
- return QVariant::fromValue(QJSValue(new QJSValuePrivate(m_v4Engine, value)));
+ return QVariant::fromValue(QJSValue(new QJSValuePrivate(m_v4Engine, v)));
if (QV4::Object *object = value.asObject()) {
if (typeHint == QMetaType::QJsonObject
@@ -450,9 +452,9 @@ void QV8Engine::initializeGlobal()
" }"\
"})"
- QV4::Scoped<QV4::FunctionObject> result(scope, QV4::Script::evaluate(m_v4Engine, QString::fromUtf8(FREEZE_SOURCE), 0));
+ QV4::Scoped<QV4::FunctionObject> result(scope, QV4::Script::evaluate(m_v4Engine, QString::fromUtf8(FREEZE_SOURCE), QV4::ObjectRef::null()));
Q_ASSERT(!!result);
- m_freezeObject = result.asValue();
+ m_freezeObject = result;
#undef FREEZE_SOURCE
}
}
@@ -460,10 +462,11 @@ void QV8Engine::initializeGlobal()
void QV8Engine::freezeObject(const QV4::Value &value)
{
QV4::Scope scope(m_v4Engine);
+ QV4::ScopedFunctionObject f(scope, m_freezeObject.value());
QV4::ScopedCallData callData(scope, 1);
callData->args[0] = value;
callData->thisObject = QV4::Value::fromObject(m_v4Engine->globalObject);
- m_freezeObject.value().asFunctionObject()->call(callData);
+ f->call(callData);
}
void QV8Engine::gc()
@@ -709,6 +712,8 @@ QV4::ReturnedValue QV8Engine::metaTypeToJS(int type, const void *data)
// data must point to a place that can store a value of the given type.
// Returns true if conversion succeeded, false otherwise.
bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) {
+ QV4::Scope scope(QV8Engine::getV4(this));
+
// check if it's one of the types we know
switch (QMetaType::Type(type)) {
case QMetaType::Bool:
@@ -871,7 +876,7 @@ bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) {
*reinterpret_cast<void* *>(data) = 0;
return true;
} else if (type == qMetaTypeId<QJSValue>()) {
- *reinterpret_cast<QJSValue*>(data) = QJSValuePrivate::get(new QJSValuePrivate(m_v4Engine, value));
+ *reinterpret_cast<QJSValue*>(data) = QJSValuePrivate::get(new QJSValuePrivate(m_v4Engine, QV4::ScopedValue(scope, value)));
return true;
}