aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4objectproto.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-05-29 12:14:53 +0200
committerLars Knoll <lars.knoll@qt.io>2018-06-04 13:02:09 +0000
commit8e23235181eb25faf99324e136412da23dc8386f (patch)
tree97071ffe480c175200e8cb765a80015aa11cf890 /src/qml/jsruntime/qv4objectproto.cpp
parenta0fcf724ef1d8586301a913d2cd744aed33e3605 (diff)
Use Symbol.toStringTag in Object.prototype.toString
This should make toString comply fully with the JS Spec. Also add a couple of missing Symbol.toStringTag properties. Change-Id: I29e2018b486a0e1d174b58ce7a14f0e42cc78767 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4objectproto.cpp')
-rw-r--r--src/qml/jsruntime/qv4objectproto.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp
index ebf1c713fb..478e2e5915 100644
--- a/src/qml/jsruntime/qv4objectproto.cpp
+++ b/src/qml/jsruntime/qv4objectproto.cpp
@@ -47,6 +47,7 @@
#include "qv4objectiterator_p.h"
#include "qv4string_p.h"
#include "qv4jscall_p.h"
+#include "qv4symbol_p.h"
#include <QtCore/QDateTime>
#include <QtCore/QStringList>
@@ -532,20 +533,33 @@ ReturnedValue ObjectPrototype::method_setPrototypeOf(const FunctionObject *f, co
ReturnedValue ObjectPrototype::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int)
{
ExecutionEngine *v4 = b->engine();
+ QString string;
if (thisObject->isUndefined()) {
- return Encode(v4->newString(QStringLiteral("[object Undefined]")));
+ string = QStringLiteral("[object Undefined]");
} else if (thisObject->isNull()) {
- return Encode(v4->newString(QStringLiteral("[object Null]")));
- } else if (thisObject->isBoolean()) {
- return Encode(v4->newString(QStringLiteral("[object Boolean]")));
- } else if (thisObject->isNumber()) {
- return Encode(v4->newString(QStringLiteral("[object Number]")));
+ string = QStringLiteral("[object Null]");
} else {
- Q_ASSERT(thisObject->isManaged());
- const Managed *m = static_cast<const Managed *>(thisObject);
- QString className = m->className();
- return Encode(v4->newString(QStringLiteral("[object %1]").arg(className)));
+ const Object *o = thisObject->as<Object>();
+ if (!o) {
+ // primitive, get the proper prototype
+ if (thisObject->isBoolean())
+ o = v4->booleanPrototype();
+ else if (thisObject->isNumber())
+ o = v4->numberPrototype();
+ else if (thisObject->isString())
+ o = v4->stringPrototype();
+ else if (thisObject->isSymbol())
+ o = v4->symbolPrototype();
+ Q_ASSERT(o);
+ }
+ QString name = o->className();
+ Scope scope(v4);
+ ScopedString toStringTag(scope, o->get(v4->symbol_toStringTag()));
+ if (toStringTag)
+ name = toStringTag->toQString();
+ string = QStringLiteral("[object %1]").arg(name);
}
+ return Encode(v4->newString(string));
}
ReturnedValue ObjectPrototype::method_toLocaleString(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)