summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-03-16 15:57:49 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-03-16 15:57:49 (GMT)
commitd10667052db5dc2f4d1c7a7c161b040e9747897e (patch)
tree9239a131e77416ef1508021af9e4653117865237
parent4574b41dfb56652e806afd1dd64cc8b300284570 (diff)
downloadQt-d10667052db5dc2f4d1c7a7c161b040e9747897e.zip
Qt-d10667052db5dc2f4d1c7a7c161b040e9747897e.tar.gz
Qt-d10667052db5dc2f4d1c7a7c161b040e9747897e.tar.bz2
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.
-rw-r--r--src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSObject.cpp2
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp20
2 files changed, 21 insertions, 1 deletions
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()