aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4arrayobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-14 19:54:31 +0200
committerLars Knoll <lars.knoll@qt.io>2018-08-23 08:13:35 +0000
commit34094f6918993dd5d10b2eb38203a54f5168d114 (patch)
tree8aa89934d34d6bab6a407e73e5d9c2765d70d7a3 /src/qml/jsruntime/qv4arrayobject.cpp
parent89a053b53f2d2bbf94bc86e133469151720b2433 (diff)
Fix toLocaleString implementations in (Typed)Array.prototype
Change-Id: Idcabd68b1651ad3cae315a16cb0e1361cba21253 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4arrayobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4arrayobject.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp
index 544be06664..9be744038c 100644
--- a/src/qml/jsruntime/qv4arrayobject.cpp
+++ b/src/qml/jsruntime/qv4arrayobject.cpp
@@ -104,7 +104,7 @@ void ArrayPrototype::init(ExecutionEngine *engine, Object *ctor)
ScopedString name(scope);
defineDefaultProperty(QStringLiteral("constructor"), (o = ctor));
defineDefaultProperty(engine->id_toString(), method_toString, 0);
- defineDefaultProperty(QStringLiteral("toLocaleString"), method_toLocaleString, 0);
+ defineDefaultProperty(engine->id_toLocaleString(), method_toLocaleString, 0);
defineDefaultProperty(QStringLiteral("concat"), method_concat, 1);
name = engine->newIdentifier(QStringLiteral("copyWithin"));
unscopables->put(name, Primitive::fromBoolean(true));
@@ -369,9 +369,36 @@ ReturnedValue ArrayPrototype::method_toString(const FunctionObject *builtin, con
return ObjectPrototype::method_toString(builtin, that, argv, argc);
}
-ReturnedValue ArrayPrototype::method_toLocaleString(const FunctionObject *builtin, const Value *thisObject, const Value *argv, int argc)
+ReturnedValue ArrayPrototype::method_toLocaleString(const FunctionObject *b, const Value *thisObject, const Value *, int)
{
- return method_toString(builtin, thisObject, argv, argc);
+ Scope scope(b);
+ ScopedObject instance(scope, thisObject);
+ if (!instance)
+ return scope.engine->throwTypeError();
+
+ uint len = instance->getLength();
+ const QString separator = QStringLiteral(",");
+
+ QString R;
+
+ ScopedValue v(scope);
+ ScopedString s(scope);
+
+ for (uint k = 0; k < len; ++k) {
+ if (k)
+ R += separator;
+
+ v = instance->get(k);
+ if (v->isNullOrUndefined())
+ continue;
+ v = Runtime::method_callElement(scope.engine, v, *scope.engine->id_toLocaleString(), nullptr, 0);
+ s = v->toString(scope.engine);
+ if (scope.hasException())
+ return Encode::undefined();
+
+ R += s->toQString();
+ }
+ return scope.engine->newString(R)->asReturnedValue();
}
ReturnedValue ArrayPrototype::method_concat(const FunctionObject *b, const Value *that, const Value *argv, int argc)