summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-09-21 10:56:11 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-09-21 14:29:16 (GMT)
commit65b4ce3c51283adb76dcb73cc654b06359b1ae00 (patch)
treec71e10c6da5f986cc83ab520efce3a5952114efe /src/script
parent1b34feacef7a2d3ac005449a7cfbcb08a6bbf947 (diff)
downloadQt-65b4ce3c51283adb76dcb73cc654b06359b1ae00.zip
Qt-65b4ce3c51283adb76dcb73cc654b06359b1ae00.tar.gz
Qt-65b4ce3c51283adb76dcb73cc654b06359b1ae00.tar.bz2
QtScript: Fix comparing QVariant and QObject.
This add a hook inside JSC to be able to implement our own comparison function when comparing objects. Reviewed-by: Kent Hansen
Diffstat (limited to 'src/script')
-rw-r--r--src/script/bridge/qscriptobject.cpp14
-rw-r--r--src/script/bridge/qscriptobject_p.h4
-rw-r--r--src/script/bridge/qscriptqobject.cpp12
-rw-r--r--src/script/bridge/qscriptqobject_p.h2
-rw-r--r--src/script/bridge/qscriptvariant.cpp8
-rw-r--r--src/script/bridge/qscriptvariant_p.h2
6 files changed, 42 insertions, 0 deletions
diff --git a/src/script/bridge/qscriptobject.cpp b/src/script/bridge/qscriptobject.cpp
index d46765a..0807dc2 100644
--- a/src/script/bridge/qscriptobject.cpp
+++ b/src/script/bridge/qscriptobject.cpp
@@ -145,6 +145,15 @@ void QScriptObject::getPropertyNames(JSC::ExecState* exec, JSC::PropertyNameArra
d->delegate->getPropertyNames(this, exec, propertyNames, listedAttributes);
}
+bool QScriptObject::compareToObject(JSC::ExecState* exec, JSC::JSObject *other)
+{
+ if (!d || !d->delegate) {
+ return JSC::JSObject::compareToObject(exec, other);
+ }
+ return d->delegate->compareToObject(this, exec, other);
+}
+
+
void QScriptObject::mark()
{
Q_ASSERT(!marked());
@@ -255,4 +264,9 @@ bool QScriptObjectDelegate::hasInstance(QScriptObject* object, JSC::ExecState* e
return object->JSC::JSObject::hasInstance(exec, value, proto);
}
+bool QScriptObjectDelegate::compareToObject(QScriptObject* object, JSC::ExecState* exec, JSC::JSObject* o)
+{
+ return object->JSC::JSObject::compareToObject(exec, o);
+}
+
QT_END_NAMESPACE
diff --git a/src/script/bridge/qscriptobject_p.h b/src/script/bridge/qscriptobject_p.h
index 8f4113f..8060914 100644
--- a/src/script/bridge/qscriptobject_p.h
+++ b/src/script/bridge/qscriptobject_p.h
@@ -108,6 +108,8 @@ public:
QScriptObjectDelegate *delegate() const;
void setDelegate(QScriptObjectDelegate *delegate);
+ virtual bool compareToObject(JSC::ExecState*, JSC::JSObject*);
+
protected:
Data *d;
};
@@ -151,6 +153,8 @@ public:
virtual bool hasInstance(QScriptObject*, JSC::ExecState*,
JSC::JSValue value, JSC::JSValue proto);
+ virtual bool compareToObject(QScriptObject*, JSC::ExecState*, JSC::JSObject*);
+
private:
Q_DISABLE_COPY(QScriptObjectDelegate)
};
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp
index b7df781..236f899 100644
--- a/src/script/bridge/qscriptqobject.cpp
+++ b/src/script/bridge/qscriptqobject.cpp
@@ -1572,6 +1572,18 @@ void QObjectDelegate::mark(QScriptObject *object)
QScriptObjectDelegate::mark(object);
}
+bool QObjectDelegate::compareToObject(QScriptObject *, JSC::ExecState *exec, JSC::JSObject *o2)
+{
+ if(!o2->inherits(&QScriptObject::info))
+ return false;
+ QScriptObject *object = static_cast<QScriptObject*>(o2);
+ QScriptObjectDelegate *delegate = object->delegate();
+ if (!delegate || (delegate->type() != QScriptObjectDelegate::QtObject))
+ return false;
+ return value() == static_cast<QObjectDelegate *>(delegate)->value();
+}
+
+
static JSC::JSValue JSC_HOST_CALL qobjectProtoFuncFindChild(JSC::ExecState *exec, JSC::JSObject*,
JSC::JSValue thisValue, const JSC::ArgList &args)
{
diff --git a/src/script/bridge/qscriptqobject_p.h b/src/script/bridge/qscriptqobject_p.h
index ef26c7d..72d066d 100644
--- a/src/script/bridge/qscriptqobject_p.h
+++ b/src/script/bridge/qscriptqobject_p.h
@@ -122,6 +122,8 @@ public:
inline void setOptions(QScriptEngine::QObjectWrapOptions options)
{ data->options = options; }
+ virtual bool compareToObject(QScriptObject*, JSC::ExecState*, JSC::JSObject*);
+
protected:
Data *data;
};
diff --git a/src/script/bridge/qscriptvariant.cpp b/src/script/bridge/qscriptvariant.cpp
index 583b61c..aa7ad94 100644
--- a/src/script/bridge/qscriptvariant.cpp
+++ b/src/script/bridge/qscriptvariant.cpp
@@ -148,6 +148,13 @@ static JSC::JSValue JSC_HOST_CALL variantProtoFuncToString(JSC::ExecState *exec,
return JSC::jsString(exec, result);
}
+bool QVariantDelegate::compareToObject(QScriptObject *, JSC::ExecState *exec, JSC::JSObject *o2)
+{
+ const QVariant &variant1 = value();
+ return variant1 == scriptEngineFromExec(exec)->scriptValueFromJSCValue(o2).toVariant();
+}
+
+
QVariantPrototype::QVariantPrototype(JSC::ExecState* exec, WTF::PassRefPtr<JSC::Structure> structure,
JSC::Structure* prototypeFunctionStructure)
: QScriptObject(structure)
@@ -158,6 +165,7 @@ QVariantPrototype::QVariantPrototype(JSC::ExecState* exec, WTF::PassRefPtr<JSC::
putDirectFunction(exec, new (exec) JSC::PrototypeFunction(exec, prototypeFunctionStructure, 0, exec->propertyNames().valueOf, variantProtoFuncValueOf), JSC::DontEnum);
}
+
} // namespace QScript
QT_END_NAMESPACE
diff --git a/src/script/bridge/qscriptvariant_p.h b/src/script/bridge/qscriptvariant_p.h
index 9325396..4ce0aa6 100644
--- a/src/script/bridge/qscriptvariant_p.h
+++ b/src/script/bridge/qscriptvariant_p.h
@@ -73,6 +73,8 @@ public:
Type type() const;
+ bool compareToObject(QScriptObject*, JSC::ExecState*, JSC::JSObject*);
+
private:
QVariant m_value;
};