summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset')
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/detached-buffer.js24
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-auto.js53
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-fixed.js49
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/return-byteoffset.js33
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/shell.js42
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/detached-buffer.js24
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/invoked-as-accessor.js25
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/invoked-as-func.js27
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/length.js34
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/name.js31
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/prop-desc.js26
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto.js53
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-fixed.js49
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/return-byteoffset.js33
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/this-has-no-typedarrayname-internal.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/this-is-not-object.js50
19 files changed, 596 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/browser.js
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/detached-buffer.js
new file mode 100644
index 0000000000..0a10adbbc2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/detached-buffer.js
@@ -0,0 +1,24 @@
+// Copyright (C) 2016 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.byteoffset
+description: Returns 0 if the instance has a detached buffer
+info: |
+ 22.2.3.3 get %TypedArray%.prototype.byteOffset
+
+ ...
+ 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
+ 5. If IsDetachedBuffer(buffer) is true, return 0.
+ ...
+includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var buffer = new ArrayBuffer(128);
+ var sample = new TA(buffer, 8, 1);
+ $DETACHBUFFER(sample.buffer);
+ assert.sameValue(sample.byteOffset, 0);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-auto.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-auto.js
new file mode 100644
index 0000000000..82604a178c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-auto.js
@@ -0,0 +1,53 @@
+// |reftest| skip -- resizable-arraybuffer is not supported
+// Copyright (C) 2021 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.byteoffset
+description: |
+ reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of
+ the dynamically-sized TypedArray instance
+includes: [testBigIntTypedArray.js]
+features: [ArrayBuffer, BigInt, TypedArray, resizable-arraybuffer]
+---*/
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ArrayBuffer.prototype.resize, "function");
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var BPE = TA.BYTES_PER_ELEMENT;
+ var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
+ var array = new TA(ab, BPE);
+
+ assert.sameValue(array.byteOffset, BPE);
+
+ try {
+ ab.resize(BPE * 5);
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, BPE, "following grow");
+
+ try {
+ ab.resize(BPE * 3);
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)");
+
+ try {
+ ab.resize(BPE);
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, BPE, "following shrink (on boundary)");
+
+ var expected = BPE;
+ try {
+ ab.resize(0);
+ expected = 0;
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-fixed.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-fixed.js
new file mode 100644
index 0000000000..f047af9c48
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-fixed.js
@@ -0,0 +1,49 @@
+// |reftest| skip -- resizable-arraybuffer is not supported
+// Copyright (C) 2021 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.byteoffset
+description: |
+ reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of
+ the fixed-sized TypedArray instance
+includes: [testBigIntTypedArray.js]
+features: [ArrayBuffer, BigInt, TypedArray, resizable-arraybuffer]
+---*/
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ArrayBuffer.prototype.resize, "function");
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var BPE = TA.BYTES_PER_ELEMENT;
+ var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
+ var array = new TA(ab, BPE, 2);
+
+ assert.sameValue(array.byteOffset, BPE);
+
+ try {
+ ab.resize(BPE * 5);
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, BPE, "following grow");
+
+ try {
+ ab.resize(BPE * 3);
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)");
+
+ var expected;
+ try {
+ ab.resize(BPE * 2);
+ expected = 0;
+ } catch (_) {
+ expected = BPE;
+ }
+
+ assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/return-byteoffset.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/return-byteoffset.js
new file mode 100644
index 0000000000..3849eab69b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/return-byteoffset.js
@@ -0,0 +1,33 @@
+// Copyright (C) 2016 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.byteoffset
+description: >
+ Return value from [[ByteOffset]] internal slot
+info: |
+ 22.2.3.3 get %TypedArray%.prototype.byteOffset
+
+ ...
+ 6. Let offset be the value of O's [[ByteOffset]] internal slot.
+ 7. Return size.
+includes: [testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var ta1 = new TA();
+ assert.sameValue(ta1.byteOffset, 0, "Regular typedArray");
+
+ var offset = 4 * TA.BYTES_PER_ELEMENT;
+
+ var buffer1 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT);
+ var ta2 = new TA(buffer1, offset);
+ assert.sameValue(ta2.byteOffset, offset, "TA(buffer, offset)");
+
+ var buffer2 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT);
+ var sample = new TA(buffer2, offset);
+ var ta3 = new TA(sample);
+ assert.sameValue(ta3.byteOffset, 0, "TA(typedArray)");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/shell.js
new file mode 100644
index 0000000000..90ee9c114d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/BigInt/shell.js
@@ -0,0 +1,42 @@
+// GENERATED, DO NOT EDIT
+// file: testBigIntTypedArray.js
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+description: |
+ Collection of functions used to assert the correctness of BigInt TypedArray objects.
+defines:
+ - TypedArray
+ - testWithBigIntTypedArrayConstructors
+---*/
+
+/**
+ * The %TypedArray% intrinsic constructor function.
+ */
+var TypedArray = Object.getPrototypeOf(Int8Array);
+
+/**
+ * Calls the provided function for every typed array constructor.
+ *
+ * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
+ * @param {Array} selected - An optional Array with filtered typed arrays
+ */
+function testWithBigIntTypedArrayConstructors(f, selected) {
+ /**
+ * Array containing every BigInt typed array constructor.
+ */
+ var constructors = selected || [
+ BigInt64Array,
+ BigUint64Array
+ ];
+
+ for (var i = 0; i < constructors.length; ++i) {
+ var constructor = constructors[i];
+ try {
+ f(constructor);
+ } catch (e) {
+ e.message += " (Testing with " + constructor.name + ".)";
+ throw e;
+ }
+ }
+}
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/browser.js
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/detached-buffer.js
new file mode 100644
index 0000000000..e831fd0232
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/detached-buffer.js
@@ -0,0 +1,24 @@
+// Copyright (C) 2016 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.byteoffset
+description: Returns 0 if the instance has a detached buffer
+info: |
+ 22.2.3.3 get %TypedArray%.prototype.byteOffset
+
+ ...
+ 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
+ 5. If IsDetachedBuffer(buffer) is true, return 0.
+ ...
+includes: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var buffer = new ArrayBuffer(128);
+ var sample = new TA(buffer, 8, 1);
+ $DETACHBUFFER(sample.buffer);
+ assert.sameValue(sample.byteOffset, 0);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/invoked-as-accessor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/invoked-as-accessor.js
new file mode 100644
index 0000000000..7ebe5f7ff2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/invoked-as-accessor.js
@@ -0,0 +1,25 @@
+// Copyright (C) 2016 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.byteoffset
+description: >
+ Requires this value to have a [[ViewedArrayBuffer]] internal slot
+info: |
+ 22.2.3.3 get %TypedArray%.prototype.byteOffset
+
+ 1. Let O be the this value.
+ 2. If Type(O) is not Object, throw a TypeError exception.
+ 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError
+ exception.
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var TypedArrayPrototype = TypedArray.prototype;
+
+assert.throws(TypeError, function() {
+ TypedArrayPrototype.byteOffset;
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/invoked-as-func.js
new file mode 100644
index 0000000000..e7ff71bfef
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/invoked-as-func.js
@@ -0,0 +1,27 @@
+// Copyright (C) 2016 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.byteoffset
+description: Throws a TypeError exception when invoked as a function
+info: |
+ 22.2.3.3 get %TypedArray%.prototype.byteOffset
+
+ 1. Let O be the this value.
+ 2. If Type(O) is not Object, throw a TypeError exception.
+ 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError
+ exception.
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var TypedArrayPrototype = TypedArray.prototype;
+var getter = Object.getOwnPropertyDescriptor(
+ TypedArrayPrototype, 'byteOffset'
+).get;
+
+assert.throws(TypeError, function() {
+ getter();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/length.js
new file mode 100644
index 0000000000..f8e16555cb
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/length.js
@@ -0,0 +1,34 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-get-%typedarray%.prototype.byteoffset
+description: >
+ get %TypedArray%.prototype.byteOffset.length is 0.
+info: |
+ get %TypedArray%.prototype.byteOffset
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, has a length
+ property whose value is an integer. Unless otherwise specified, this
+ value is equal to the largest number of named arguments shown in the
+ subclause headings for the function description, including optional
+ parameters. However, rest parameters shown using the form “...name”
+ are not included in the default argument count.
+
+ Unless otherwise specified, the length property of a built-in Function
+ object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
+ [[Configurable]]: true }.
+includes: [propertyHelper.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var desc = Object.getOwnPropertyDescriptor(TypedArray.prototype, "byteOffset");
+
+assert.sameValue(desc.get.length, 0);
+
+verifyNotEnumerable(desc.get, "length");
+verifyNotWritable(desc.get, "length");
+verifyConfigurable(desc.get, "length");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/name.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/name.js
new file mode 100644
index 0000000000..4a2e7d3ea3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/name.js
@@ -0,0 +1,31 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-get-%typedarray%.prototype.byteoffset
+description: >
+ get %TypedArray%.prototype.byteOffset.name is "get byteOffset".
+info: |
+ get %TypedArray%.prototype.byteOffset
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, that is not
+ identified as an anonymous function has a name property whose value
+ is a String.
+
+ Unless otherwise specified, the name property of a built-in Function
+ object, if it exists, has the attributes { [[Writable]]: false,
+ [[Enumerable]]: false, [[Configurable]]: true }.
+includes: [propertyHelper.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var desc = Object.getOwnPropertyDescriptor(TypedArray.prototype, "byteOffset");
+
+assert.sameValue(desc.get.name, "get byteOffset");
+
+verifyNotEnumerable(desc.get, "name");
+verifyNotWritable(desc.get, "name");
+verifyConfigurable(desc.get, "name");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/prop-desc.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/prop-desc.js
new file mode 100644
index 0000000000..8d6f554f4a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/prop-desc.js
@@ -0,0 +1,26 @@
+// Copyright (C) 2016 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.byteoffset
+description: >
+ "byteOffset" property of TypedArrayPrototype
+info: |
+ %TypedArray%.prototype.byteOffset is an accessor property whose set accessor
+ function is undefined.
+
+ Section 17: Every accessor property described in clauses 18 through 26 and in
+ Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true }
+includes: [propertyHelper.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var TypedArrayPrototype = TypedArray.prototype;
+var desc = Object.getOwnPropertyDescriptor(TypedArrayPrototype, "byteOffset");
+
+assert.sameValue(desc.set, undefined);
+assert.sameValue(typeof desc.get, "function");
+
+verifyNotEnumerable(TypedArrayPrototype, "byteOffset");
+verifyConfigurable(TypedArrayPrototype, "byteOffset");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto.js
new file mode 100644
index 0000000000..3f90222055
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto.js
@@ -0,0 +1,53 @@
+// |reftest| skip -- resizable-arraybuffer is not supported
+// Copyright (C) 2021 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.byteoffset
+description: |
+ reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of
+ the dynamically-sized TypedArray instance
+includes: [testTypedArray.js]
+features: [TypedArray, resizable-arraybuffer]
+---*/
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ArrayBuffer.prototype.resize, "function");
+
+testWithTypedArrayConstructors(function(TA) {
+ var BPE = TA.BYTES_PER_ELEMENT;
+ var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
+ var array = new TA(ab, BPE);
+
+ assert.sameValue(array.byteOffset, BPE);
+
+ try {
+ ab.resize(BPE * 5);
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, BPE, "following grow");
+
+ try {
+ ab.resize(BPE * 3);
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)");
+
+ try {
+ ab.resize(BPE);
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, BPE, "following shrink (on boundary)");
+
+ var expected = BPE;
+ try {
+ ab.resize(0);
+ expected = 0;
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-fixed.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-fixed.js
new file mode 100644
index 0000000000..66555faa47
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/resizable-array-buffer-fixed.js
@@ -0,0 +1,49 @@
+// |reftest| skip -- resizable-arraybuffer is not supported
+// Copyright (C) 2021 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.byteoffset
+description: |
+ reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of
+ the fixed-sized TypedArray instance
+includes: [testTypedArray.js]
+features: [TypedArray, resizable-arraybuffer]
+---*/
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ArrayBuffer.prototype.resize, "function");
+
+testWithTypedArrayConstructors(function(TA) {
+ var BPE = TA.BYTES_PER_ELEMENT;
+ var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5});
+ var array = new TA(ab, BPE, 2);
+
+ assert.sameValue(array.byteOffset, BPE);
+
+ try {
+ ab.resize(BPE * 5);
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, BPE, "following grow");
+
+ try {
+ ab.resize(BPE * 3);
+ } catch (_) {}
+
+ assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)");
+
+ var expected;
+ try {
+ ab.resize(BPE * 2);
+ expected = 0;
+ } catch (_) {
+ expected = BPE;
+ }
+
+ assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/return-byteoffset.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/return-byteoffset.js
new file mode 100644
index 0000000000..889aef45b5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/return-byteoffset.js
@@ -0,0 +1,33 @@
+// Copyright (C) 2016 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.byteoffset
+description: >
+ Return value from [[ByteOffset]] internal slot
+info: |
+ 22.2.3.3 get %TypedArray%.prototype.byteOffset
+
+ ...
+ 6. Let offset be the value of O's [[ByteOffset]] internal slot.
+ 7. Return size.
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta1 = new TA();
+ assert.sameValue(ta1.byteOffset, 0, "Regular typedArray");
+
+ var offset = 4 * TA.BYTES_PER_ELEMENT;
+
+ var buffer1 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT);
+ var ta2 = new TA(buffer1, offset);
+ assert.sameValue(ta2.byteOffset, offset, "TA(buffer, offset)");
+
+ var buffer2 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT);
+ var sample = new TA(buffer2, offset);
+ var ta3 = new TA(sample);
+ assert.sameValue(ta3.byteOffset, 0, "TA(typedArray)");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/shell.js
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/this-has-no-typedarrayname-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/this-has-no-typedarrayname-internal.js
new file mode 100644
index 0000000000..4388d3d760
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/this-has-no-typedarrayname-internal.js
@@ -0,0 +1,43 @@
+// Copyright (C) 2016 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.byteoffset
+description: >
+ Throws a TypeError exception when `this` does not have a [[TypedArrayName]]
+ internal slot
+info: |
+ 22.2.3.3 get %TypedArray%.prototype.byteOffset
+
+ 1. Let O be the this value.
+ 2. If Type(O) is not Object, throw a TypeError exception.
+ 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError
+ exception.
+ ...
+includes: [testTypedArray.js]
+features: [DataView, TypedArray]
+---*/
+
+var TypedArrayPrototype = TypedArray.prototype;
+var getter = Object.getOwnPropertyDescriptor(
+ TypedArrayPrototype, "byteOffset"
+).get;
+
+assert.throws(TypeError, function() {
+ getter.call({});
+});
+
+assert.throws(TypeError, function() {
+ getter.call([]);
+});
+
+var ab = new ArrayBuffer(8);
+assert.throws(TypeError, function() {
+ getter.call(ab);
+});
+
+var dv = new DataView(new ArrayBuffer(8), 0);
+assert.throws(TypeError, function() {
+ getter.call(dv);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/this-is-not-object.js b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/this-is-not-object.js
new file mode 100644
index 0000000000..da5c78ed28
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/byteOffset/this-is-not-object.js
@@ -0,0 +1,50 @@
+// Copyright (C) 2016 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.byteoffset
+description: Throws a TypeError exception when `this` is not Object
+info: |
+ 22.2.3.3 get %TypedArray%.prototype.byteOffset
+
+ 1. Let O be the this value.
+ 2. If Type(O) is not Object, throw a TypeError exception.
+ ...
+includes: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var TypedArrayPrototype = TypedArray.prototype;
+var getter = Object.getOwnPropertyDescriptor(
+ TypedArrayPrototype, "byteOffset"
+).get;
+
+assert.throws(TypeError, function() {
+ getter.call(undefined);
+}, "this is undefined");
+
+assert.throws(TypeError, function() {
+ getter.call(null);
+}, "this is null");
+
+assert.throws(TypeError, function() {
+ getter.call(42);
+}, "this is 42");
+
+assert.throws(TypeError, function() {
+ getter.call("1");
+}, "this is a string");
+
+assert.throws(TypeError, function() {
+ getter.call(true);
+}, "this is true");
+
+assert.throws(TypeError, function() {
+ getter.call(false);
+}, "this is false");
+
+var s = Symbol("s");
+assert.throws(TypeError, function() {
+ getter.call(s);
+}, "this is a Symbol");
+
+reportCompare(0, 0);