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 <simon.hausmann@digia.com>
This commit is contained in:
Lars Knoll 2013-10-11 12:26:27 +02:00 committed by The Qt Project
parent f6de6160b9
commit e964fc3426
11 changed files with 45 additions and 5 deletions

View 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;
}
}

View 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);
}

View 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)));

View 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"));
}

View 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);

View 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();
}

View 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();
}

View 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();

View 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)

View 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);

View 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);