[rab/gsab] TypedArray.prototype.fill: Support rab / gsab

Bug: v8:11111
Change-Id: I09e918a3f8c50e10691c8ab4718b7c4ae9184000
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3055303
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75946}
This commit is contained in:
Marja Hölttä 2021-07-27 18:22:05 +02:00 committed by V8 LUCI CQ
parent d5212940fb
commit 8c9fc13a4a
8 changed files with 195 additions and 27 deletions

View File

@ -119,7 +119,7 @@ BUILTIN(TypedArrayPrototypeFill) {
ElementsKind kind = array->GetElementsKind();
Handle<Object> 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;

View File

@ -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;
}

View File

@ -3296,7 +3296,7 @@ class TypedElementsAccessor
Handle<JSTypedArray> typed_array = Handle<JSTypedArray>::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<ElementType*>(typed_array->DataPtr());

View File

@ -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],

View File

@ -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));
}
})();

View File

@ -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);
}
}

View File

@ -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));
}
})();

View File

@ -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.