Details
-
Sub-task
-
Resolution: Invalid
-
P2: Important
-
None
-
None
Description
If you create two QObject wrapper objects (using QScriptEngine::newQObject()) for the same C++ object, you'll get two distinct JS objects. This means that, according to ECMA-262, operator == should return false, because it compares the JS object references – nothing else. There is no way to overload operators in ECMAScript.
But QtScript does "magic" comparison when QObject and QVariant wrappers are involved, so that if the wrappers contain the same value, operator == returns true. This is also true for the C++ API (QScriptValue::equals()).
This requires some hooks/hacks in the VM that are not so nice. We'd like to drop this behavior, and introduce e.g. QObject.prototype.equals() if necessary.
Unfortunately QML also relies on this behavior. But if QML (and other applications) want operator == to work for wrapper objects, they should ensure that there's a one-to-one relationship between wrappers and real objects.
Attachments
Issue Links
- relates to
-
QTBUG-11715 [QtScript/JavaScriptCore] Add object comparison hook
-
- Closed
-