Use object identity to detect cycles in JS-to-C++ type conversion
authorKent Hansen <kent.hansen@nokia.com>
Thu, 16 Aug 2012 12:11:52 +0000 (14:11 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 20 Aug 2012 11:24:31 +0000 (13:24 +0200)
commitcd6eabb2d68321536c7fbc032a2a93990e891936
tree9f3ed5952f5da0da1ed3ee4959f891fcad9d4d42
parent2791a13757912cfd0d5cc6a83f228fab5c1645ae
Use object identity to detect cycles in JS-to-C++ type conversion

The documentation for v8::Object::GetIdentityHash() states that the
hash value is not guaranteed to be unique (the current implementation
just returns a random number). Hence, the hash value should not be
used to determine whether an object has already been visited during
type conversion; in the worst (and non-deterministic) case, the
conversion will be "cut off" prematurely (due to identical hash
values for two different objects), resulting in data loss.

Instead, represent the visited objects as a set of V8 object handles.
This is safe since the type conversion is always done on the stack,
within a handle scope. Use v8::Object::GetIdentityHash() merely to
implement the qHash() specialization needed for the set.

V8 already provides an operator==() for handles, and it is documented
to return true "if the objects to which they refer are identical",
which is the behavior required by the set implementation.

Task-number: QTBUG-21681
Change-Id: I1f2a1eee8f7c197c02c2ffeaaa1fc0274e8ab740
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
src/qml/qml/v8/qv8engine.cpp
src/qml/qml/v8/qv8engine_p.h
src/qml/qml/v8/qv8jsonwrapper.cpp
src/qml/qml/v8/qv8jsonwrapper_p.h