From d10667052db5dc2f4d1c7a7c161b040e9747897e Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Tue, 16 Mar 2010 16:57:49 +0100 Subject: QtScript: Fix regression when calling newQObject() from native constructor The thisObject passed to native constructors did not have all the new structure flags, so if it was promoted to a QObject (using the overload of newQObject() that takes an existing script object as first argument), the resulting script object did not receive dynamic property access callbacks. --- .../JavaScriptCore/runtime/JSObject.cpp | 2 +- tests/auto/qscriptengine/tst_qscriptengine.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSObject.cpp b/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSObject.cpp index c6835fe..0e3475f 100644 --- a/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSObject.cpp +++ b/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSObject.cpp @@ -534,7 +534,7 @@ Structure* JSObject::createInheritorID() { #ifdef QT_BUILD_SCRIPT_LIB // ### QtScript needs the hasOwnProperty() calls etc. for QScriptObject - m_inheritorID = Structure::create(this, TypeInfo(ObjectType, ImplementsHasInstance)); + m_inheritorID = Structure::create(this, TypeInfo(ObjectType, ImplementsHasInstance | JSC::OverridesHasInstance | JSC::OverridesGetOwnPropertySlot | JSC::OverridesMarkChildren | JSC::OverridesGetPropertyNames)); #else m_inheritorID = JSObject::createStructure(this); #endif diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 8658240..d9beb45 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -155,6 +155,7 @@ private slots: void nativeFunctionScopes(); void evaluateProgram(); void collectGarbageAfterConnect(); + void promoteThisObjectToQObjectInConstructor(); void qRegExpInport_data(); void qRegExpInport(); @@ -4461,6 +4462,25 @@ void tst_QScriptEngine::collectGarbageAfterConnect() QVERIFY(widget == 0); } +static QScriptValue constructQObjectFromThisObject(QScriptContext *ctx, QScriptEngine *eng) +{ + Q_ASSERT(ctx->isCalledAsConstructor()); + return eng->newQObject(ctx->thisObject(), new QObject, QScriptEngine::ScriptOwnership); +} + +void tst_QScriptEngine::promoteThisObjectToQObjectInConstructor() +{ + QScriptEngine engine; + QScriptValue ctor = engine.newFunction(constructQObjectFromThisObject); + engine.globalObject().setProperty("Ctor", ctor); + QScriptValue object = engine.evaluate("new Ctor"); + QVERIFY(!object.isError()); + QVERIFY(object.isQObject()); + QVERIFY(object.toQObject() != 0); + QVERIFY(object.property("objectName").isString()); + QVERIFY(object.property("deleteLater").isFunction()); +} + static QRegExp minimal(QRegExp r) { r.setMinimal(true); return r; } void tst_QScriptEngine::qRegExpInport_data() -- cgit v0.12