aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4persistent.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-01-13 09:01:29 +0100
committerLars Knoll <lars.knoll@digia.com>2015-01-13 22:42:04 +0100
commit39f1e0d66dc434e764731fbfed29c8fd98d217aa (patch)
treed9855dbedd752c23395ccb6d4d3dc8fc3bece254 /src/qml/jsruntime/qv4persistent.cpp
parenta38f9ec6c96559efa56e8f7346f74f5990810c3a (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/qv4persistent.cpp')
-rw-r--r--src/qml/jsruntime/qv4persistent.cpp108
1 files changed, 58 insertions, 50 deletions
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)