Fix the remaining objects against self destruction
authorLars Knoll <lars.knoll@digia.com>
Fri, 11 Oct 2013 10:26:27 +0000 (12:26 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 11 Oct 2013 14:01:24 +0000 (16:01 +0200)
This makes pretty much all test cases pass with exact
garbage collection.

Change-Id: Ia874e3c17c3984afb7cfe370f9bd3ad8fe46699a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4engine.cpp
src/qml/jsruntime/qv4jsonobject.cpp
src/qml/jsruntime/qv4mathobject.cpp
src/qml/jsruntime/qv4qobjectwrapper.cpp
src/qml/jsruntime/qv4regexpobject.cpp
src/qml/jsruntime/qv4sequenceobject.cpp
src/qml/jsruntime/qv4sparsearray.cpp
src/qml/jsruntime/qv4stringobject.cpp
src/qml/jsruntime/qv4variantobject.cpp
src/qml/qml/qqmlxmlhttprequest.cpp
src/quick/items/context2d/qquickcontext2d.cpp

index 41eb6fe..6257d8b 100644 (file)
@@ -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;
     }
 }
index 2295fb5..331b528 100644 (file)
@@ -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);
 }
index fcff9e4..6280b7c 100644 (file)
@@ -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)));
index d42d842..03d8393 100644 (file)
@@ -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"));
 }
 
index 9c7fe94..4adee43 100644 (file)
@@ -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);
index c535dbe..05f51be 100644 (file)
@@ -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();
     }
index a9faf63..ec6b0f5 100644 (file)
@@ -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();
 }
 
 
index 7e503e4..25e1ea5 100644 (file)
@@ -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();
index 2fe9c71..a37da31 100644 (file)
@@ -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)
index 6aeabf9..7a25160 100644 (file)
@@ -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);
index 6f7cd77..f770430 100644 (file)
@@ -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);