From 73a8f5f4845d34d74470b5a524d655be9eaf6dfc Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 10 Nov 2014 10:50:37 +0100 Subject: Cleanup debugger to be safe for the new GC Added a bit of convenience to PersistentValue as well. Change-Id: I5a858079543b41ce1ef48a84e9350a7d6fa64501 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4debugging.cpp | 11 +++++------ src/qml/jsruntime/qv4debugging_p.h | 2 +- src/qml/jsruntime/qv4persistent.cpp | 10 ++++++++++ src/qml/jsruntime/qv4persistent_p.h | 6 ++++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/qml/jsruntime/qv4debugging.cpp b/src/qml/jsruntime/qv4debugging.cpp index 7ef32a1c92..c906fb3581 100644 --- a/src/qml/jsruntime/qv4debugging.cpp +++ b/src/qml/jsruntime/qv4debugging.cpp @@ -152,7 +152,6 @@ public: Debugger::Debugger(QV4::ExecutionEngine *engine) : m_engine(engine) - , m_currentContext(0) , m_agent(0) , m_state(Running) , m_stepping(NotStepping) @@ -219,7 +218,7 @@ void Debugger::resume(Speed speed) if (!m_returnedValue.isUndefined()) m_returnedValue = Encode::undefined(); - m_currentContext = m_engine->currentContext(); + m_currentContext = m_engine->currentContext()->d(); m_stepping = speed; m_runningCondition.wakeAll(); } @@ -524,7 +523,7 @@ void Debugger::maybeBreakAtInstruction() switch (m_stepping) { case StepOver: - if (m_currentContext != m_engine->currentContext()) + if (m_currentContext.asManaged()->d() != m_engine->currentContext()->d()) break; // fall through case StepIn: @@ -550,7 +549,7 @@ void Debugger::enteringFunction() QMutexLocker locker(&m_lock); if (m_stepping == StepIn) { - m_currentContext = m_engine->currentContext(); + m_currentContext = m_engine->currentContext()->d(); } } @@ -563,8 +562,8 @@ void Debugger::leavingFunction(const ReturnedValue &retVal) QMutexLocker locker(&m_lock); Scope scope(m_engine); - if (m_stepping != NotStepping && m_currentContext == m_engine->currentContext()) { - m_currentContext = Scoped(scope, m_engine->currentContext()->d()->parent).getPointer(); + if (m_stepping != NotStepping && m_currentContext.asManaged()->d() == m_engine->currentContext()->d()) { + m_currentContext = m_engine->currentContext()->d()->parent; m_stepping = StepOver; m_returnedValue = retVal; } diff --git a/src/qml/jsruntime/qv4debugging_p.h b/src/qml/jsruntime/qv4debugging_p.h index 7ba95b83b8..5780dc7c0d 100644 --- a/src/qml/jsruntime/qv4debugging_p.h +++ b/src/qml/jsruntime/qv4debugging_p.h @@ -196,7 +196,7 @@ private: private: QV4::ExecutionEngine *m_engine; - QV4::ExecutionContext *m_currentContext; + QV4::PersistentValue m_currentContext; DebuggerAgent *m_agent; QMutex m_lock; QWaitCondition m_runningCondition; diff --git a/src/qml/jsruntime/qv4persistent.cpp b/src/qml/jsruntime/qv4persistent.cpp index ff10d71aae..af15804e1f 100644 --- a/src/qml/jsruntime/qv4persistent.cpp +++ b/src/qml/jsruntime/qv4persistent.cpp @@ -89,6 +89,16 @@ PersistentValue &PersistentValue::operator =(ReturnedValue other) return *this; } +PersistentValue &PersistentValue::operator=(Heap::Base *obj) +{ + if (!d) { + d = new PersistentValuePrivate(Value::fromHeapObject(obj).asReturnedValue()); + return *this; + } + d = d->detach(Value::fromHeapObject(obj).asReturnedValue()); + return *this; +} + PersistentValue::~PersistentValue() { if (d) diff --git a/src/qml/jsruntime/qv4persistent_p.h b/src/qml/jsruntime/qv4persistent_p.h index 57b30f74ec..43d1b6e374 100644 --- a/src/qml/jsruntime/qv4persistent_p.h +++ b/src/qml/jsruntime/qv4persistent_p.h @@ -81,11 +81,17 @@ public: PersistentValue &operator =(ReturnedValue other); template PersistentValue &operator=(Returned *obj); + PersistentValue &operator=(Heap::Base *obj); ~PersistentValue(); ReturnedValue value() const { return (d ? d->value.asReturnedValue() : Primitive::undefinedValue().asReturnedValue()); } + Managed *asManaged() const { + if (!d) + return 0; + return d->value.asManaged(); + } ExecutionEngine *engine() { if (!d) -- cgit v1.2.3