summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-06-23 02:45:34 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-06-23 02:45:34 (GMT)
commit3e209785c3f027973089ccbebc6528501f416f2b (patch)
tree52ff9053cabeb94266ab91932bfbf10897b070a5
parent27d59016d35ae84d89e8d09bdadb1c3a89ac3f22 (diff)
downloadQt-3e209785c3f027973089ccbebc6528501f416f2b.zip
Qt-3e209785c3f027973089ccbebc6528501f416f2b.tar.gz
Qt-3e209785c3f027973089ccbebc6528501f416f2b.tar.bz2
References to undefined variables throws a ReferenceError
This is consistent with normal JavaScript
-rw-r--r--src/declarative/qml/qdeclarativeglobalscriptclass.cpp24
-rw-r--r--src/declarative/qml/qdeclarativeglobalscriptclass_p.h5
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/eval.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/function.qml6
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml2
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp13
6 files changed, 31 insertions, 25 deletions
diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp
index 6e107fb..f29b3f4 100644
--- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp
@@ -41,6 +41,7 @@
#include "private/qdeclarativeglobalscriptclass_p.h"
+#include <QtCore/qstringlist.h>
#include <QtScript/qscriptstring.h>
#include <QtScript/qscriptengine.h>
#include <QtScript/qscriptvalueiterator.h>
@@ -87,18 +88,7 @@ QDeclarativeGlobalScriptClass::queryProperty(const QScriptValue &object,
Q_UNUSED(name);
Q_UNUSED(flags);
Q_UNUSED(id);
- return HandlesReadAccess | HandlesWriteAccess;
-}
-
-QScriptValue
-QDeclarativeGlobalScriptClass::property(const QScriptValue &object,
- const QScriptString &name,
- uint id)
-{
- Q_UNUSED(object);
- Q_UNUSED(name);
- Q_UNUSED(id);
- return engine()->undefinedValue();
+ return HandlesWriteAccess;
}
void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object,
@@ -114,8 +104,9 @@ void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object,
}
/* This method is for the use of tst_qdeclarativeecmascript::callQtInvokables() only */
-void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, const QScriptValue &value)
+void QDeclarativeGlobalScriptClass::explicitSetProperty(const QStringList &names, const QList<QScriptValue> &values)
{
+ Q_ASSERT(names.count() == values.count());
QScriptValue globalObject = engine()->globalObject();
QScriptValue v = engine()->newObject();
@@ -126,7 +117,12 @@ void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, con
v.setProperty(iter.scriptName(), iter.value());
}
- v.setProperty(name, value);
+ for (int ii = 0; ii < names.count(); ++ii) {
+ const QString &name = names.at(ii);
+ const QScriptValue &value = values.at(ii);
+ v.setProperty(name, value);
+ }
+
v.setScriptClass(this);
engine()->setGlobalObject(v);
diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
index 7690edd..fb44e5d 100644
--- a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
+++ b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
@@ -67,13 +67,10 @@ public:
const QScriptString &name,
QueryFlags flags, uint *id);
- virtual QScriptValue property(const QScriptValue &object,
- const QScriptString &name, uint id);
-
virtual void setProperty(QScriptValue &object, const QScriptString &name,
uint id, const QScriptValue &value);
- void explicitSetProperty(const QString &, const QScriptValue &);
+ void explicitSetProperty(const QStringList &, const QList<QScriptValue> &);
const QScriptValue &globalObject() const { return m_globalObject; }
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml b/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml
index bc2df98..aab39be 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml
@@ -16,7 +16,11 @@ QtObject {
test1 = (eval("a") == 7);
test2 = (eval("b") == 9);
- test3 = (eval("c") == undefined);
+ try {
+ eval("c");
+ } catch(e) {
+ test3 = true;
+ }
test4 = (eval("console") == console);
test5 = (eval("Qt") == Qt);
}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/function.qml b/tests/auto/declarative/qdeclarativeecmascript/data/function.qml
index b435f58..80d6ef4 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/function.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/function.qml
@@ -14,6 +14,10 @@ QtObject {
test1 = (func1(4) == 11);
test2 = (func2("Hello World!") == Qt.atob("Hello World!"));
- test3 = (func3() == undefined);
+ try {
+ func3();
+ } catch(e) {
+ test3 = true;
+ }
}
}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml
index e8f7b62..f601f49 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml
@@ -4,7 +4,7 @@ import "scriptErrors.js" as Script
MyQmlObject {
property int t: a.value
property int w: Script.getValue();
- property int x: undefinedObject
+ property int x: undefined
property int y: (a.value, undefinedObject)
onBasicSignal: { console.log(a.value); }
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 16e7ec5..50da55d 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -1002,10 +1002,10 @@ void tst_qdeclarativeecmascript::scriptErrors()
QString url = component.url().toString();
QString warning1 = url.left(url.length() - 3) + "js:2: Error: Invalid write to global property \"a\"";
- QString warning2 = url + ":5: TypeError: Result of expression 'a' [undefined] is not an object.";
+ QString warning2 = url + ":5: ReferenceError: Can't find variable: a";
QString warning3 = url.left(url.length() - 3) + "js:4: Error: Invalid write to global property \"a\"";
- QString warning4 = url + ":10: TypeError: Result of expression 'a' [undefined] is not an object.";
- QString warning5 = url + ":8: TypeError: Result of expression 'a' [undefined] is not an object.";
+ QString warning4 = url + ":10: ReferenceError: Can't find variable: a";
+ QString warning5 = url + ":8: ReferenceError: Can't find variable: a";
QString warning6 = url + ":7: Unable to assign [undefined] to int x";
QString warning7 = url + ":12: Error: Cannot assign to read-only property \"trueProperty\"";
QString warning8 = url + ":13: Error: Cannot assign to non-existent property \"fakeProperty\"";
@@ -1322,7 +1322,12 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QDeclarativeEngine qmlengine;
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(&qmlengine);
QScriptEngine *engine = &ep->scriptEngine;
- ep->globalClass->explicitSetProperty("object", ep->objectClass->newQObject(&o));
+
+ QStringList names; QList<QScriptValue> values;
+ names << QLatin1String("object"); values << ep->objectClass->newQObject(&o);
+ names << QLatin1String("undefined"); values << engine->undefinedValue();
+
+ ep->globalClass->explicitSetProperty(names, values);
// Non-existent methods
o.reset();