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/jsruntime | |
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/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4debugging.cpp | 13 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4include.cpp | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4persistent.cpp | 108 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4persistent_p.h | 29 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 8 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 5 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script_p.h | 2 |
8 files changed, 90 insertions, 87 deletions
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; |