diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-19 16:05:25 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-22 01:06:20 +0200 |
commit | 47bf40dd49f90b52cc1b545b2be3035d48d6199e (patch) | |
tree | 9e671c23d610822ac354e4a1399e2c805cbea599 /src/qml/qml/qqmlxmlhttprequest.cpp | |
parent | 78b49cf8361b1462cc94a061916a15f0b98e27e3 (diff) |
Prevent objects from being collected while in their constructor
While objects are being constructed, we don't have a reference to them
on the JS stack yet. So the constructor needs to protect itself against
being collected by putting the this object onto the JS stack.
Added an environment switch MM_EXACT_GC to test exact garbage
collection.
Change-Id: Ie37665a954de800359c272ffbebbe1488e7a8ace
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlxmlhttprequest.cpp')
-rw-r--r-- | src/qml/qml/qqmlxmlhttprequest.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 79b9344994..48072f53c8 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -1585,9 +1585,12 @@ struct QQmlXMLHttpRequestCtor : public FunctionObject { Q_MANAGED QQmlXMLHttpRequestCtor(ExecutionEngine *engine) - : FunctionObject(engine->rootContext, engine->newString(QStringLiteral("XMLHttpRequest"))) + : FunctionObject(engine->rootContext, QStringLiteral("XMLHttpRequest")) { vtbl = &static_vtbl; + Scope scope(engine); + ScopedValue protectThis(scope, this); + defineReadonlyProperty(QStringLiteral("UNSENT"), Value::fromInt32(0)); defineReadonlyProperty(QStringLiteral("OPENED"), Value::fromInt32(1)); defineReadonlyProperty(QStringLiteral("HEADERS_RECEIVED"), Value::fromInt32(2)); @@ -1595,7 +1598,6 @@ struct QQmlXMLHttpRequestCtor : public FunctionObject defineReadonlyProperty(QStringLiteral("DONE"), Value::fromInt32(4)); if (!proto) setupProto(); - Scope scope(engine); ScopedString s(scope, engine->id_prototype); defineDefaultProperty(s, Value::fromObject(proto)); } |