Commit ce1a9ab6 authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

[rab/gsab] Enable code paths needed for BigInt TypedArrays

Bug: v8:11111
Change-Id: Ib3ae55349024ebeab9ceaf9472a6de2b4d86ce55
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3056975Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75993}
parent 2442ea5e
......@@ -622,6 +622,11 @@ DEF_GETTER(JSObject, HasTypedArrayElements, bool) {
return map(cage_base).has_typed_array_elements();
}
DEF_GETTER(JSObject, HasTypedArrayOrRabGsabTypedArrayElements, bool) {
DCHECK(!elements(cage_base).is_null());
return map(cage_base).has_typed_array_or_rab_gsab_typed_array_elements();
}
#define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype) \
DEF_GETTER(JSObject, HasFixed##Type##Elements, bool) { \
return map(cage_base).elements_kind() == TYPE##_ELEMENTS; \
......
......@@ -364,6 +364,7 @@ class JSObject : public TorqueGeneratedJSObject<JSObject, JSReceiver> {
DECL_GETTER(HasNonextensibleElements, bool)
DECL_GETTER(HasTypedArrayElements, bool)
DECL_GETTER(HasTypedArrayOrRabGsabTypedArrayElements, bool)
DECL_GETTER(HasFixedUint8ClampedElements, bool)
DECL_GETTER(HasFixedArrayElements, bool)
......
......@@ -2770,12 +2770,11 @@ Maybe<bool> Object::SetDataProperty(LookupIterator* it, Handle<Object> value) {
Handle<Object> to_assign = value;
// Convert the incoming value to a number for storing into typed arrays.
// TODO(v8:11111): Support RAB / GSAB.
if (it->IsElement() && receiver->IsJSObject(isolate) &&
JSObject::cast(*receiver).HasTypedArrayElements(isolate)) {
JSObject::cast(*receiver).HasTypedArrayOrRabGsabTypedArrayElements(
isolate)) {
ElementsKind elements_kind = JSObject::cast(*receiver).GetElementsKind();
if (elements_kind == BIGINT64_ELEMENTS ||
elements_kind == BIGUINT64_ELEMENTS) {
if (IsBigIntTypedArrayElementsKind(elements_kind)) {
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, to_assign,
BigInt::FromObject(isolate, value),
Nothing<bool>());
......
......@@ -8,22 +8,6 @@
d8.file.execute('test/mjsunit/typedarray-helpers.js');
class MyUint8Array extends Uint8Array {};
const ctors = [
Uint8Array,
Int8Array,
Uint16Array,
Int16Array,
Int32Array,
Float32Array,
Float64Array,
Uint8ClampedArray,
BigUint64Array,
BigInt64Array,
MyUint8Array
];
function CreateGrowableSharedArrayBuffer(byteLength, maxByteLength) {
return new SharedArrayBuffer(byteLength, {maxByteLength: maxByteLength});
}
......@@ -404,17 +388,12 @@ function CreateGrowableSharedArrayBuffer(byteLength, maxByteLength) {
function TestIteration(ta, expected) {
let values = [];
for (const value of ta) {
values.push(value);
values.push(Number(value));
}
assertEquals(expected, values);
}
for (let ctor of ctors) {
if (ctor == BigInt64Array || ctor == BigUint64Array) {
// This test doesn't work for BigInts.
continue;
}
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
// We can use the same GSAB for all the TAs below, since we won't modify it
// after writing the initial values.
......@@ -425,7 +404,7 @@ function CreateGrowableSharedArrayBuffer(byteLength, maxByteLength) {
// Write some data into the array.
let ta_write = new ctor(gsab);
for (let i = 0; i < no_elements; ++i) {
ta_write[i] = i % 128;
WriteToTypedArray(ta_write, i, i % 128);
}
// Create various different styles of TypedArrays with the GSAB as the
......@@ -468,11 +447,11 @@ function CreateGrowableSharedArrayBuffer(byteLength, maxByteLength) {
// Helpers for iteration tests.
function CreateGsab(buffer_byte_length, ctor) {
const gsab = CreateGrowableSharedArrayBuffer(buffer_byte_length,
2 * buffer_byte_length);
2 * buffer_byte_length);
// Write some data into the array.
let ta_write = new ctor(gsab);
for (let i = 0; i < buffer_byte_length / ctor.BYTES_PER_ELEMENT; ++i) {
ta_write[i] = i % 128;
WriteToTypedArray(ta_write, i, i % 128);
}
return gsab;
}
......@@ -482,7 +461,7 @@ function TestIterationAndGrow(ta, expected, gsab, grow_after,
let values = [];
let grown = false;
for (const value of ta) {
values.push(value);
values.push(Number(value));
if (!grown && values.length == grow_after) {
gsab.grow(new_byte_length);
grown = true;
......@@ -497,10 +476,6 @@ function TestIterationAndGrow(ta, expected, gsab, grow_after,
const offset = 2;
for (let ctor of ctors) {
if (ctor == BigInt64Array || ctor == BigUint64Array) {
// This test doesn't work for BigInts.
continue;
}
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
......@@ -555,10 +530,6 @@ function TestIterationAndGrow(ta, expected, gsab, grow_after,
// We need to recreate the gsab between all TA tests, since we grow it.
for (let ctor of ctors) {
if (ctor == BigInt64Array || ctor == BigUint64Array) {
// This test doesn't work for BigInts.
continue;
}
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
......
......@@ -2,6 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
class MyUint8Array extends Uint8Array {};
class MyBigInt64Array extends BigInt64Array {};
const ctors = [
Uint8Array,
Int8Array,
Uint16Array,
Int16Array,
Int32Array,
Float32Array,
Float64Array,
Uint8ClampedArray,
BigUint64Array,
BigInt64Array,
MyUint8Array,
MyBigInt64Array,
];
function ReadDataFromBuffer(ab, ctor) {
let result = [];
const ta = new ctor(ab, 0, ab.byteLength / ctor.BYTES_PER_ELEMENT);
......@@ -11,6 +29,15 @@ function ReadDataFromBuffer(ab, ctor) {
return result;
}
function WriteToTypedArray(array, index, value) {
if (array instanceof BigInt64Array ||
array instanceof BigUint64Array) {
array[index] = BigInt(value);
} else {
array[index] = value;
}
}
function FillHelper(ta, n, start, end) {
if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) {
ta.fill(BigInt(n), start, end);
......
......@@ -8,22 +8,6 @@
d8.file.execute('test/mjsunit/typedarray-helpers.js');
class MyUint8Array extends Uint8Array {};
const ctors = [
Uint8Array,
Int8Array,
Uint16Array,
Int16Array,
Int32Array,
Float32Array,
Float64Array,
Uint8ClampedArray,
BigUint64Array,
BigInt64Array,
MyUint8Array
];
function CreateResizableArrayBuffer(byteLength, maxByteLength) {
return new ArrayBuffer(byteLength, {maxByteLength: maxByteLength});
}
......@@ -677,17 +661,12 @@ function CreateResizableArrayBuffer(byteLength, maxByteLength) {
function TestIteration(ta, expected) {
let values = [];
for (const value of ta) {
values.push(value);
values.push(Number(value));
}
assertEquals(expected, values);
}
for (let ctor of ctors) {
if (ctor == BigInt64Array || ctor == BigUint64Array) {
// This test doesn't work for BigInts.
continue;
}
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
// We can use the same RAB for all the TAs below, since we won't modify it
// after writing the initial values.
......@@ -698,7 +677,7 @@ function CreateResizableArrayBuffer(byteLength, maxByteLength) {
// Write some data into the array.
let ta_write = new ctor(rab);
for (let i = 0; i < no_elements; ++i) {
ta_write[i] = i % 128;
WriteToTypedArray(ta_write, i, i % 128);
}
// Create various different styles of TypedArrays with the RAB as the
......@@ -741,11 +720,11 @@ function CreateResizableArrayBuffer(byteLength, maxByteLength) {
// Helpers for iteration tests.
function CreateRab(buffer_byte_length, ctor) {
const rab = CreateResizableArrayBuffer(buffer_byte_length,
2 * buffer_byte_length);
2 * buffer_byte_length);
// Write some data into the array.
let ta_write = new ctor(rab);
for (let i = 0; i < buffer_byte_length / ctor.BYTES_PER_ELEMENT; ++i) {
ta_write[i] = i % 128;
WriteToTypedArray(ta_write, i, i % 128);
}
return rab;
}
......@@ -755,7 +734,7 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
let values = [];
let resized = false;
for (const value of ta) {
values.push(value);
values.push(Number(value));
if (!resized && values.length == resize_after) {
rab.resize(new_byte_length);
resized = true;
......@@ -770,10 +749,6 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
const offset = 2;
for (let ctor of ctors) {
if (ctor == BigInt64Array || ctor == BigUint64Array) {
// This test doesn't work for BigInts.
continue;
}
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
......@@ -828,10 +803,6 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
// We need to recreate the RAB between all TA tests, since we grow it.
for (let ctor of ctors) {
if (ctor == BigInt64Array || ctor == BigUint64Array) {
// This test doesn't work for BigInts.
continue;
}
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
......@@ -875,10 +846,6 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
const offset = 2;
for (let ctor of ctors) {
if (ctor == BigInt64Array || ctor == BigUint64Array) {
// This test doesn't work for BigInts.
continue;
}
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
......@@ -935,10 +902,6 @@ function TestIterationAndResize(ta, expected, rab, resize_after,
const offset = 2;
for (let ctor of ctors) {
if (ctor == BigInt64Array || ctor == BigUint64Array) {
// This test doesn't work for BigInts.
continue;
}
const buffer_byte_length = no_elements * ctor.BYTES_PER_ELEMENT;
const byte_offset = offset * ctor.BYTES_PER_ELEMENT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment