diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-01-13 09:01:29 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2015-01-13 22:42:04 +0100 |
commit | 39f1e0d66dc434e764731fbfed29c8fd98d217aa (patch) | |
tree | d9855dbedd752c23395ccb6d4d3dc8fc3bece254 /src/qml | |
parent | a38f9ec6c96559efa56e8f7346f74f5990810c3a (diff) |
Make sure we always have an engine when assigning to a Persistent
This prepares things for a rewrite of the internals of Persistent.
Change-Id: Ib93ec5911984d1bfce87ffdc3f86bc75f6ecafe9
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml')
24 files changed, 145 insertions, 135 deletions
diff --git a/src/qml/jsapi/qjsvalueiterator.cpp b/src/qml/jsapi/qjsvalueiterator.cpp index 002a84ee08..c74a5d2d76 100644 --- a/src/qml/jsapi/qjsvalueiterator.cpp +++ b/src/qml/jsapi/qjsvalueiterator.cpp @@ -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); diff --git a/src/qml/jsruntime/qv4debugging.cpp b/src/qml/jsruntime/qv4debugging.cpp index 85874d1318..9361fa1a23 100644 --- a/src/qml/jsruntime/qv4debugging.cpp +++ b/src/qml/jsruntime/qv4debugging.cpp @@ -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); } } diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp index 2627e26d4b..56e7717c26 100644 --- a/src/qml/jsruntime/qv4include.cpp +++ b/src/qml/jsruntime/qv4include.cpp @@ -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(); diff --git a/src/qml/jsruntime/qv4persistent.cpp b/src/qml/jsruntime/qv4persistent.cpp index af15804e1f..1236d2a469 100644 --- a/src/qml/jsruntime/qv4persistent.cpp +++ b/src/qml/jsruntime/qv4persistent.cpp @@ -33,16 +33,17 @@ #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) diff --git a/src/qml/jsruntime/qv4persistent_p.h b/src/qml/jsruntime/qv4persistent_p.h index 9ccab914a7..41c482fbb7 100644 --- a/src/qml/jsruntime/qv4persistent_p.h +++ b/src/qml/jsruntime/qv4persistent_p.h @@ -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) diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 284d20d975..7ec66dd0e5 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -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) { diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index 3a16eb73ce..e12b91340d 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -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) {} diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 6882061f6b..e8471ca019 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -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) { diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h index 894859ce5e..f2fd9cb7fc 100644 --- a/src/qml/jsruntime/qv4script_p.h +++ b/src/qml/jsruntime/qv4script_p.h @@ -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; diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index 3de29551ff..91fa2aa7bd 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -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() diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index 1703d0fbd5..811efcaef5 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -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]; diff --git a/src/qml/qml/qqmlboundsignal_p.h b/src/qml/qml/qqmlboundsignal_p.h index d2fec2afc8..6e0fbe90e6 100644 --- a/src/qml/qml/qqmlboundsignal_p.h +++ b/src/qml/qml/qqmlboundsignal_p.h @@ -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; diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index fd43898770..8f146b7a8a 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -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) diff --git a/src/qml/qml/qqmlexpression.cpp b/src/qml/qml/qqmlexpression.cpp index 1e31a8f638..ba561ad8e5 100644 --- a/src/qml/qml/qqmlexpression.cpp +++ b/src/qml/qml/qqmlexpression.cpp @@ -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); diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index 1745a338f3..5f8190b8dc 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -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(); } diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp index 06c446fc3b..05cfd2e2a1 100644 --- a/src/qml/qml/qqmllocale.cpp +++ b/src/qml/qml/qqmllocale.cpp @@ -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() diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index f564cd235e..8c34fc3997 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -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)); diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 4b7fe9eb04..2a000e34e1 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -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; diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 6636b3a8e4..40ae8ce35a 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -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; } diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 6b38b03357..f5451a2976 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -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() diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 9ea17d8418..d0c8c08fce 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -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 } } diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 88cb086d32..8309df8403 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -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() diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index b822c155b6..4ad2c34247 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -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); diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp index 1a7c5ca0d4..4cf34ae078 100644 --- a/src/qml/util/qqmladaptormodel.cpp +++ b/src/qml/util/qqmladaptormodel.cpp @@ -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() |