aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4lookup.cpp
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2019-05-31 19:01:07 +0200
committerDavid Faure <david.faure@kdab.com>2019-05-31 19:09:20 +0200
commit99c96eb1042575a7ca5ba534f453c679c6dc9cd8 (patch)
tree798d8c93c7121fccec201b485c9d64c22b1ced59 /src/qml/jsruntime/qv4lookup.cpp
parent5af16fb4dfa39ead82240f5ffbc004634f3c288f (diff)
Improve "Type error" when looking up a property of null or undefined
Before: MenuItem.qml:98: TypeError: Type error After: MenuItem.qml:101: TypeError: Cannot read property 'height' of null The wording matches the similar error messages in qv4runtime.cpp. Change-Id: I3d9b3506195fe8e17e78117f2f51aba2adbc0564 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Laurent Montel <laurent.montel@kdab.com>
Diffstat (limited to 'src/qml/jsruntime/qv4lookup.cpp')
-rw-r--r--src/qml/jsruntime/qv4lookup.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp
index f8999342d1..6b8fb509a8 100644
--- a/src/qml/jsruntime/qv4lookup.cpp
+++ b/src/qml/jsruntime/qv4lookup.cpp
@@ -77,8 +77,13 @@ ReturnedValue Lookup::resolvePrimitiveGetter(ExecutionEngine *engine, const Valu
primitiveLookup.type = object.type();
switch (primitiveLookup.type) {
case Value::Undefined_Type:
- case Value::Null_Type:
- return engine->throwTypeError();
+ case Value::Null_Type: {
+ Scope scope(engine);
+ ScopedString name(scope, engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]);
+ const QString message = QStringLiteral("Cannot read property '%1' of %2").arg(name->toQString())
+ .arg(QLatin1String(primitiveLookup.type == Value::Undefined_Type ? "undefined" : "null"));
+ return engine->throwTypeError(message);
+ }
case Value::Boolean_Type:
primitiveLookup.proto = engine->booleanPrototype()->d();
break;