From 8c9fc13a4ac5661b8040798e0545280bd5f7ebb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marja=20H=C3=B6ltt=C3=A4?= Date: Tue, 27 Jul 2021 18:22:05 +0200 Subject: [PATCH] [rab/gsab] TypedArray.prototype.fill: Support rab / gsab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: v8:11111 Change-Id: I09e918a3f8c50e10691c8ab4718b7c4ae9184000 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3055303 Commit-Queue: Marja Hölttä Reviewed-by: Jakob Kummerow Cr-Commit-Position: refs/heads/master@{#75946} --- src/builtins/builtins-typed-array.cc | 4 +- src/objects/elements-kind.h | 6 ++ src/objects/elements.cc | 2 +- test/mjsunit/mjsunit.status | 1 + .../typedarray-growablesharedarraybuffer.js | 54 ++++++++++++ test/mjsunit/typedarray-helpers.js | 20 +++++ .../typedarray-resizablearraybuffer.js | 85 +++++++++++++++++++ test/test262/test262.status | 50 +++++------ 8 files changed, 195 insertions(+), 27 deletions(-) create mode 100644 test/mjsunit/typedarray-helpers.js diff --git a/src/builtins/builtins-typed-array.cc b/src/builtins/builtins-typed-array.cc index adcf762ffe..bc8c6a749c 100644 --- a/src/builtins/builtins-typed-array.cc +++ b/src/builtins/builtins-typed-array.cc @@ -119,7 +119,7 @@ BUILTIN(TypedArrayPrototypeFill) { ElementsKind kind = array->GetElementsKind(); Handle obj_value = args.atOrUndefined(isolate, 1); - if (kind == BIGINT64_ELEMENTS || kind == BIGUINT64_ELEMENTS) { + if (IsBigIntTypedArrayElementsKind(kind)) { ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, obj_value, BigInt::FromObject(isolate, obj_value)); } else { @@ -127,7 +127,7 @@ BUILTIN(TypedArrayPrototypeFill) { Object::ToNumber(isolate, obj_value)); } - int64_t len = array->length(); + int64_t len = array->GetLength(); int64_t start = 0; int64_t end = len; diff --git a/src/objects/elements-kind.h b/src/objects/elements-kind.h index f7da82caf7..0d546aba8d 100644 --- a/src/objects/elements-kind.h +++ b/src/objects/elements-kind.h @@ -197,6 +197,12 @@ inline bool IsTypedArrayOrRabGsabTypedArrayElementsKind(ElementsKind kind) { LAST_RAB_GSAB_FIXED_TYPED_ARRAY_ELEMENTS_KIND); } +inline bool IsBigIntTypedArrayElementsKind(ElementsKind kind) { + return kind == BIGINT64_ELEMENTS || kind == BIGUINT64_ELEMENTS || + kind == RAB_GSAB_BIGINT64_ELEMENTS || + kind == RAB_GSAB_BIGUINT64_ELEMENTS; +} + inline bool IsWasmArrayElementsKind(ElementsKind kind) { return kind == WASM_ARRAY_ELEMENTS; } diff --git a/src/objects/elements.cc b/src/objects/elements.cc index dd137aab55..4eedf3d6c0 100644 --- a/src/objects/elements.cc +++ b/src/objects/elements.cc @@ -3296,7 +3296,7 @@ class TypedElementsAccessor Handle typed_array = Handle::cast(receiver); DCHECK(!typed_array->WasDetached()); DCHECK_LE(start, end); - DCHECK_LE(end, typed_array->length()); + DCHECK_LE(end, typed_array->GetLength()); DisallowGarbageCollection no_gc; ElementType scalar = FromHandle(value); ElementType* data = static_cast(typed_array->DataPtr()); diff --git a/test/mjsunit/mjsunit.status b/test/mjsunit/mjsunit.status index 75fcbf1ec3..f1fdc37076 100644 --- a/test/mjsunit/mjsunit.status +++ b/test/mjsunit/mjsunit.status @@ -35,6 +35,7 @@ 'wasm/exceptions-utils': [SKIP], 'wasm/wasm-module-builder': [SKIP], 'compiler/fast-api-helpers': [SKIP], + 'typedarray-helpers': [SKIP], # All tests in the bug directory are expected to fail. 'bugs/*': [FAIL], diff --git a/test/mjsunit/typedarray-growablesharedarraybuffer.js b/test/mjsunit/typedarray-growablesharedarraybuffer.js index e4dfd7c657..db37556d52 100644 --- a/test/mjsunit/typedarray-growablesharedarraybuffer.js +++ b/test/mjsunit/typedarray-growablesharedarraybuffer.js @@ -6,6 +6,8 @@ "use strict"; +d8.file.execute('test/mjsunit/typedarray-helpers.js'); + class MyUint8Array extends Uint8Array {}; const ctors = [ @@ -594,3 +596,55 @@ function TestIterationAndGrow(ta, expected, gsab, grow_after, } } }()); + +(function TestFill() { + for (let ctor of ctors) { + const gsab = CreateGrowableSharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, + 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(gsab, 0, 4); + const fixedLengthWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(gsab, 0); + const lengthTrackingWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT); + + assertEquals([0, 0, 0, 0], ReadDataFromBuffer(gsab, ctor)); + + FillHelper(fixedLength, 1); + assertEquals([1, 1, 1, 1], ReadDataFromBuffer(gsab, ctor)); + + FillHelper(fixedLengthWithOffset, 2); + assertEquals([1, 1, 2, 2], ReadDataFromBuffer(gsab, ctor)); + + FillHelper(lengthTracking, 3); + assertEquals([3, 3, 3, 3], ReadDataFromBuffer(gsab, ctor)); + + FillHelper(lengthTrackingWithOffset, 4); + assertEquals([3, 3, 4, 4], ReadDataFromBuffer(gsab, ctor)); + + gsab.grow(6 * ctor.BYTES_PER_ELEMENT); + + FillHelper(fixedLength, 13); + assertEquals([13, 13, 13, 13, 0, 0], ReadDataFromBuffer(gsab, ctor)); + + FillHelper(fixedLengthWithOffset, 14); + assertEquals([13, 13, 14, 14, 0, 0], ReadDataFromBuffer(gsab, ctor)); + + FillHelper(lengthTracking, 15); + assertEquals([15, 15, 15, 15, 15, 15], ReadDataFromBuffer(gsab, ctor)); + + FillHelper(lengthTrackingWithOffset, 16); + assertEquals([15, 15, 16, 16, 16, 16], ReadDataFromBuffer(gsab, ctor)); + + // Filling with non-undefined start & end. + FillHelper(fixedLength, 17, 1, 3); + assertEquals([15, 17, 17, 16, 16, 16], ReadDataFromBuffer(gsab, ctor)); + + FillHelper(fixedLengthWithOffset, 18, 1, 2); + assertEquals([15, 17, 17, 18, 16, 16], ReadDataFromBuffer(gsab, ctor)); + + FillHelper(lengthTracking, 19, 1, 3); + assertEquals([15, 19, 19, 18, 16, 16], ReadDataFromBuffer(gsab, ctor)); + + FillHelper(lengthTrackingWithOffset, 20, 1, 2); + assertEquals([15, 19, 19, 20, 16, 16], ReadDataFromBuffer(gsab, ctor)); + } +})(); diff --git a/test/mjsunit/typedarray-helpers.js b/test/mjsunit/typedarray-helpers.js new file mode 100644 index 0000000000..c9e09071d2 --- /dev/null +++ b/test/mjsunit/typedarray-helpers.js @@ -0,0 +1,20 @@ +// Copyright 2021 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +function ReadDataFromBuffer(ab, ctor) { + let result = []; + const ta = new ctor(ab, 0, ab.byteLength / ctor.BYTES_PER_ELEMENT); + for (let item of ta) { + result.push(Number(item)); + } + return result; +} + +function FillHelper(ta, n, start, end) { + if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) { + ta.fill(BigInt(n), start, end); + } else { + ta.fill(n, start, end); + } +} diff --git a/test/mjsunit/typedarray-resizablearraybuffer.js b/test/mjsunit/typedarray-resizablearraybuffer.js index 8b83733e9d..44e245b513 100644 --- a/test/mjsunit/typedarray-resizablearraybuffer.js +++ b/test/mjsunit/typedarray-resizablearraybuffer.js @@ -6,6 +6,8 @@ "use strict"; +d8.file.execute('test/mjsunit/typedarray-helpers.js'); + class MyUint8Array extends Uint8Array {}; const ctors = [ @@ -967,3 +969,86 @@ function TestIterationAndResize(ta, expected, rab, resize_after, }); } }()); + +(function TestFill() { + for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, + 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + assertEquals([0, 0, 0, 0], ReadDataFromBuffer(rab, ctor)); + + FillHelper(fixedLength, 1); + assertEquals([1, 1, 1, 1], ReadDataFromBuffer(rab, ctor)); + + FillHelper(fixedLengthWithOffset, 2); + assertEquals([1, 1, 2, 2], ReadDataFromBuffer(rab, ctor)); + + FillHelper(lengthTracking, 3); + assertEquals([3, 3, 3, 3], ReadDataFromBuffer(rab, ctor)); + + FillHelper(lengthTrackingWithOffset, 4); + assertEquals([3, 3, 4, 4], ReadDataFromBuffer(rab, ctor)); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + FillHelper(fixedLength, 5); + assertEquals([3, 3, 4], ReadDataFromBuffer(rab, ctor)); + + FillHelper(fixedLengthWithOffset, 6); + assertEquals([3, 3, 4], ReadDataFromBuffer(rab, ctor)); + + FillHelper(lengthTracking, 7); + assertEquals([7, 7, 7], ReadDataFromBuffer(rab, ctor)); + + FillHelper(lengthTrackingWithOffset, 8); + assertEquals([7, 7, 8], ReadDataFromBuffer(rab, ctor)); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + + FillHelper(fixedLength, 9); + assertEquals([7], ReadDataFromBuffer(rab, ctor)); + + FillHelper(fixedLengthWithOffset, 10); + assertEquals([7], ReadDataFromBuffer(rab, ctor)); + + FillHelper(lengthTracking, 11); + assertEquals([11], ReadDataFromBuffer(rab, ctor)); + + FillHelper(lengthTrackingWithOffset, 12); + assertEquals([11], ReadDataFromBuffer(rab, ctor)); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + + FillHelper(fixedLength, 13); + assertEquals([13, 13, 13, 13, 0, 0], ReadDataFromBuffer(rab, ctor)); + + FillHelper(fixedLengthWithOffset, 14); + assertEquals([13, 13, 14, 14, 0, 0], ReadDataFromBuffer(rab, ctor)); + + FillHelper(lengthTracking, 15); + assertEquals([15, 15, 15, 15, 15, 15], ReadDataFromBuffer(rab, ctor)); + + FillHelper(lengthTrackingWithOffset, 16); + assertEquals([15, 15, 16, 16, 16, 16], ReadDataFromBuffer(rab, ctor)); + + // Filling with non-undefined start & end. + FillHelper(fixedLength, 17, 1, 3); + assertEquals([15, 17, 17, 16, 16, 16], ReadDataFromBuffer(rab, ctor)); + + FillHelper(fixedLengthWithOffset, 18, 1, 2); + assertEquals([15, 17, 17, 18, 16, 16], ReadDataFromBuffer(rab, ctor)); + + FillHelper(lengthTracking, 19, 1, 3); + assertEquals([15, 19, 19, 18, 16, 16], ReadDataFromBuffer(rab, ctor)); + + FillHelper(lengthTrackingWithOffset, 20, 1, 2); + assertEquals([15, 19, 19, 20, 16, 16], ReadDataFromBuffer(rab, ctor)); + } +})(); diff --git a/test/test262/test262.status b/test/test262/test262.status index 4c6947084d..e41c3869e2 100644 --- a/test/test262/test262.status +++ b/test/test262/test262.status @@ -597,32 +597,8 @@ 'built-ins/DataView/prototype/setUint8/resizable-buffer': [FAIL], 'built-ins/TypedArrayConstructors/ctors/typedarray-arg/out-of-bounds-when-species-retrieved-different-type': [FAIL], 'built-ins/TypedArrayConstructors/ctors/typedarray-arg/out-of-bounds-when-species-retrieved-same-type': [FAIL], - 'built-ins/TypedArray/prototype/at/return-abrupt-from-this-out-of-bounds': [FAIL], 'built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto': [FAIL], 'built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-fixed': [FAIL], - 'built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-this-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/entries/return-abrupt-from-this-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/every/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/fill/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/filter/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/findIndex/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/find/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/forEach/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/includes/return-abrupt-from-this-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/indexOf/return-abrupt-from-this-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/join/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/keys/return-abrupt-from-this-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/lastIndexOf/return-abrupt-from-this-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/map/return-abrupt-from-this-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/reduce/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/reduceRight/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/reverse/return-abrupt-from-this-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/set/typedarray-arg-target-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/slice/return-abrupt-from-this-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/some/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/sort/return-abrupt-from-this-out-of-bounds': [FAIL], - 'built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-this-out-of-bounds': [SKIP], - 'built-ins/TypedArray/prototype/values/return-abrupt-from-this-out-of-bounds': [FAIL], # https://bugs.chromium.org/p/v8/issues/detail?id=11544 'built-ins/Temporal/Calendar/prototype/fields/long-input': [FAIL], @@ -692,6 +668,32 @@ # https://github.com/tc39/test262/issues/3109 'built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-fixed': [FAIL], + # https://github.com/tc39/test262/issues/3111 + 'built-ins/TypedArray/prototype/at/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/entries/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/every/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/fill/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/filter/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/findIndex/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/find/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/forEach/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/includes/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/indexOf/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/join/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/keys/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/lastIndexOf/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/map/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/reduce/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/reduceRight/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/reverse/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/set/typedarray-arg-target-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/slice/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/some/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/sort/return-abrupt-from-this-out-of-bounds': [FAIL], + 'built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-this-out-of-bounds': [SKIP], + 'built-ins/TypedArray/prototype/values/return-abrupt-from-this-out-of-bounds': [FAIL], + ############################ SKIPPED TESTS ############################# # These tests take a looong time to run.