From: Lars Knoll Date: Fri, 11 Oct 2013 10:26:27 +0000 (+0200) Subject: Fix the remaining objects against self destruction X-Git-Tag: upstream/5.2.1~249 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e964fc34269bc2087fb3246172a1890224a160bd;p=platform%2Fupstream%2Fqtdeclarative.git Fix the remaining objects against self destruction This makes pretty much all test cases pass with exact garbage collection. Change-Id: Ia874e3c17c3984afb7cfe370f9bd3ad8fe46699a Reviewed-by: Simon Hausmann --- diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 41eb6fe..6257d8b 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -673,12 +673,16 @@ void ExecutionEngine::requireArgumentsAccessors(int n) if (n <= argumentsAccessors.size()) return; + Scope scope(this); + ScopedFunctionObject get(scope); + ScopedFunctionObject set(scope); + uint oldSize = argumentsAccessors.size(); argumentsAccessors.resize(n); for (int i = oldSize; i < n; ++i) { - FunctionObject *get = new (memoryManager) ArgumentsGetterFunction(rootContext, i); - FunctionObject *set = new (memoryManager) ArgumentsSetterFunction(rootContext, i); - Property pd = Property::fromAccessor(get, set); + get = new (memoryManager) ArgumentsGetterFunction(rootContext, i); + set = new (memoryManager) ArgumentsSetterFunction(rootContext, i); + Property pd = Property::fromAccessor(get.getPointer(), set.getPointer()); argumentsAccessors[i] = pd; } } diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index 2295fb5..331b528 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -881,6 +881,9 @@ JsonObject::JsonObject(ExecutionEngine *engine) { type = Type_JSONObject; + Scope scope(engine); + ScopedObject protectThis(scope, this); + defineDefaultProperty(QStringLiteral("parse"), method_parse, 2); defineDefaultProperty(QStringLiteral("stringify"), method_stringify, 3); } diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index fcff9e4..6280b7c 100644 --- a/src/qml/jsruntime/qv4mathobject.cpp +++ b/src/qml/jsruntime/qv4mathobject.cpp @@ -55,6 +55,9 @@ MathObject::MathObject(ExecutionEngine *engine) { type = Type_MathObject; + Scope scope(engine); + ScopedObject protectThis(scope, this); + defineReadonlyProperty(QStringLiteral("E"), Primitive::fromDouble(::exp(1.0))); defineReadonlyProperty(QStringLiteral("LN2"), Primitive::fromDouble(::log(2.0))); defineReadonlyProperty(QStringLiteral("LN10"), Primitive::fromDouble(::log(10.0))); diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index d42d842..03d8393 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -243,6 +243,9 @@ QObjectWrapper::QObjectWrapper(ExecutionEngine *engine, QObject *object) { vtbl = &static_vtbl; + Scope scope(engine); + ScopedObject protectThis(scope, this); + m_destroy = engine->newIdentifier(QStringLiteral("destroy")); } diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index 9c7fe94..4adee43 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -132,6 +132,9 @@ RegExpObject::RegExpObject(ExecutionEngine *engine, const QRegExp &re) pattern = ecmaPattern; } + Scope scope(engine); + ScopedObject protectThis(scope, this); + value = RegExp::create(engine, pattern, re.caseSensitivity() == Qt::CaseInsensitive, false); init(engine); diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index c535dbe..05f51be 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -175,6 +175,8 @@ public: { type = Type_QmlSequence; vtbl = &static_vtbl; + QV4::Scope scope(engine); + QV4::ScopedObject protectThis(scope, this); init(); } @@ -186,6 +188,8 @@ public: { type = Type_QmlSequence; vtbl = &static_vtbl; + QV4::Scope scope(engine); + QV4::ScopedObject protectThis(scope, this); loadReference(); init(); } diff --git a/src/qml/jsruntime/qv4sparsearray.cpp b/src/qml/jsruntime/qv4sparsearray.cpp index a9faf63..ec6b0f5 100644 --- a/src/qml/jsruntime/qv4sparsearray.cpp +++ b/src/qml/jsruntime/qv4sparsearray.cpp @@ -73,7 +73,9 @@ bool ArrayElementLessThan::operator()(const Property &p1, const Property &p2) co return result->toNumber() <= 0; } - return p1.value.toString(m_context)->toQString() < p2.value.toString(m_context)->toQString(); + ScopedString p1s(scope, p1.value.toString(m_context)); + ScopedString p2s(scope, p2.value.toString(m_context)); + return p1s->toQString() < p2s->toQString(); } diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index 7e503e4..25e1ea5 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -82,6 +82,10 @@ StringObject::StringObject(InternalClass *ic) { vtbl = &static_vtbl; type = Type_StringObject; + + Scope scope(engine()); + ScopedObject protectThis(scope, this); + value = ic->engine->newString("")->asReturnedValue(); tmpProperty.value = Primitive::undefinedValue(); @@ -94,6 +98,10 @@ StringObject::StringObject(ExecutionEngine *engine, const ValueRef val) { vtbl = &static_vtbl; type = Type_StringObject; + + Scope scope(engine); + ScopedObject protectThis(scope, this); + value = *val; tmpProperty.value = Primitive::undefinedValue(); diff --git a/src/qml/jsruntime/qv4variantobject.cpp b/src/qml/jsruntime/qv4variantobject.cpp index 2fe9c71..a37da31 100644 --- a/src/qml/jsruntime/qv4variantobject.cpp +++ b/src/qml/jsruntime/qv4variantobject.cpp @@ -66,7 +66,7 @@ VariantObject::VariantObject(ExecutionEngine *engine, const QVariant &value) { vtbl = &static_vtbl; if (isScarce()) - internalClass->engine->scarceResources.insert(this); + engine->scarceResources.insert(this); } QVariant VariantObject::toVariant(const QV4::ValueRef v) diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 6aeabf9..7a25160 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -259,6 +259,10 @@ public: : Object(engine) { vtbl = &static_vtbl; + + Scope scope(engine); + ScopedObject protectThis(scope, this); + defineAccessorProperty(QStringLiteral("nodeName"), method_get_nodeName, 0); defineAccessorProperty(QStringLiteral("nodeValue"), method_get_nodeValue, 0); defineAccessorProperty(QStringLiteral("nodeType"), method_get_nodeType, 0); diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index 6f7cd77..f770430 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -545,6 +545,9 @@ public: QQuickJSContext2DPrototype(QV4::ExecutionEngine *engine) : QV4::Object(engine) { + QV4::Scope scope(engine); + QV4::ScopedObject protectThis(scope, this); + defineDefaultProperty(QStringLiteral("quadraticCurveTo"), method_quadraticCurveTo, 0); defineDefaultProperty(QStringLiteral("restore"), method_restore, 0); defineDefaultProperty(QStringLiteral("moveTo"), method_moveTo, 0); @@ -891,6 +894,9 @@ struct QQuickJSContext2DImageData : public QV4::Object { vtbl = &static_vtbl; + QV4::Scope scope(engine); + QV4::ScopedObject protectThis(scope, this); + defineAccessorProperty(QStringLiteral("width"), method_get_width, 0); defineAccessorProperty(QStringLiteral("height"), method_get_height, 0); defineAccessorProperty(QStringLiteral("data"), method_get_data, 0);