Make sure we always have an engine when assigning to a Persistent
authorLars Knoll <lars.knoll@theqtcompany.com>
Tue, 13 Jan 2015 08:01:29 +0000 (09:01 +0100)
committerLars Knoll <lars.knoll@digia.com>
Tue, 13 Jan 2015 21:42:04 +0000 (22:42 +0100)
This prepares things for a rewrite of the internals of Persistent.

Change-Id: Ib93ec5911984d1bfce87ffdc3f86bc75f6ecafe9
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
29 files changed:
src/qml/jsapi/qjsvalueiterator.cpp
src/qml/jsruntime/qv4debugging.cpp
src/qml/jsruntime/qv4include.cpp
src/qml/jsruntime/qv4persistent.cpp
src/qml/jsruntime/qv4persistent_p.h
src/qml/jsruntime/qv4qobjectwrapper.cpp
src/qml/jsruntime/qv4scopedvalue_p.h
src/qml/jsruntime/qv4script.cpp
src/qml/jsruntime/qv4script_p.h
src/qml/qml/qqmlbinding.cpp
src/qml/qml/qqmlboundsignal.cpp
src/qml/qml/qqmlboundsignal_p.h
src/qml/qml/qqmlcomponent.cpp
src/qml/qml/qqmlexpression.cpp
src/qml/qml/qqmljavascriptexpression.cpp
src/qml/qml/qqmllocale.cpp
src/qml/qml/qqmlobjectcreator.cpp
src/qml/qml/qqmltypeloader.cpp
src/qml/qml/qqmlvmemetaobject.cpp
src/qml/qml/qqmlxmlhttprequest.cpp
src/qml/qml/v8/qv8engine.cpp
src/qml/types/qqmldelegatemodel.cpp
src/qml/types/qquickworkerscript.cpp
src/qml/util/qqmladaptormodel.cpp
src/quick/items/context2d/qquickcanvasitem.cpp
src/quick/items/context2d/qquickcontext2d.cpp
src/quick/items/qquickloader.cpp
src/quick/items/qquickview.cpp
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

index 002a84e..c74a5d2 100644 (file)
@@ -52,7 +52,7 @@ QJSValueIteratorPrivate::QJSValueIteratorPrivate(const QJSValue &v)
 
     QV4::Scope scope(e);
     QV4::ScopedObject o(scope, jsp->value);
-    iterator = e->newForEachIteratorObject(o)->asReturnedValue();
+    iterator.set(e, e->newForEachIteratorObject(o));
 
     currentName = (QV4::String *)0;
     nextName = (QV4::String *)0;
@@ -216,14 +216,14 @@ QJSValueIterator& QJSValueIterator::operator=(QJSValue& object)
     d_ptr->nextName = (QV4::String *)0;
     QV4::ExecutionEngine *v4 = d_ptr->iterator.engine();
     if (!v4) {
-        d_ptr->iterator = QV4::Encode::undefined();
+        d_ptr->iterator.set(v4, QV4::Encode::undefined());
         return *this;
     }
 
     QJSValuePrivate *jsp = QJSValuePrivate::get(object);
     QV4::Scope scope(v4);
     QV4::ScopedObject o(scope, jsp->value);
-    d_ptr->iterator = v4->newForEachIteratorObject(o)->asReturnedValue();
+    d_ptr->iterator.set(v4, v4->newForEachIteratorObject(o));
     QV4::Scoped<QV4::ForEachIteratorObject> it(scope, d_ptr->iterator.value());
     it->d()->it.flags =  QV4::ObjectIterator::NoFlags;
     QV4::ScopedString nm(scope);
index 85874d1..9361fa1 100644 (file)
@@ -172,7 +172,7 @@ Debugger::Debugger(QV4::ExecutionEngine *engine)
     , m_pauseRequested(false)
     , m_haveBreakPoints(false)
     , m_breakOnThrow(false)
-    , m_returnedValue(Primitive::undefinedValue())
+    , m_returnedValue(engine, Primitive::undefinedValue())
     , m_gatherSources(0)
     , m_runningJob(0)
 {
@@ -230,9 +230,9 @@ void Debugger::resume(Speed speed)
         return;
 
     if (!m_returnedValue.isUndefined())
-        m_returnedValue = Encode::undefined();
+        m_returnedValue.set(m_engine, Encode::undefined());
 
-    m_currentContext = m_engine->currentContext();
+    m_currentContext.set(m_engine, m_engine->currentContext());
     m_stepping = speed;
     m_runningCondition.wakeAll();
 }
@@ -559,7 +559,7 @@ void Debugger::enteringFunction()
     QMutexLocker locker(&m_lock);
 
     if (m_stepping == StepIn) {
-        m_currentContext = m_engine->currentContext();
+        m_currentContext.set(m_engine, m_engine->currentContext());
     }
 }
 
@@ -571,11 +571,10 @@ void Debugger::leavingFunction(const ReturnedValue &retVal)
 
     QMutexLocker locker(&m_lock);
 
-    Scope scope(m_engine);
     if (m_stepping != NotStepping && m_currentContext.asManaged()->d() == m_engine->currentContext()) {
-        m_currentContext = m_engine->currentContext()->parent;
+        m_currentContext.set(m_engine, m_engine->currentContext()->parent);
         m_stepping = StepOver;
-        m_returnedValue = retVal;
+        m_returnedValue.set(m_engine, retVal);
     }
 }
 
index 2627e26..56e7717 100644 (file)
@@ -53,11 +53,11 @@ QV4Include::QV4Include(const QUrl &url, QV4::ExecutionEngine *engine, QQmlContex
                        const QV4::ValueRef qmlglobal, const QV4::ValueRef callback)
     : v4(engine), m_network(0), m_reply(0), m_url(url), m_redirectCount(0), m_context(context)
 {
-    m_qmlglobal = qmlglobal;
+    m_qmlglobal.set(engine, qmlglobal);
     if (callback->asFunctionObject())
-        m_callbackFunction = callback;
+        m_callbackFunction.set(engine, callback);
 
-    m_resultObject = resultValue(v4);
+    m_resultObject.set(v4, resultValue(v4));
 
     m_network = engine->v8Engine->networkAccessManager();
 
index af15804..1236d2a 100644 (file)
 
 #include "qv4persistent_p.h"
 #include "qv4mm_p.h"
+#include "qv4object_p.h"
 
 using namespace QV4;
 
-PersistentValue::PersistentValue(const ValueRef val)
-    : d(new PersistentValuePrivate(val.asReturnedValue()))
+PersistentValue::PersistentValue(ExecutionEngine *engine, const ValueRef val)
+    : d(new PersistentValuePrivate(val.asReturnedValue(), engine))
 {
 }
 
-PersistentValue::PersistentValue(ReturnedValue val)
-    : d(new PersistentValuePrivate(val))
+PersistentValue::PersistentValue(ExecutionEngine *engine, ReturnedValue val)
+    : d(new PersistentValuePrivate(val, engine))
 {
 }
 
@@ -53,6 +54,12 @@ PersistentValue::PersistentValue(const PersistentValue &other)
         d->ref();
 }
 
+PersistentValue::~PersistentValue()
+{
+    if (d)
+        d->deref();
+}
+
 PersistentValue &PersistentValue::operator=(const PersistentValue &other)
 {
     if (d == other.d)
@@ -69,45 +76,48 @@ PersistentValue &PersistentValue::operator=(const PersistentValue &other)
     return *this;
 }
 
-PersistentValue &PersistentValue::operator =(const ValueRef other)
+PersistentValue &PersistentValue::operator=(const WeakValue &other)
 {
-    if (!d) {
-        d = new PersistentValuePrivate(other.asReturnedValue());
-        return *this;
-    }
-    d = d->detach(other.asReturnedValue());
+    QV4::ExecutionEngine *engine = other.engine();
+    if (!d)
+        d = new PersistentValuePrivate(other.value(), engine);
+    else
+        d = d->detach(other.value());
     return *this;
 }
 
-PersistentValue &PersistentValue::operator =(ReturnedValue other)
+PersistentValue &PersistentValue::operator=(Object *object)
 {
-    if (!d) {
-        d = new PersistentValuePrivate(other);
-        return *this;
-    }
-    d = d->detach(other);
+    QV4::ExecutionEngine *engine = object->engine();
+    if (!d)
+        d = new PersistentValuePrivate(object->asReturnedValue(), engine);
+    else
+        d = d->detach(object->asReturnedValue());
     return *this;
 }
 
-PersistentValue &PersistentValue::operator=(Heap::Base *obj)
+void PersistentValue::set(ExecutionEngine *engine, const ValueRef val)
 {
-    if (!d) {
-        d = new PersistentValuePrivate(Value::fromHeapObject(obj).asReturnedValue());
-        return *this;
-    }
-    d = d->detach(Value::fromHeapObject(obj).asReturnedValue());
-    return *this;
+    if (!d)
+        d = new PersistentValuePrivate(val.asReturnedValue(), engine);
+    else
+        d = d->detach(val.asReturnedValue());
 }
 
-PersistentValue::~PersistentValue()
+void PersistentValue::set(ExecutionEngine *engine, ReturnedValue val)
 {
-    if (d)
-        d->deref();
+    if (!d)
+        d = new PersistentValuePrivate(val, engine);
+    else
+        d = d->detach(val);
 }
 
-WeakValue::WeakValue(const ValueRef val)
-    : d(new PersistentValuePrivate(val.asReturnedValue(), /*engine*/0, /*weak*/true))
+void PersistentValue::set(ExecutionEngine *engine, Heap::Base *obj)
 {
+    if (!d)
+        d = new PersistentValuePrivate(obj->asReturnedValue(), engine);
+    else
+        d = d->detach(obj->asReturnedValue());
 }
 
 WeakValue::WeakValue(const WeakValue &other)
@@ -117,11 +127,6 @@ WeakValue::WeakValue(const WeakValue &other)
         d->ref();
 }
 
-WeakValue::WeakValue(ReturnedValue val)
-    : d(new PersistentValuePrivate(val, /*engine*/0, /*weak*/true))
-{
-}
-
 WeakValue &WeakValue::operator=(const WeakValue &other)
 {
     if (d == other.d)
@@ -138,31 +143,34 @@ WeakValue &WeakValue::operator=(const WeakValue &other)
     return *this;
 }
 
-WeakValue &WeakValue::operator =(const ValueRef other)
+WeakValue::~WeakValue()
 {
-    if (!d) {
-        d = new PersistentValuePrivate(other.asReturnedValue(), /*engine*/0, /*weak*/true);
-        return *this;
-    }
-    d = d->detach(other.asReturnedValue(), /*weak*/true);
-    return *this;
+    if (d)
+        d->deref();
 }
 
-WeakValue &WeakValue::operator =(const ReturnedValue &other)
+void WeakValue::set(ExecutionEngine *e, const ValueRef val)
 {
-    if (!d) {
-        d = new PersistentValuePrivate(other, /*engine*/0, /*weak*/true);
-        return *this;
-    }
-    d = d->detach(other, /*weak*/true);
-    return *this;
+    if (!d)
+        d = new PersistentValuePrivate(val.asReturnedValue(), e, /*weak*/true);
+    else
+        d = d->detach(val.asReturnedValue(), /*weak*/true);
 }
 
+void WeakValue::set(ExecutionEngine *e, ReturnedValue val)
+{
+    if (!d)
+        d = new PersistentValuePrivate(val, e, /*weak*/true);
+    else
+        d = d->detach(val, /*weak*/true);
+}
 
-WeakValue::~WeakValue()
+void WeakValue::set(ExecutionEngine *e, Heap::Base *obj)
 {
-    if (d)
-        d->deref();
+    if (!d)
+        d = new PersistentValuePrivate(obj->asReturnedValue(), e, /*weak*/true);
+    else
+        d = d->detach(obj->asReturnedValue(), /*weak*/true);
 }
 
 void WeakValue::markOnce(ExecutionEngine *e)
index 9ccab91..41c482f 100644 (file)
@@ -71,15 +71,17 @@ public:
     PersistentValue() : d(0) {}
     PersistentValue(const PersistentValue &other);
     PersistentValue &operator=(const PersistentValue &other);
-
-    PersistentValue(const ValueRef val);
-    PersistentValue(ReturnedValue val);
-    PersistentValue &operator=(const ValueRef other);
-    PersistentValue &operator=(const ScopedValue &other);
-    PersistentValue &operator =(ReturnedValue other);
-    PersistentValue &operator=(Heap::Base *obj);
+    PersistentValue &operator=(const WeakValue &other);
+    PersistentValue &operator=(Object *object);
     ~PersistentValue();
 
+    PersistentValue(ExecutionEngine *engine, const ValueRef val);
+    PersistentValue(ExecutionEngine *engine, ReturnedValue val);
+
+    void set(ExecutionEngine *engine, const ValueRef val);
+    void set(ExecutionEngine *engine, ReturnedValue val);
+    void set(ExecutionEngine *engine, Heap::Base *obj);
+
     ReturnedValue value() const {
         return (d ? d->value.asReturnedValue() : Primitive::undefinedValue().asReturnedValue());
     }
@@ -89,7 +91,7 @@ public:
         return d->value.asManaged();
     }
 
-    ExecutionEngine *engine() {
+    ExecutionEngine *engine() const {
         if (!d)
             return 0;
         if (d->engine)
@@ -113,20 +115,19 @@ class Q_QML_EXPORT WeakValue
 {
 public:
     WeakValue() : d(0) {}
-    WeakValue(const ValueRef val);
     WeakValue(const WeakValue &other);
-    WeakValue(ReturnedValue val);
     WeakValue &operator=(const WeakValue &other);
-    WeakValue &operator=(const ValueRef other);
-    WeakValue &operator =(const ReturnedValue &other);
-
     ~WeakValue();
 
+    void set(ExecutionEngine *e, const ValueRef val);
+    void set(ExecutionEngine *e, ReturnedValue val);
+    void set(ExecutionEngine *e, Heap::Base *obj);
+
     ReturnedValue value() const {
         return (d ? d->value.asReturnedValue() : Primitive::undefinedValue().asReturnedValue());
     }
 
-    ExecutionEngine *engine() {
+    ExecutionEngine *engine() const {
         if (!d)
             return 0;
         if (d->engine)
index 284d20d..7ec66dd 100644 (file)
@@ -593,7 +593,7 @@ ReturnedValue QObjectWrapper::wrap(ExecutionEngine *engine, QObject *object)
                 !ddata->hasTaintedV8Object)) { // Someone else has used the QObject, but it isn't tainted
 
         QV4::ScopedValue rv(scope, create(engine, object));
-        ddata->jsWrapper = rv;
+        ddata->jsWrapper.set(scope.engine, rv);
         ddata->jsEngineId = engine->m_engineId;
         return rv.asReturnedValue();
 
@@ -608,7 +608,7 @@ ReturnedValue QObjectWrapper::wrap(ExecutionEngine *engine, QObject *object)
         // a handle in the ddata, we can assume ownership of the ddata->v8object
         if (ddata->jsWrapper.isUndefined() && !alternateWrapper) {
             QV4::ScopedValue result(scope, create(engine, object));
-            ddata->jsWrapper = result;
+            ddata->jsWrapper.set(scope.engine, result);
             ddata->jsEngineId = engine->m_engineId;
             return result.asReturnedValue();
         }
@@ -919,8 +919,8 @@ ReturnedValue QObjectWrapper::method_connect(CallContext *ctx)
     QV4::QObjectSlotDispatcher *slot = new QV4::QObjectSlotDispatcher;
     slot->signalIndex = signalIndex;
 
-    slot->thisObject = thisObject;
-    slot->function = f;
+    slot->thisObject.set(scope.engine, thisObject);
+    slot->function.set(scope.engine, f);
 
     if (QQmlData *ddata = QQmlData::get(signalObject)) {
         if (QQmlPropertyCache *propertyCache = ddata->propertyCache) {
index 3a16eb7..e12b913 100644 (file)
@@ -468,11 +468,6 @@ inline TypedValue<T> &TypedValue<T>::operator=(const TypedValue<T> &t)
     return *this;
 }
 
-inline PersistentValue &PersistentValue::operator=(const ScopedValue &other)
-{
-    return operator=(other.asReturnedValue());
-}
-
 inline ValueRef::ValueRef(const ScopedValue &v)
     : ptr(v.ptr)
 {}
index 6882061..e8471ca 100644 (file)
@@ -193,7 +193,7 @@ Heap::FunctionObject *QmlBindingWrapper::createQmlCallableForFunction(QQmlContex
 
 Script::Script(ExecutionEngine *v4, Object *qml, CompiledData::CompilationUnit *compilationUnit)
     : line(0), column(0), scope(v4->rootContext()), strictMode(false), inheritContext(true), parsed(false)
-    , qml(qml->asReturnedValue()), vmFunction(0), parseAsBinding(true)
+    , qml(v4, qml->asReturnedValue()), vmFunction(0), parseAsBinding(true)
 {
     parsed = true;
 
@@ -201,7 +201,7 @@ Script::Script(ExecutionEngine *v4, Object *qml, CompiledData::CompilationUnit *
     if (vmFunction) {
         Scope valueScope(v4);
         ScopedObject holder(valueScope, v4->memoryManager->alloc<CompilationUnitHolder>(v4, compilationUnit));
-        compilationUnitHolder = holder.asReturnedValue();
+        compilationUnitHolder.set(v4, holder);
     }
 }
 
@@ -272,7 +272,7 @@ void Script::parse()
         QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit = isel->compile();
         vmFunction = compilationUnit->linkToEngine(v4);
         ScopedObject holder(valueScope, v4->memoryManager->alloc<CompilationUnitHolder>(v4, compilationUnit));
-        compilationUnitHolder = holder.asReturnedValue();
+        compilationUnitHolder.set(v4, holder);
     }
 
     if (!vmFunction) {
index 894859c..f2fd9cb 100644 (file)
@@ -118,7 +118,7 @@ struct Q_QML_EXPORT Script {
     Script(ExecutionEngine *engine, Object *qml, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0)
         : sourceFile(source), line(line), column(column), sourceCode(sourceCode)
         , scope(engine->rootContext()), strictMode(false), inheritContext(true), parsed(false)
-        , qml(qml->asReturnedValue()), vmFunction(0), parseAsBinding(true) {}
+        , qml(engine, qml->asReturnedValue()), vmFunction(0), parseAsBinding(true) {}
     Script(ExecutionEngine *engine, Object *qml, CompiledData::CompilationUnit *compilationUnit);
     ~Script();
     QString sourceFile;
index 3de2955..91fa2aa 100644 (file)
@@ -74,7 +74,8 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContext *ctxt)
     QQmlAbstractExpression::setContext(QQmlContextData::get(ctxt));
     setScopeObject(obj);
 
-    v4function = qmlBinding(context(), obj, str, QString(), 0);
+    QV4::ExecutionEngine *v4 = QQmlEnginePrivate::get(context()->engine)->v4engine();
+    v4function.set(v4, qmlBinding(context(), obj, str, QString(), 0));
 }
 
 QQmlBinding::QQmlBinding(const QQmlScriptString &script, QObject *obj, QQmlContext *ctxt)
@@ -102,11 +103,12 @@ QQmlBinding::QQmlBinding(const QQmlScriptString &script, QObject *obj, QQmlConte
     QQmlAbstractExpression::setContext(QQmlContextData::get(ctxt ? ctxt : scriptPrivate->context));
     setScopeObject(obj ? obj : scriptPrivate->scope);
 
+    QV4::ExecutionEngine *v4 = QQmlEnginePrivate::get(context()->engine)->v4engine();
     if (runtimeFunction) {
-        v4function = QV4::QmlBindingWrapper::createQmlCallableForFunction(ctxtdata, scopeObject(), runtimeFunction);
+        v4function.set(v4, QV4::QmlBindingWrapper::createQmlCallableForFunction(ctxtdata, scopeObject(), runtimeFunction));
     } else {
         QString code = scriptPrivate->script;
-        v4function = qmlBinding(context(), scopeObject(), code, url, scriptPrivate->lineNumber);
+        v4function.set(v4, qmlBinding(context(), scopeObject(), code, url, scriptPrivate->lineNumber));
     }
 }
 
@@ -117,7 +119,8 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj, QQmlContextData *ctxt
     QQmlAbstractExpression::setContext(ctxt);
     setScopeObject(obj);
 
-    v4function = qmlBinding(ctxt, obj, str, QString(), 0);
+    QV4::ExecutionEngine *v4 = QQmlEnginePrivate::get(context()->engine)->v4engine();
+    v4function.set(v4, qmlBinding(ctxt, obj, str, QString(), 0));
 }
 
 QQmlBinding::QQmlBinding(const QString &str, QObject *obj,
@@ -130,7 +133,8 @@ QQmlBinding::QQmlBinding(const QString &str, QObject *obj,
     QQmlAbstractExpression::setContext(ctxt);
     setScopeObject(obj);
 
-    v4function = qmlBinding(ctxt, obj, str, url, lineNumber);
+    QV4::ExecutionEngine *v4 = QQmlEnginePrivate::get(context()->engine)->v4engine();
+    v4function.set(v4, qmlBinding(ctxt, obj, str, url, lineNumber));
 }
 
 QQmlBinding::QQmlBinding(const QV4::ValueRef functionPtr, QObject *obj, QQmlContextData *ctxt)
@@ -140,7 +144,7 @@ QQmlBinding::QQmlBinding(const QV4::ValueRef functionPtr, QObject *obj, QQmlCont
     QQmlAbstractExpression::setContext(ctxt);
     setScopeObject(obj);
 
-    v4function = functionPtr;
+    v4function.set(functionPtr->asObject()->engine(), functionPtr);
 }
 
 QQmlBinding::~QQmlBinding()
index 1703d0f..811efca 100644 (file)
@@ -89,7 +89,7 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
 QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, QQmlContextData *ctxt, QObject *scope, const QV4::ValueRef &function)
     : QQmlJavaScriptExpression(&QQmlBoundSignalExpression_jsvtable),
       m_index(index),
-      m_v8function(function),
+      m_function(function->asObject()->engine(), function),
       m_target(target),
       m_extra(0)
 {
@@ -113,7 +113,8 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
 
     QMetaMethod signal = QMetaObjectPrivate::signal(m_target->metaObject(), m_index);
     QString error;
-    m_v8function = QV4::QmlBindingWrapper::createQmlCallableForFunction(ctxt, scope, runtimeFunction, signal.parameterNames(), &error);
+    QV4::ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(ctxt->engine);
+    m_function.set(engine, QV4::QmlBindingWrapper::createQmlCallableForFunction(ctxt, scope, runtimeFunction, signal.parameterNames(), &error));
     if (!error.isEmpty()) {
         qmlInfo(scopeObject()) << error;
         setInvalidParameterName(true);
@@ -168,7 +169,7 @@ QString QQmlBoundSignalExpression::expression() const
     if (expressionFunctionValid()) {
         Q_ASSERT (context() && engine());
         QV4::Scope scope(QQmlEnginePrivate::get(engine())->v4engine());
-        QV4::ScopedValue v(scope, m_v8function.value());
+        QV4::ScopedValue v(scope, m_function.value());
         return v->toQStringNoThrow();
     } else {
         Q_ASSERT(!m_extra.isNull());
@@ -181,7 +182,7 @@ QV4::Function *QQmlBoundSignalExpression::function() const
     if (expressionFunctionValid()) {
         Q_ASSERT (context() && engine());
         QV4::Scope scope(QQmlEnginePrivate::get(engine())->v4engine());
-        QV4::ScopedFunctionObject v(scope, m_v8function.value());
+        QV4::ScopedFunctionObject v(scope, m_function.value());
         return v ? v->function() : 0;
     }
     return 0;
@@ -236,10 +237,10 @@ void QQmlBoundSignalExpression::evaluate(void **a)
             m_extra->m_handlerName.clear();
             m_extra->m_parameterString.clear();
 
-            m_v8function = evalFunction(context(), scopeObject(), expression,
-                                        m_extra->m_sourceLocation.sourceFile, m_extra->m_sourceLocation.line, &m_extra->m_v8qmlscope);
+            m_function.set(scope.engine, evalFunction(context(), scopeObject(), expression,
+                                                      m_extra->m_sourceLocation.sourceFile, m_extra->m_sourceLocation.line, &m_extra->m_v8qmlscope));
 
-            if (m_v8function.isNullOrUndefined()) {
+            if (m_function.isNullOrUndefined()) {
                 ep->dereferenceScarceResources();
                 return; // could not evaluate function.  Not valid.
             }
@@ -253,7 +254,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
         int *argsTypes = QQmlMetaObject(m_target).methodParameterTypes(methodIndex, dummy, 0);
         int argCount = argsTypes ? *argsTypes : 0;
 
-        QV4::ScopedValue f(scope, m_v8function.value());
+        QV4::ScopedValue f(scope, m_function.value());
         QV4::ScopedCallData callData(scope, argCount);
         for (int ii = 0; ii < argCount; ++ii) {
             int type = argsTypes[ii + 1];
index d2fec2a..6e0fbe9 100644 (file)
@@ -99,7 +99,7 @@ private:
     void setInvalidParameterName(bool v) { m_extra.setFlag2Value(v); }
 
     int m_index;
-    QV4::PersistentValue m_v8function;
+    QV4::PersistentValue m_function;
 
     QObject *m_target;
 
index fd43898..8f146b7 100644 (file)
@@ -1414,7 +1414,7 @@ QQmlComponentExtension::QQmlComponentExtension(QV4::ExecutionEngine *v4)
     proto->defineAccessorProperty(QStringLiteral("object"), QV4::QmlIncubatorObject::method_get_object, 0);
     proto->defineDefaultProperty(QStringLiteral("forceCompletion"), QV4::QmlIncubatorObject::method_forceCompletion);
 
-    incubationProto = proto;
+    incubationProto.set(v4, proto);
 }
 
 QV4::ReturnedValue QV4::QmlIncubatorObject::method_get_object(QV4::CallContext *ctx)
index 1e31a8f..ba561ad 100644 (file)
@@ -73,7 +73,8 @@ void QQmlExpressionPrivate::init(QQmlContextData *ctxt, const QString &expr, QOb
 void QQmlExpressionPrivate::init(QQmlContextData *ctxt, QV4::Function *runtimeFunction, QObject *me)
 {
     expressionFunctionValid = true;
-    function = QV4::QmlBindingWrapper::createQmlCallableForFunction(ctxt, me, runtimeFunction);
+    QV4::ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(ctxt->engine);
+    function.set(engine, QV4::QmlBindingWrapper::createQmlCallableForFunction(ctxt, me, runtimeFunction));
 
     QQmlAbstractExpression::setContext(ctxt);
     setScopeObject(me);
@@ -247,12 +248,13 @@ QV4::ReturnedValue QQmlExpressionPrivate::v4value(bool *isUndefined)
 {
     Q_Q(QQmlExpression);
 
+    QV4::ExecutionEngine *v4 = QQmlEnginePrivate::get(q->engine())->v4engine();
+
     if (!expressionFunctionValid) {
-        function = qmlBinding(context(), scopeObject(), expression, url, line, &qmlscope);
+        function.set(v4, qmlBinding(context(), scopeObject(), expression, url, line, &qmlscope));
         expressionFunctionValid = true;
     }
 
-    QV4::ExecutionEngine *v4 = QQmlEnginePrivate::get(q->engine())->v4engine();
     QV4::Scope scope(v4);
     QV4::ScopedValue f(scope, function.value());
     return evaluate(context(), f, isUndefined);
index 1745a33..5f8190b 100644 (file)
@@ -308,7 +308,7 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scopeObje
         return QV4::Encode::undefined();
     }
     if (qmlscope)
-        *qmlscope = qmlScopeObject;
+        qmlscope->set(v4, qmlScopeObject);
     return result.asReturnedValue();
 }
 
@@ -341,7 +341,7 @@ QV4::ReturnedValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt, Q
         return QV4::Encode::undefined();
     }
     if (qmlscope)
-        *qmlscope = qmlScopeObject;
+        qmlscope->set(v4, qmlScopeObject);
     return result.asReturnedValue();
 }
 
index 06c446f..05cfd2e 100644 (file)
@@ -683,7 +683,7 @@ QV4LocaleDataDeletable::QV4LocaleDataDeletable(QV4::ExecutionEngine *engine)
     o->defineAccessorProperty(QStringLiteral("measurementSystem"), QQmlLocaleData::method_get_measurementSystem, 0);
     o->defineAccessorProperty(QStringLiteral("exponential"), QQmlLocaleData::method_get_exponential, 0);
 
-    prototype = o;
+    prototype.set(engine, o);
 }
 
 QV4LocaleDataDeletable::~QV4LocaleDataDeletable()
index f564cd2..8c34fc3 100644 (file)
@@ -208,7 +208,7 @@ QObject *QQmlObjectCreator::create(int subComponentIndex, QObject *parent, QQmlI
 
     if (subComponentIndex == -1) {
         QV4::ScopedObject scripts(scope, v4->newArrayObject(compiledData->scripts.count()));
-        context->importedScripts = scripts;
+        context->importedScripts.set(v4, scripts);
         for (int i = 0; i < compiledData->scripts.count(); ++i) {
             QQmlScriptData *s = compiledData->scripts.at(i);
             scripts->putIndexed(i, s->scriptValueForContext(context));
index 4b7fe9e..2a000e3 100644 (file)
@@ -2504,7 +2504,7 @@ QV4::PersistentValue QQmlScriptData::scriptValueForContext(QQmlContextData *pare
     QV4::ScopedObject scriptsArray(scope);
     if (ctxt->importedScripts.isNullOrUndefined()) {
         scriptsArray = v4->newArrayObject(scripts.count());
-        ctxt->importedScripts = scriptsArray;
+        ctxt->importedScripts.set(v4, scriptsArray);
     } else {
         scriptsArray = ctxt->importedScripts;
     }
@@ -2523,7 +2523,7 @@ QV4::PersistentValue QQmlScriptData::scriptValueForContext(QQmlContextData *pare
     QV4::ScopedValue qmlglobal(scope, QV4::QmlContextWrapper::qmlScope(v4, ctxt, 0));
     QV4::QmlContextWrapper::takeContextOwnership(qmlglobal);
 
-    m_program->qml = qmlglobal;
+    m_program->qml.set(scope.engine, qmlglobal);
     m_program->run();
     if (scope.engine->hasException) {
         QQmlError error = scope.engine->catchExceptionAsQmlError();
@@ -2531,7 +2531,7 @@ QV4::PersistentValue QQmlScriptData::scriptValueForContext(QQmlContextData *pare
             ep->warning(error);
     }
 
-    rv = qmlglobal;
+    rv.set(scope.engine, qmlglobal);
     if (shared) {
         m_value = rv;
         m_loaded = true;
index 6636b3a..40ae8ce 100644 (file)
@@ -608,7 +608,7 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj,
 
             QV4::Function *runtimeFunction = compilationUnit->runtimeFunctions[data->runtimeFunctionIndex];
             o = QV4::FunctionObject::createScriptFunction(qmlBindingContext, runtimeFunction);
-            v8methods[index] = o;
+            v8methods[index].set(qmlBindingContext->engine(), o);
         }
     }
 }
@@ -1183,7 +1183,7 @@ void QQmlVMEMetaObject::setVmeMethod(int index, QV4::ValueRef function)
         v8methods = new QV4::PersistentValue[metaData->methodCount];
 
     int methodIndex = index - methodOffset() - plainSignals;
-    v8methods[methodIndex] = function;
+    v8methods[methodIndex].set(function->asObject()->engine(), function);
 }
 
 QV4::ReturnedValue QQmlVMEMetaObject::vmeProperty(int index)
@@ -1253,7 +1253,7 @@ void QQmlVMEMetaObject::allocateVarPropertiesArray()
     assert(qml);
     QV4::ExecutionEngine *v4 = QV8Engine::getV4(qml->handle());
     QV4::Scope scope(v4);
-    varProperties = QV4::ScopedValue(scope, v4->newArrayObject(metaData->varPropertyCount));
+    varProperties.set(scope.engine, v4->newArrayObject(metaData->varPropertyCount));
     varPropertiesInitialized = true;
 }
 
index 6b38b03..f5451a2 100644 (file)
@@ -589,7 +589,7 @@ ReturnedValue NodePrototype::getProto(ExecutionEngine *v4)
     QQmlXMLHttpRequestData *d = xhrdata(v4);
     if (d->nodePrototype.isUndefined()) {
         ScopedObject p(scope, v4->memoryManager->alloc<NodePrototype>(v4));
-        d->nodePrototype = p;
+        d->nodePrototype.set(v4, p);
         v4->v8Engine->freezeObject(p);
     }
     return d->nodePrototype.value();
@@ -638,7 +638,7 @@ ReturnedValue Element::prototype(ExecutionEngine *engine)
         ScopedObject pp(scope);
         p->setPrototype((pp = NodePrototype::getProto(engine)));
         p->defineAccessorProperty(QStringLiteral("tagName"), NodePrototype::method_get_nodeName, 0);
-        d->elementPrototype = p;
+        d->elementPrototype.set(engine, p);
         engine->v8Engine->freezeObject(p);
     }
     return d->elementPrototype.value();
@@ -655,7 +655,7 @@ ReturnedValue Attr::prototype(ExecutionEngine *engine)
         p->defineAccessorProperty(QStringLiteral("name"), method_name, 0);
         p->defineAccessorProperty(QStringLiteral("value"), method_value, 0);
         p->defineAccessorProperty(QStringLiteral("ownerElement"), method_ownerElement, 0);
-        d->attrPrototype = p;
+        d->attrPrototype.set(engine, p);
         engine->v8Engine->freezeObject(p);
     }
     return d->attrPrototype.value();
@@ -711,7 +711,7 @@ ReturnedValue CharacterData::prototype(ExecutionEngine *v4)
         p->setPrototype((pp = NodePrototype::getProto(v4)));
         p->defineAccessorProperty(QStringLiteral("data"), NodePrototype::method_get_nodeValue, 0);
         p->defineAccessorProperty(QStringLiteral("length"), method_length, 0);
-        d->characterDataPrototype = p;
+        d->characterDataPrototype.set(v4, p);
         v4->v8Engine->freezeObject(p);
     }
     return d->characterDataPrototype.value();
@@ -746,7 +746,7 @@ ReturnedValue Text::prototype(ExecutionEngine *v4)
         p->setPrototype((pp = CharacterData::prototype(v4)));
         p->defineAccessorProperty(QStringLiteral("isElementContentWhitespace"), method_isElementContentWhitespace, 0);
         p->defineAccessorProperty(QStringLiteral("wholeText"), method_wholeText, 0);
-        d->textPrototype = p;
+        d->textPrototype.set(v4, p);
         v4->v8Engine->freezeObject(p);
     }
     return d->textPrototype.value();
@@ -761,7 +761,7 @@ ReturnedValue CDATA::prototype(ExecutionEngine *v4)
         ScopedObject p(scope, v4->newObject());
         ScopedObject pp(scope);
         p->setPrototype((pp = Text::prototype(v4)));
-        d->cdataPrototype = p;
+        d->cdataPrototype.set(v4, p);
         v4->v8Engine->freezeObject(p);
     }
     return d->cdataPrototype.value();
@@ -779,7 +779,7 @@ ReturnedValue Document::prototype(ExecutionEngine *v4)
         p->defineAccessorProperty(QStringLiteral("xmlEncoding"), method_xmlEncoding, 0);
         p->defineAccessorProperty(QStringLiteral("xmlStandalone"), method_xmlStandalone, 0);
         p->defineAccessorProperty(QStringLiteral("documentElement"), method_documentElement, 0);
-        d->documentPrototype = p;
+        d->documentPrototype.set(v4, p);
         v4->v8Engine->freezeObject(p);
     }
     return d->documentPrototype.value();
@@ -1308,7 +1308,7 @@ ReturnedValue QQmlXMLHttpRequest::getMe() const
 
 void QQmlXMLHttpRequest::setMe(const ValueRef me)
 {
-    m_me = me;
+    m_me.set(v4, me);
 }
 
 void QQmlXMLHttpRequest::readyRead()
index 9ea17d8..d0c8c08 100644 (file)
@@ -217,7 +217,7 @@ void QV8Engine::initializeGlobal()
 
         QV4::ScopedFunctionObject result(scope, QV4::Script::evaluate(m_v4Engine, QString::fromUtf8(FREEZE_SOURCE), 0));
         Q_ASSERT(!!result);
-        m_freezeObject = result;
+        m_freezeObject.set(scope.engine, result);
 #undef FREEZE_SOURCE
     }
 }
index 88cb086..8309df8 100644 (file)
@@ -1757,7 +1757,7 @@ void QQmlDelegateModelItemMetaType::initializePrototype()
         p->setSetter(0);
         proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
     }
-    modelItemProto = proto;
+    modelItemProto.set(v4, proto);
 }
 
 int QQmlDelegateModelItemMetaType::parseGroups(const QStringList &groups) const
@@ -3341,7 +3341,7 @@ QQmlDelegateModelEngineData::QQmlDelegateModelEngineData(QV4::ExecutionEngine *v
     proto->defineAccessorProperty(QStringLiteral("index"), QQmlDelegateModelGroupChange::method_get_index, 0);
     proto->defineAccessorProperty(QStringLiteral("count"), QQmlDelegateModelGroupChange::method_get_count, 0);
     proto->defineAccessorProperty(QStringLiteral("moveId"), QQmlDelegateModelGroupChange::method_get_moveId, 0);
-    changeProto = proto;
+    changeProto.set(v4, proto);
 }
 
 QQmlDelegateModelEngineData::~QQmlDelegateModelEngineData()
index b822c15..4ad2c34 100644 (file)
@@ -222,7 +222,7 @@ void QQuickWorkerScriptEnginePrivate::WorkerEngine::init()
 
     QV4::Scope scope(m_v4Engine);
     QV4::ScopedContext globalContext(scope, scope.engine->rootContext());
-    onmessage = QV4::Script(globalContext, QString::fromUtf8(CALL_ONMESSAGE_SCRIPT)).run(); // do not use QStringLiteral here, MSVC2012 cannot apply this cleanly to the macro
+    onmessage.set(scope.engine, QV4::Script(globalContext, QString::fromUtf8(CALL_ONMESSAGE_SCRIPT)).run()); // do not use QStringLiteral here, MSVC2012 cannot apply this cleanly to the macro
     Q_ASSERT(!scope.engine->hasException);
     QV4::Script createsendscript(globalContext, QString::fromUtf8(SEND_MESSAGE_CREATE_SCRIPT)); // do not use QStringLiteral here, MSVC2012 cannot apply this cleanly to the macro
     QV4::ScopedFunctionObject createsendconstructor(scope, createsendscript.run());
@@ -233,7 +233,7 @@ void QQuickWorkerScriptEnginePrivate::WorkerEngine::init()
     QV4::ScopedCallData callData(scope, 1);
     callData->args[0] = function;
     callData->thisObject = global();
-    createsend = createsendconstructor->call(callData);
+    createsend.set(scope.engine, createsendconstructor->call(callData));
 }
 
 // Requires handle and context scope
@@ -300,7 +300,7 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::getWorker(WorkerScript *scri
         QV4::ExecutionEngine *v4 = QV8Engine::getV4(workerEngine);
         QV4::Scope scope(v4);
 
-        script->object = QV4::QmlContextWrapper::urlScope(v4, script->source);
+        script->object.set(v4, QV4::QmlContextWrapper::urlScope(v4, script->source));
 
         QV4::Scoped<QV4::QmlContextWrapper> w(scope, script->object.value());
         Q_ASSERT(!!w);
index 1a7c5ca..4cf34ae 100644 (file)
@@ -226,7 +226,7 @@ public:
             p->setSetter(s);
             proto->insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotEnumerable|QV4::Attr_NotConfigurable);
         }
-        prototype = proto;
+        prototype.set(v4, proto);
     }
 
     // QAbstractDynamicMetaObject
@@ -963,7 +963,7 @@ QQmlAdaptorModelEngineData::QQmlAdaptorModelEngineData(QV4::ExecutionEngine *v4)
     proto->defineAccessorProperty(QStringLiteral("index"), get_index, 0);
     proto->defineAccessorProperty(QStringLiteral("modelData"),
                                   QQmlDMListAccessorData::get_modelData, QQmlDMListAccessorData::set_modelData);
-    listItemProto = proto;
+    listItemProto.set(v4, proto);
 }
 
 QQmlAdaptorModelEngineData::~QQmlAdaptorModelEngineData()
index 2688c72..f8ed81d 100644 (file)
@@ -864,7 +864,7 @@ void QQuickCanvasItem::requestAnimationFrame(QQmlV4Function *args)
 
     static int id = 0;
 
-    d->animationCallbacks.insert(++id, QV4::PersistentValue(f));
+    d->animationCallbacks.insert(++id, QV4::PersistentValue(scope.engine, f));
 
     if (isVisible())
         polish();
index e46aa53..da4212e 100644 (file)
@@ -1390,13 +1390,13 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_fillStyle(QV4::CallContext *ctx
        if (color.isValid()) {
            r->d()->context->state.fillStyle = color;
            r->d()->context->buffer()->setFillStyle(color);
-           r->d()->context->m_fillStyle = value;
+           r->d()->context->m_fillStyle.set(scope.engine, value);
        } else {
            QV4::Scoped<QQuickContext2DStyle> style(scope, value->as<QQuickContext2DStyle>());
            if (style && style->d()->brush != r->d()->context->state.fillStyle) {
                r->d()->context->state.fillStyle = style->d()->brush;
                r->d()->context->buffer()->setFillStyle(style->d()->brush, style->d()->patternRepeatX, style->d()->patternRepeatY);
-               r->d()->context->m_fillStyle = value;
+               r->d()->context->m_fillStyle.set(scope.engine, value);
                r->d()->context->state.fillPatternRepeatX = style->d()->patternRepeatX;
                r->d()->context->state.fillPatternRepeatY = style->d()->patternRepeatY;
            }
@@ -1406,7 +1406,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_fillStyle(QV4::CallContext *ctx
        if (color.isValid() && r->d()->context->state.fillStyle != QBrush(color)) {
             r->d()->context->state.fillStyle = QBrush(color);
             r->d()->context->buffer()->setFillStyle(r->d()->context->state.fillStyle);
-            r->d()->context->m_fillStyle = value;
+            r->d()->context->m_fillStyle.set(scope.engine, value);
        }
    }
    return QV4::Encode::undefined();
@@ -1499,13 +1499,13 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_strokeStyle(QV4::CallContext *c
         if (color.isValid()) {
             r->d()->context->state.fillStyle = color;
             r->d()->context->buffer()->setStrokeStyle(color);
-            r->d()->context->m_strokeStyle = value;
+            r->d()->context->m_strokeStyle.set(scope.engine, value);
         } else {
             QV4::Scoped<QQuickContext2DStyle> style(scope, value->as<QQuickContext2DStyle>());
             if (style && style->d()->brush != r->d()->context->state.strokeStyle) {
                 r->d()->context->state.strokeStyle = style->d()->brush;
                 r->d()->context->buffer()->setStrokeStyle(style->d()->brush, style->d()->patternRepeatX, style->d()->patternRepeatY);
-                r->d()->context->m_strokeStyle = value;
+                r->d()->context->m_strokeStyle.set(scope.engine, value);
                 r->d()->context->state.strokePatternRepeatX = style->d()->patternRepeatX;
                 r->d()->context->state.strokePatternRepeatY = style->d()->patternRepeatY;
 
@@ -1516,7 +1516,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_strokeStyle(QV4::CallContext *c
         if (color.isValid() && r->d()->context->state.strokeStyle != QBrush(color)) {
              r->d()->context->state.strokeStyle = QBrush(color);
              r->d()->context->buffer()->setStrokeStyle(r->d()->context->state.strokeStyle);
-             r->d()->context->m_strokeStyle = value;
+             r->d()->context->m_strokeStyle.set(scope.engine, value);
         }
     }
     return QV4::Encode::undefined();
@@ -2076,7 +2076,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_path(QV4::CallContext *ctx)
         QString path =value->toQStringNoThrow();
         QQuickSvgParser::parsePathDataFast(path, r->d()->context->m_path);
     }
-    r->d()->context->m_v4path = value;
+    r->d()->context->m_v4path.set(scope.engine, value);
     return QV4::Encode::undefined();
 }
 
index 906126b..4123f25 100644 (file)
@@ -466,7 +466,7 @@ void QQuickLoader::setSourceComponent(QQmlComponent *comp)
     d->component = comp;
     if (comp) {
         if (QQmlData *ddata = QQmlData::get(comp))
-            d->componentStrongReference = ddata->jsWrapper.value();
+            d->componentStrongReference = ddata->jsWrapper;
     }
     d->loadingFromSource = false;
 
@@ -574,8 +574,8 @@ void QQuickLoader::setSource(QQmlV4Function *args)
     QUrl sourceUrl = d->resolveSourceUrl(args);
     if (!ipv->isUndefined()) {
         d->disposeInitialPropertyValues();
-        d->initialPropertyValues = ipv.asReturnedValue();
-        d->qmlGlobalForIpv = args->qmlGlobal();
+        d->initialPropertyValues.set(args->v4engine(), ipv);
+        d->qmlGlobalForIpv.set(args->v4engine(), args->qmlGlobal());
     }
 
     setSource(sourceUrl, false); // already cleared and set ipv above.
index 0a16457..245fa48 100644 (file)
@@ -83,7 +83,7 @@ void QQuickViewPrivate::init(QQmlEngine* e)
         QV4::ExecutionEngine *v4 = QQmlEnginePrivate::getV4Engine(engine.data());
         QV4::Scope scope(v4);
         QV4::Scoped<QV4::QQuickRootItemMarker> v(scope, QV4::QQuickRootItemMarker::create(engine.data(), q));
-        rootItemMarker = v;
+        rootItemMarker.set(v4, v);
     }
 
     if (QQmlDebugService::isDebuggingEnabled())
index 81e5439..e137f6b 100644 (file)
@@ -5075,9 +5075,9 @@ void tst_qqmlecmascript::propertyVarInheritance()
         // XXX NOTE: this is very implementation dependent.  QDVMEMO->vmeProperty() is the only
         // public function which can return us a handle to something in the varProperties array.
         QV4::ReturnedValue tmp = icovmemo->vmeProperty(ico5->metaObject()->indexOfProperty("circ"));
-        icoCanaryHandle = tmp;
+        icoCanaryHandle.set(QQmlEnginePrivate::getV4Engine(&engine), tmp);
         tmp = ccovmemo->vmeProperty(cco5->metaObject()->indexOfProperty("circ"));
-        ccoCanaryHandle = tmp;
+        ccoCanaryHandle.set(QQmlEnginePrivate::getV4Engine(&engine), tmp);
         tmp = QV4::Encode::null();
         QVERIFY(!icoCanaryHandle.isUndefined());
         QVERIFY(!ccoCanaryHandle.isUndefined());
@@ -5115,7 +5115,8 @@ void tst_qqmlecmascript::propertyVarInheritance2()
     QCOMPARE(childObject->property("textCanary").toInt(), 10);
     QV4::WeakValue childObjectVarArrayValueHandle;
     {
-        childObjectVarArrayValueHandle = QQmlVMEMetaObject::get(childObject)->vmeProperty(childObject->metaObject()->indexOfProperty("vp"));
+        childObjectVarArrayValueHandle.set(QQmlEnginePrivate::getV4Engine(&engine),
+                                           QQmlVMEMetaObject::get(childObject)->vmeProperty(childObject->metaObject()->indexOfProperty("vp")));
         QVERIFY(!childObjectVarArrayValueHandle.isUndefined());
         gc(engine);
         QVERIFY(!childObjectVarArrayValueHandle.isUndefined()); // should not have been collected yet.