diff options
author | Chris Adams <christopher.adams@nokia.com> | 2011-08-03 11:04:01 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-30 07:15:51 +0200 |
commit | be244df6cdce029eeb04d3e919ccf5c4983bd3e4 (patch) | |
tree | 2d6d839d5e398f996c481411b94fb5e4131f944c /tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp | |
parent | 6cec35c85acdf458d14126784b7739c5419314eb (diff) |
Implement script module api property get and set
This commit adds code for property get and set for script module
APIs, and also splits up the module API unit tests into QObject and
Script (QJSValue) parts.
Related to commit: 3ee8a19f5b7142b96e2df649ea0dac444b5622a2
Task-number: QMLNG-33
Task-number: QTBUG-17318
Change-Id: I4aaf5d1cc1d4774dd0f0999f0985439e4d76f0ca
Reviewed-on: http://codereview.qt.nokia.com/1472
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp')
-rw-r--r-- | tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp index 160a57215b..05d5510033 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp @@ -111,6 +111,21 @@ static QJSValue script_api(QDeclarativeEngine *engine, QJSEngine *scriptEngine) return v; } +static QJSValue readonly_script_api(QDeclarativeEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + + static int testProperty = 42; + QJSValue v = scriptEngine->newObject(); + v.setProperty("scriptTestProperty", testProperty++); + + // now freeze it so that it's read-only + QJSValue freezeFunction = scriptEngine->evaluate("(function(obj) { return Object.freeze(obj); })"); + v = freezeFunction.call(QJSValue(), (QJSValueList() << v)); + + return v; +} + static QObject *qobject_api(QDeclarativeEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) @@ -166,6 +181,7 @@ void registerTypes() qmlRegisterModuleApi("Qt.test",1,0,script_api); // register (script) module API for an existing uri which contains elements qmlRegisterModuleApi("Qt.test",1,0,qobject_api); // register (qobject) for an existing uri for which another module API was previously regd. Should replace! qmlRegisterModuleApi("Qt.test.scriptApi",1,0,script_api); // register (script) module API for a uri which doesn't contain elements + qmlRegisterModuleApi("Qt.test.scriptApi",2,0,readonly_script_api); // register (script) module API for a uri which doesn't contain elements - will be made read-only qmlRegisterModuleApi("Qt.test.qobjectApi",1,0,qobject_api); // register (qobject) module API for a uri which doesn't contain elements qmlRegisterModuleApi("Qt.test.qobjectApi",1,3,qobject_api); // register (qobject) module API for a uri which doesn't contain elements, minor version set qmlRegisterModuleApi("Qt.test.qobjectApi",2,0,qobject_api); // register (qobject) module API for a uri which doesn't contain elements, major version set |