diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt')
11 files changed, 452 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/custom-separator-result-from-tostring-on-each-simple-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/custom-separator-result-from-tostring-on-each-simple-value.js new file mode 100644 index 0000000000..f1bd47bc53 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/custom-separator-result-from-tostring-on-each-simple-value.js @@ -0,0 +1,80 @@ +// 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-%typedarray%.prototype.join +description: > + Concatenates the result of toString for each value with custom separator +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 7. If element0 is undefined or null, let R be the empty String; otherwise, let + R be ? ToString(element0). + 8. Let k be 1. + 9. Repeat, while k < len + a. Let S be the String value produced by concatenating R and sep. + b. Let element be ? Get(O, ! ToString(k)). + c. If element is undefined or null, let next be the empty String; otherwise, + let next be ? ToString(element). + d. Let R be a String value produced by concatenating S and next. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 0n, 2n, 3n, 42n, 127n]); + + var result; + + result = sample.join(","); + assert.sameValue(result, "1,0,2,3,42,127"); + + result = sample.join(undefined); + assert.sameValue(result, "1,0,2,3,42,127"); + + result = sample.join(null); + assert.sameValue(result, "1null0null2null3null42null127"); + + result = sample.join(",,"); + assert.sameValue(result, "1,,0,,2,,3,,42,,127"); + + result = sample.join(0); + assert.sameValue(result, "10002030420127"); + + result = sample.join(""); + assert.sameValue(result, "102342127"); + + result = sample.join(" a b c "); + assert.sameValue(result, "1 a b c 0 a b c 2 a b c 3 a b c 42 a b c 127"); + + result = sample.join({}); + assert.sameValue(result, "1[object Object]0[object Object]2[object Object]3[object Object]42[object Object]127"); + + result = sample.join(true); + assert.sameValue(result, "1true0true2true3true42true127"); + + result = sample.join({ toString: function() { return "foo"; }}); + assert.sameValue(result, "1foo0foo2foo3foo42foo127"); + + result = sample.join({ toString: undefined, valueOf: function() { return "bar"; }}); + assert.sameValue(result, "1bar0bar2bar3bar42bar127"); + + result = sample.join(false); + assert.sameValue(result, "1false0false2false3false42false127"); + + result = sample.join(-1); + assert.sameValue(result, "1-10-12-13-142-1127"); + + result = sample.join(-0); + assert.sameValue(result, "10002030420127"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js new file mode 100644 index 0000000000..d5d51beb51 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js @@ -0,0 +1,44 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.join +description: Returns single separator if buffer is detached after ValidateTypedArray +info: | + %TypedArray%.prototype.join ( separator ) + + The interpretation and use of the arguments of %TypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15. + + When the join method is called with one argument separator, the following steps are taken: + + Let O be the this value. + Perform ? ValidateTypedArray(O). + Let len be O.[[ArrayLength]]. + If separator is undefined, let sep be the single-element String ",". + Else, let sep be ? ToString(separator). + Let R be the empty String. + Let k be 0. + Repeat, while k < len, + If k > 0, set R to the string-concatenation of R and sep. + Let element be ! Get(O, ! ToString(𝔽(k))). + If element is undefined or null, let next be the empty String; otherwise, let next be ! ToString(element). + Set R to the string-concatenation of R and next. + Set k to k + 1. + Return R. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA([1n,2n,3n]); + const separator = { + toString() { + $DETACHBUFFER(sample.buffer); + return ','; + } + }; + + assert.sameValue(sample.join(separator), ',,'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/detached-buffer.js new file mode 100644 index 0000000000..e7aeb7c15e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/detached-buffer.js @@ -0,0 +1,35 @@ +// 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-%typedarray%.prototype.join +description: Throws a TypeError if this has a detached buffer +info: | + %TypedArray%.prototype.join ( separator ) + + The interpretation and use of the arguments of %TypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15. + + When the join method is called with one argument separator, the following steps are taken: + + Let O be the this value. + Perform ? ValidateTypedArray(O). + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +let obj = { + toString() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, () => { + sample.join(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/empty-instance-empty-string.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/empty-instance-empty-string.js new file mode 100644 index 0000000000..3636e8c8a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/empty-instance-empty-string.js @@ -0,0 +1,31 @@ +// 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-%typedarray%.prototype.join +description: Return the empty String if length is 0 +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.sameValue(sample.join(), ""); + assert.sameValue(sample.join("test262"), ""); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/get-length-uses-internal-arraylength.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000..28e6929360 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,47 @@ +// 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-%typedarray%.prototype.join +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... + 5. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.join(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.notSameValue(result, "", "result is not affected but custom length 0"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/result-from-tostring-on-each-simple-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/result-from-tostring-on-each-simple-value.js new file mode 100644 index 0000000000..905cb9dc48 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/result-from-tostring-on-each-simple-value.js @@ -0,0 +1,39 @@ +// 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-%typedarray%.prototype.join +description: Concatenates the result of toString for each simple value +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 7. If element0 is undefined or null, let R be the empty String; otherwise, let + R be ? ToString(element0). + 8. Let k be 1. + 9. Repeat, while k < len + a. Let S be the String value produced by concatenating R and sep. + b. Let element be ? Get(O, ! ToString(k)). + c. If element is undefined or null, let next be the empty String; otherwise, + let next be ? ToString(element). + d. Let R be a String value produced by concatenating S and next. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 0n, 2n, 3n, 42n, 127n]); + + var result = sample.join(); + + assert.sameValue(result, "1,0,2,3,42,127"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator-symbol.js new file mode 100644 index 0000000000..d4162a247f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator-symbol.js @@ -0,0 +1,34 @@ +// 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-%typedarray%.prototype.join +description: Return abrupt from ToString(Symbol separator) +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol(""); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.join(s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator.js new file mode 100644 index 0000000000..6c280a1326 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator.js @@ -0,0 +1,38 @@ +// 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-%typedarray%.prototype.join +description: Return abrupt from ToString(separator) +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.join(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..7b8d2a5db7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |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-%typedarray%.prototype.join +description: Return abrupt when "this" value fails buffer boundary checks +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, TypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof TypedArray.prototype.join, + 'function', + 'implements TypedArray.prototype.join' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.join(','); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.join(','); + + var expectedError; + try { + ab.resize(BPE * 2); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the join operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.join(','); + throw new Test262Error('join completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/join/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/join/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; + } + } +} |