RAB: Integrate staging tests for .byteLength method (#4071)

* RAB: Integrate staging tests for .byteLength method
of TypedArray.prototype

This is part of PR #3888 to make reviewing easier.
Includes changes to use the helper ./harness/resizableArrayBufferUtils.js
This commit is contained in:
Ioanna M Dimitriou H 2024-05-08 17:35:46 +02:00 committed by GitHub
parent 0fca7339eb
commit 55a5346f99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-%typedarray%.prototype.bytelength
description: >
TypedArray.p.byteLength behaves correctly on assorted kinds of receivers
backed by resizable buffers
includes: [compareArray.js, resizableArrayBufferUtils.js]
features: [resizable-arraybuffer]
---*/
const rab = CreateResizableArrayBuffer(40, 80);
for (let ctor of ctors) {
const ta = new ctor(rab, 0, 3);
assert.compareArray(ta.buffer, rab);
assert.sameValue(ta.byteLength, 3 * ctor.BYTES_PER_ELEMENT);
const empty_ta = new ctor(rab, 0, 0);
assert.compareArray(empty_ta.buffer, rab);
assert.sameValue(empty_ta.byteLength, 0);
const ta_with_offset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 3);
assert.compareArray(ta_with_offset.buffer, rab);
assert.sameValue(ta_with_offset.byteLength, 3 * ctor.BYTES_PER_ELEMENT);
const empty_ta_with_offset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 0);
assert.compareArray(empty_ta_with_offset.buffer, rab);
assert.sameValue(empty_ta_with_offset.byteLength, 0);
const length_tracking_ta = new ctor(rab);
assert.compareArray(length_tracking_ta.buffer, rab);
assert.sameValue(length_tracking_ta.byteLength, 40);
const offset = 8;
const length_tracking_ta_with_offset = new ctor(rab, offset);
assert.compareArray(length_tracking_ta_with_offset.buffer, rab);
assert.sameValue(length_tracking_ta_with_offset.byteLength, 40 - offset);
const empty_length_tracking_ta_with_offset = new ctor(rab, 40);
assert.compareArray(empty_length_tracking_ta_with_offset.buffer, rab);
assert.sameValue(empty_length_tracking_ta_with_offset.byteLength, 0);
}