From: Lars Knoll Date: Thu, 11 Dec 2014 09:55:32 +0000 (+0100) Subject: Use pointers to Heap object to avoid recursion X-Git-Tag: v5.5.90+alpha1~631 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=234e933b1527510bc487435a9e46c4338d7b9701;p=platform%2Fupstream%2Fqtdeclarative.git Use pointers to Heap object to avoid recursion Change-Id: If491b35ba43758bd4792166f7213cd5a11d227d9 Reviewed-by: Simon Hausmann --- diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index 26cfe10..a34faee 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -1017,14 +1017,14 @@ QJsonObject JsonObject::toJsonObject(Object *o, V4ObjectSet &visitedObjects) Scope scope(o->engine()); - if (visitedObjects.contains(o)) { + if (visitedObjects.contains(o->d())) { // Avoid recursion. // For compatibility with QVariant{List,Map} conversion, we return an // empty object (and no error is thrown). return result; } - visitedObjects.insert(o); + visitedObjects.insert(o->d()); ObjectIterator it(scope, o, ObjectIterator::EnumerableOnly); ScopedValue name(scope); @@ -1039,7 +1039,7 @@ QJsonObject JsonObject::toJsonObject(Object *o, V4ObjectSet &visitedObjects) result.insert(key, toJsonValue(val, visitedObjects)); } - visitedObjects.remove(o); + visitedObjects.remove(o->d()); return result; } @@ -1065,14 +1065,14 @@ QJsonArray JsonObject::toJsonArray(ArrayObject *a, V4ObjectSet &visitedObjects) Scope scope(a->engine()); - if (visitedObjects.contains(a)) { + if (visitedObjects.contains(a->d())) { // Avoid recursion. // For compatibility with QVariant{List,Map} conversion, we return an // empty array (and no error is thrown). return result; } - visitedObjects.insert(a); + visitedObjects.insert(a->d()); ScopedValue v(scope); quint32 length = a->getLength(); @@ -1083,7 +1083,7 @@ QJsonArray JsonObject::toJsonArray(ArrayObject *a, V4ObjectSet &visitedObjects) result.append(toJsonValue(v, visitedObjects)); } - visitedObjects.remove(a); + visitedObjects.remove(a->d()); return result; } diff --git a/src/qml/jsruntime/qv4jsonobject_p.h b/src/qml/jsruntime/qv4jsonobject_p.h index 4004a06..32d890c 100644 --- a/src/qml/jsruntime/qv4jsonobject_p.h +++ b/src/qml/jsruntime/qv4jsonobject_p.h @@ -54,7 +54,8 @@ struct JsonObject : Object { Q_MANAGED_TYPE(JsonObject) V4_OBJECT2(JsonObject, Object) private: - typedef QSet V4ObjectSet; + // ### GC + typedef QSet V4ObjectSet; public: static ReturnedValue method_parse(CallContext *ctx); diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index ed0f50f..5e9e20b 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -259,7 +259,7 @@ QVariant QV8Engine::objectToVariant(QV4::Object *o, V8ObjectSet *visitedObjects) V8ObjectSet recursionGuardSet; if (!visitedObjects) { visitedObjects = &recursionGuardSet; - } else if (visitedObjects->contains(o)) { + } else if (visitedObjects->contains(o->d())) { // Avoid recursion. // For compatibility with QVariant{List,Map} conversion, we return an // empty object (and no error is thrown). @@ -267,7 +267,7 @@ QVariant QV8Engine::objectToVariant(QV4::Object *o, V8ObjectSet *visitedObjects) return QVariantList(); return QVariantMap(); } - visitedObjects->insert(o); + visitedObjects->insert(o->d()); QVariant result; @@ -302,7 +302,7 @@ QVariant QV8Engine::objectToVariant(QV4::Object *o, V8ObjectSet *visitedObjects) result = map; } - visitedObjects->remove(o); + visitedObjects->remove(o->d()); return result; } diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 2379689..4a6737a 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -165,7 +165,8 @@ class QQmlContextData; class Q_QML_PRIVATE_EXPORT QV8Engine { friend class QJSEngine; - typedef QSet V8ObjectSet; + // ### GC + typedef QSet V8ObjectSet; public: static QV8Engine* get(QJSEngine* q) { Q_ASSERT(q); return q->handle(); } // static QJSEngine* get(QV8Engine* d) { Q_ASSERT(d); return d->q; }