From a1ea2b8ec057bca58fdb5e9498e2f302ef0e61b4 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Thu, 24 May 2018 21:19:22 +0200 Subject: qv4arrayobject: Implement Array.prototype.fill according to ES7 Task-number: QTBUG-56824 Change-Id: Ib12b9fe5ebdd5375f17cf4927eb9b4e292731932 Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4object_p.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/qml/jsruntime/qv4object_p.h') diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 7cc99376be..5ad67635db 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -385,6 +385,23 @@ public: DoNotThrow }; + // This is the same as set(), but it doesn't require creating a string key, + // which is much more efficient for the array case. + inline bool setIndexed(uint idx, const Value &v, ThrowOnFailure shouldThrow) + { + bool ret = vtable()->putIndexed(this, idx, v); + // ES6: 7.3.3, 6: If success is false and Throw is true, throw a TypeError exception. + if (!ret && shouldThrow == ThrowOnFailure::DoThrowOnRejection) { + ExecutionEngine *e = engine(); + if (!e->hasException) { // allow a custom set impl to throw itself + QString message = QLatin1String("Cannot assign to read-only property \"") + + QString::number(idx) + QLatin1Char('\"'); + e->throwTypeError(message); + } + } + return ret; + } + // ES6: 7.3.3 Set (O, P, V, Throw) inline bool set(StringOrSymbol *name, const Value &v, ThrowOnFailure shouldThrow) { -- cgit v1.2.3