aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-05-30 22:57:15 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2013-05-31 07:05:55 +0200
commit992cf583d4c559027206ef570d623eda95a0ffa3 (patch)
tree9213d1f1f85dc4082a0780c76b0f3ff4244a351e
parentc19817473bb617d8b4663392eaf5d2dea6c71c79 (diff)
Get rid of v8::UserObjectComparisonCallback
Add a isEqualTo Method to the Managed's vtable, that will be used for comparing. Change-Id: I4d253db93851c16a57aa1412fa7142913d1744e6 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper.cpp17
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper_p.h1
-rw-r--r--src/qml/qml/v4/qv4managed.cpp7
-rw-r--r--src/qml/qml/v4/qv4managed_p.h9
-rw-r--r--src/qml/qml/v4/qv4runtime.cpp10
-rw-r--r--src/qml/qml/v4/qv4string.cpp1
-rw-r--r--src/qml/qml/v4/qv4v8.cpp25
-rw-r--r--src/qml/qml/v4/qv4v8_p.h10
-rw-r--r--src/qml/qml/v4/qv4variantobject.cpp15
-rw-r--r--src/qml/qml/v4/qv4variantobject_p.h1
-rw-r--r--src/qml/qml/v8/qv8engine.cpp30
11 files changed, 52 insertions, 74 deletions
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index 2db3a2f865..ddc22daa5e 100644
--- a/src/qml/qml/qqmlvaluetypewrapper.cpp
+++ b/src/qml/qml/qqmlvaluetypewrapper.cpp
@@ -48,6 +48,7 @@
#include <private/qv4engine_p.h>
#include <private/qv4functionobject_p.h>
+#include <private/qv4variantobject_p.h>
QT_BEGIN_NAMESPACE
@@ -146,7 +147,6 @@ Value QmlValueTypeWrapper::create(QV8Engine *v8, QObject *object, int property,
initProto(v4);
QmlValueTypeReference *r = new (v4->memoryManager) QmlValueTypeReference(v8);
- r->externalComparison = true;
r->prototype = proto.value().objectValue();
r->type = type; r->object = object; r->property = property;
return Value::fromObject(r);
@@ -158,7 +158,6 @@ Value QmlValueTypeWrapper::create(QV8Engine *v8, const QVariant &value, QQmlValu
initProto(v4);
QmlValueTypeCopy *r = new (v4->memoryManager) QmlValueTypeCopy(v8);
- r->externalComparison = true;
r->prototype = proto.value().objectValue();
r->type = type; r->value = value;
return Value::fromObject(r);
@@ -190,6 +189,20 @@ void QmlValueTypeWrapper::destroy(Managed *that)
static_cast<QmlValueTypeCopy *>(w)->~QmlValueTypeCopy();
}
+bool QmlValueTypeWrapper::isEqualTo(Managed *m, Managed *other)
+{
+ QV4::QmlValueTypeWrapper *lv = m->asQmlValueTypeWrapper();
+ assert(lv);
+
+ if (QV4::VariantObject *rv = other->asVariantObject())
+ return lv->isEqual(rv->data);
+
+ if (QV4::QmlValueTypeWrapper *v = other->asQmlValueTypeWrapper())
+ return lv->isEqual(v->toVariant());
+
+ return false;
+}
+
bool QmlValueTypeWrapper::isEqual(const QVariant& value)
{
if (objectType == QmlValueTypeWrapper::Reference) {
diff --git a/src/qml/qml/qqmlvaluetypewrapper_p.h b/src/qml/qml/qqmlvaluetypewrapper_p.h
index ca30d006f2..c75556a71b 100644
--- a/src/qml/qml/qqmlvaluetypewrapper_p.h
+++ b/src/qml/qml/qqmlvaluetypewrapper_p.h
@@ -85,6 +85,7 @@ public:
static Value get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty);
static void put(Managed *m, ExecutionContext *ctx, String *name, const Value &value);
static void destroy(Managed *that);
+ static bool isEqualTo(Managed *m, Managed *other);
static QV4::Value method_toString(SimpleCallContext *ctx);
diff --git a/src/qml/qml/v4/qv4managed.cpp b/src/qml/qml/v4/qv4managed.cpp
index 77e36a780d..1adf310858 100644
--- a/src/qml/qml/v4/qv4managed.cpp
+++ b/src/qml/qml/v4/qv4managed.cpp
@@ -62,6 +62,7 @@ const ManagedVTable Managed::static_vtbl =
0,
0,
0,
+ isEqualTo,
"Managed",
};
@@ -193,6 +194,12 @@ void Managed::setLookup(Managed *, ExecutionContext *ctx, Lookup *, const Value
ctx->throwTypeError();
}
+bool Managed::isEqualTo(Managed *, Managed *)
+{
+ return false;
+}
+
+
Value Managed::get(ExecutionContext *ctx, String *name, bool *hasProperty)
{
return vtbl->get(this, ctx, name, hasProperty);
diff --git a/src/qml/qml/v4/qv4managed_p.h b/src/qml/qml/v4/qv4managed_p.h
index ea2f4e16f9..f9641e6689 100644
--- a/src/qml/qml/v4/qv4managed_p.h
+++ b/src/qml/qml/v4/qv4managed_p.h
@@ -103,6 +103,7 @@ struct ManagedVTable
bool (*deleteIndexedProperty)(Managed *m, ExecutionContext *ctx, uint index);
void (*getLookup)(Managed *m, ExecutionContext *ctx, Lookup *l, Value *result);
void (*setLookup)(Managed *m, ExecutionContext *ctx, Lookup *l, const Value &v);
+ bool (*isEqualTo)(Managed *m, Managed *other);
const char *className;
};
@@ -124,6 +125,7 @@ const QV4::ManagedVTable classname::static_vtbl = \
deleteIndexedProperty, \
getLookup, \
setLookup, \
+ isEqualTo, \
#classname \
}
@@ -268,12 +270,16 @@ public:
void setLookup(ExecutionContext *ctx, Lookup *l, const Value &v)
{ vtbl->setLookup(this, ctx, l, v); }
+ bool isEqualTo(Managed *other)
+ { return vtbl->isEqualTo(this, other); }
+
static void destroy(Managed *that) { that->_data = 0; }
static bool hasInstance(Managed *that, ExecutionContext *ctx, const Value &value);
static Value construct(Managed *, ExecutionContext *context, Value *, int);
static Value call(Managed *, ExecutionContext *, const Value &, Value *, int);
static void getLookup(Managed *, ExecutionContext *context, Lookup *, Value *);
static void setLookup(Managed *, ExecutionContext *ctx, Lookup *l, const Value &v);
+ static bool isEqualTo(Managed *m, Managed *other);
uint internalType() const {
return type;
@@ -292,9 +298,8 @@ public:
uint strictMode : 1; // used by FunctionObject
uint type : 8;
mutable uint subtype : 3;
- uint externalComparison : 1;
uint bindingKeyFlag : 1;
- uint unused : 11;
+ uint unused : 12;
};
};
diff --git a/src/qml/qml/v4/qv4runtime.cpp b/src/qml/qml/v4/qv4runtime.cpp
index 52da74b9c1..26363df309 100644
--- a/src/qml/qml/v4/qv4runtime.cpp
+++ b/src/qml/qml/v4/qv4runtime.cpp
@@ -694,9 +694,9 @@ uint __qmljs_equal(const Value &x, const Value &y)
case Value::String_Type:
return x.stringValue()->isEqualTo(y.stringValue());
case Value::Object_Type:
- if (x.objectValue()->externalComparison && y.objectValue()->externalComparison)
- return x.objectValue()->internalClass->engine->externalResourceComparison(x, y);
- return x.objectValue() == y.objectValue();
+ if (x.objectValue() == y.objectValue())
+ return true;
+ return x.objectValue()->isEqualTo(y.objectValue());
default: // double
return x.doubleValue() == y.doubleValue();
}
@@ -744,8 +744,8 @@ Bool __qmljs_strict_equal(const Value &x, const Value &y)
return false;
if (x.isString())
return x.stringValue()->isEqualTo(y.stringValue());
- if (x.isObject() && x.objectValue()->externalComparison && y.objectValue()->externalComparison)
- return x.objectValue()->internalClass->engine->externalResourceComparison(x, y);
+ if (x.isObject())
+ return x.objectValue()->isEqualTo(y.objectValue());
return false;
}
diff --git a/src/qml/qml/v4/qv4string.cpp b/src/qml/qml/v4/qv4string.cpp
index 41682121f0..8622635041 100644
--- a/src/qml/qml/v4/qv4string.cpp
+++ b/src/qml/qml/v4/qv4string.cpp
@@ -91,6 +91,7 @@ const ManagedVTable String::static_vtbl =
deleteIndexedProperty,
0 /*getLookup*/,
0 /*setLookup*/,
+ Managed::isEqualTo,
"String",
};
diff --git a/src/qml/qml/v4/qv4v8.cpp b/src/qml/qml/v4/qv4v8.cpp
index 97379956bc..3db0b36cf0 100644
--- a/src/qml/qml/v4/qv4v8.cpp
+++ b/src/qml/qml/v4/qv4v8.cpp
@@ -1286,7 +1286,6 @@ Handle<Object> ObjectTemplate::NewInstance()
QV4::ExecutionEngine *engine = currentEngine();
QV4::Object *o = new (engine->memoryManager) V4V8Object<QV4::Object>(engine, this);
o->prototype = engine->objectPrototype;
- o->externalComparison = m_useUserComparison;
return QV4::Value::fromObject(o);
}
@@ -1362,11 +1361,6 @@ void ObjectTemplate::SetHasExternalResource(bool value)
Q_UNUSED(value);
}
-void ObjectTemplate::MarkAsUseUserObjectComparison()
-{
- m_useUserComparison = true;
-}
-
ObjectTemplate::ObjectTemplate()
{
m_namedPropertyGetter = 0;
@@ -1386,8 +1380,6 @@ ObjectTemplate::ObjectTemplate()
m_indexedPropertyQuery = 0;
m_indexedPropertyDeleter = 0;
m_indexedPropertyEnumerator = 0;
-
- m_useUserComparison = false;
}
Handle<Value> ThrowException(Handle<Value> exception)
@@ -1460,23 +1452,6 @@ Isolate *Isolate::GetCurrent()
}
-static UserObjectComparisonCallback userObjectComparisonCallback = 0;
-
-static bool v8ExternalResourceComparison(const QV4::Value &a, const QV4::Value &b)
-{
- if (!userObjectComparisonCallback)
- return false;
- Handle<Object> la = a;
- Handle<Object> lb = b;
- return userObjectComparisonCallback(la, lb);
-}
-
-void V8::SetUserObjectComparisonCallbackFunction(UserObjectComparisonCallback callback)
-{
- userObjectComparisonCallback = callback;
- currentEngine()->externalResourceComparison = v8ExternalResourceComparison;
-}
-
void V8::AddGCPrologueCallback(GCPrologueCallback, GCType)
{
// not required currently as we don't have weak Persistent references.
diff --git a/src/qml/qml/v4/qv4v8_p.h b/src/qml/qml/v4/qv4v8_p.h
index 0c3df028db..81e23702b7 100644
--- a/src/qml/qml/v4/qv4v8_p.h
+++ b/src/qml/qml/v4/qv4v8_p.h
@@ -1239,12 +1239,6 @@ class V8EXPORT ObjectTemplate : public Template {
bool HasExternalResource();
void SetHasExternalResource(bool value);
- /**
- * Mark object instances of the template as using the user object
- * comparison callback.
- */
- void MarkAsUseUserObjectComparison();
-
struct Accessor {
QV4::PersistentValue getter;
QV4::PersistentValue setter;
@@ -1275,7 +1269,6 @@ class V8EXPORT ObjectTemplate : public Template {
IndexedPropertyEnumerator m_indexedPropertyEnumerator;
QV4::PersistentValue m_indexedPropertyData;
- bool m_useUserComparison;
private:
ObjectTemplate();
};
@@ -1370,9 +1363,6 @@ class V8EXPORT Isolate {
class V8EXPORT V8 {
public:
- /** Callback for user object comparisons */
- static void SetUserObjectComparisonCallbackFunction(UserObjectComparisonCallback);
-
/**
* Enables the host application to receive a notification before a
* garbage collection. Allocations are not allowed in the
diff --git a/src/qml/qml/v4/qv4variantobject.cpp b/src/qml/qml/v4/qv4variantobject.cpp
index 99e28ddea9..c962b21f51 100644
--- a/src/qml/qml/v4/qv4variantobject.cpp
+++ b/src/qml/qml/v4/qv4variantobject.cpp
@@ -42,6 +42,7 @@
#include "qv4variantobject_p.h"
#include "qv4functionobject_p.h"
#include "qv4objectproto_p.h"
+#include <private/qqmlvaluetypewrapper_p.h>
QT_BEGIN_NAMESPACE
@@ -80,6 +81,20 @@ void VariantObject::destroy(Managed *that)
Object::destroy(that);
}
+bool VariantObject::isEqualTo(Managed *m, Managed *other)
+{
+ QV4::VariantObject *lv = m->asVariantObject();
+ assert(lv);
+
+ if (QV4::VariantObject *rv = other->asVariantObject())
+ return lv->data == rv->data;
+
+ if (QV4::QmlValueTypeWrapper *v = other->asQmlValueTypeWrapper())
+ return v->isEqual(lv->data);
+
+ return false;
+}
+
void VariantObject::addVmePropertyReference()
{
if (isScarce() && ++m_vmePropertyReferenceCount == 1) {
diff --git a/src/qml/qml/v4/qv4variantobject_p.h b/src/qml/qml/v4/qv4variantobject_p.h
index 085d06bf96..b0ff5ad406 100644
--- a/src/qml/qml/v4/qv4variantobject_p.h
+++ b/src/qml/qml/v4/qv4variantobject_p.h
@@ -77,6 +77,7 @@ public:
int m_vmePropertyReferenceCount;
static void destroy(Managed *that);
+ static bool isEqualTo(Managed *m, Managed *other);
private:
static const ManagedVTable static_vtbl;
diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp
index 4165ab6d59..1d8de37102 100644
--- a/src/qml/qml/v8/qv8engine.cpp
+++ b/src/qml/qml/v8/qv8engine.cpp
@@ -84,35 +84,6 @@ Q_DECLARE_METATYPE(QList<int>)
// QQmlEngine is not available
QT_BEGIN_NAMESPACE
-static bool ObjectComparisonCallback(v8::Handle<v8::Object> lhs, v8::Handle<v8::Object> rhs)
-{
- if (lhs == rhs)
- return true;
-
- if (lhs.IsEmpty() || rhs.IsEmpty())
- return false;
-
- if (QV4::VariantObject *lv = lhs->v4Value().asVariantObject()) {
- if (QV4::VariantObject *rv = rhs->v4Value().asVariantObject())
- return lv->data == rv->data;
-
- if (QV4::QmlValueTypeWrapper *v = rhs->v4Value().asQmlValueType())
- return v->isEqual(lv->data);
-
- return false;
- }
-
- if (QV4::QmlValueTypeWrapper *lv = lhs->v4Value().asQmlValueType()) {
- if (QV4::VariantObject *rv = rhs->v4Value().asVariantObject())
- return lv->isEqual(rv->data);
-
- if (QV4::QmlValueTypeWrapper *v = rhs->v4Value().asQmlValueType())
- return lv->isEqual(v->toVariant());
- }
-
- return false;
-}
-
QV8Engine::QV8Engine(QJSEngine* qq)
: q(qq)
@@ -130,7 +101,6 @@ QV8Engine::QV8Engine(QJSEngine* qq)
v8::Isolate::SetEngine(m_v4Engine);
m_v4Engine->publicEngine = q;
- v8::V8::SetUserObjectComparisonCallbackFunction(ObjectComparisonCallback);
QV8GCCallback::registerGcPrologueCallback();
m_strongReferencer = QV4::Value::fromObject(m_v4Engine->newObject());