diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/from')
21 files changed, 303 insertions, 11 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/from/arylk-get-length-error.js b/js/src/tests/test262/built-ins/TypedArray/from/arylk-get-length-error.js index 705df14bf9..fb759d77dc 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/arylk-get-length-error.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/arylk-get-length-error.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/js/src/tests/test262/built-ins/TypedArray/from/arylk-to-length-error.js b/js/src/tests/test262/built-ins/TypedArray/from/arylk-to-length-error.js index e4ab814d5f..357362d82e 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/arylk-to-length-error.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/arylk-to-length-error.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/js/src/tests/test262/built-ins/TypedArray/from/from-array-mapper-detaches-result.js b/js/src/tests/test262/built-ins/TypedArray/from/from-array-mapper-detaches-result.js new file mode 100644 index 0000000000..0af40c814e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/from-array-mapper-detaches-result.js @@ -0,0 +1,39 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.from +description: > + If the mapper function detaches the result typed array, .from performs Set operation which ignores out-of-bounds indices. +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +includes: [detachArrayBuffer.js] +features: [TypedArray] +---*/ + +let ab = new ArrayBuffer(3); +let target = new Int8Array(ab); +let values = [0, 1, 2]; + +let result = Int32Array.from.call(function() { + return target; +}, values, v => { + if (v === 1) { + $DETACHBUFFER(ab); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/from-array-mapper-makes-result-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/from/from-array-mapper-makes-result-out-of-bounds.js new file mode 100644 index 0000000000..c3c541a2a8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/from-array-mapper-makes-result-out-of-bounds.js @@ -0,0 +1,40 @@ +// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.from +description: > + If the mapper function makes result typed array out-of-bounds, .from performs Set operation which ignores out-of-bounds indices. +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(3, {maxByteLength: 5}); +let target = new Int8Array(rab); +let values = [0, 1, 2]; + +let result = Int32Array.from.call(function() { + return target; +}, values, v => { + if (v === 1) { + rab.resize(1); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], 10); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-into-itself-mapper-detaches-result.js b/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-into-itself-mapper-detaches-result.js new file mode 100644 index 0000000000..3ef68a8e8d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-into-itself-mapper-detaches-result.js @@ -0,0 +1,39 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.from +description: > + If the mapper function detaches the result typed array, .from performs Set operation which ignores out-of-bounds indices. +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +includes: [detachArrayBuffer.js] +features: [TypedArray] +---*/ + +let ab = new ArrayBuffer(3); +let target = new Int8Array(ab); +target.set([0, 1, 2]); + +let result = Int32Array.from.call(function() { + return target; +}, target, v => { + if (v === 1) { + $DETACHBUFFER(ab); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-into-itself-mapper-makes-result-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-into-itself-mapper-makes-result-out-of-bounds.js new file mode 100644 index 0000000000..d83cf5f5f6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-into-itself-mapper-makes-result-out-of-bounds.js @@ -0,0 +1,40 @@ +// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.from +description: > + If the mapper function makes result typed array out-of-bounds, .from performs Set operation which ignores out-of-bounds indices. +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(3, {maxByteLength: 5}); +let target = new Int8Array(rab); +target.set([0, 1, 2]); + +let result = Int32Array.from.call(function() { + return target; +}, target, v => { + if (v === 1) { + rab.resize(1); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], 10); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-mapper-detaches-result.js b/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-mapper-detaches-result.js new file mode 100644 index 0000000000..25b64bdde8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-mapper-detaches-result.js @@ -0,0 +1,39 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.from +description: > + If the mapper function detaches the result typed array, .from performs Set operation which ignores out-of-bounds indices. +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +includes: [detachArrayBuffer.js] +features: [TypedArray] +---*/ + +let ab = new ArrayBuffer(3); +let target = new Int8Array(ab); +let values = new Int8Array([0, 1, 2]); + +let result = Int32Array.from.call(function() { + return target; +}, values, v => { + if (v === 1) { + $DETACHBUFFER(ab); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-mapper-makes-result-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-mapper-makes-result-out-of-bounds.js new file mode 100644 index 0000000000..389155bfe9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/from-typedarray-mapper-makes-result-out-of-bounds.js @@ -0,0 +1,40 @@ +// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.from +description: > + If the mapper function makes result typed array out-of-bounds, .from performs Set operation which ignores out-of-bounds indices. +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(3, {maxByteLength: 5}); +let target = new Int8Array(rab); +let values = new Int8Array([0, 1, 2]); + +let result = Int32Array.from.call(function() { + return target; +}, values, v => { + if (v === 1) { + rab.resize(1); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], 10); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-func.js index 97ce6b2ff9..364a5d4a24 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-func.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-func.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-method.js b/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-method.js index d2414e0923..9cafb59fdf 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-method.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/invoked-as-method.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/js/src/tests/test262/built-ins/TypedArray/from/iter-access-error.js b/js/src/tests/test262/built-ins/TypedArray/from/iter-access-error.js index b37537d19e..5d37f8179c 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/iter-access-error.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/iter-access-error.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/js/src/tests/test262/built-ins/TypedArray/from/iter-invoke-error.js b/js/src/tests/test262/built-ins/TypedArray/from/iter-invoke-error.js index de395eb2dc..99605d1254 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/iter-invoke-error.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/iter-invoke-error.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/js/src/tests/test262/built-ins/TypedArray/from/iter-next-error.js b/js/src/tests/test262/built-ins/TypedArray/from/iter-next-error.js index 7cbea13246..7783529181 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/iter-next-error.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/iter-next-error.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/js/src/tests/test262/built-ins/TypedArray/from/iter-next-value-error.js b/js/src/tests/test262/built-ins/TypedArray/from/iter-next-value-error.js index a1674c417b..3742e273ab 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/iter-next-value-error.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/iter-next-value-error.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/js/src/tests/test262/built-ins/TypedArray/from/iterated-array-changed-by-tonumber.js b/js/src/tests/test262/built-ins/TypedArray/from/iterated-array-changed-by-tonumber.js new file mode 100644 index 0000000000..a0d6099170 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/from/iterated-array-changed-by-tonumber.js @@ -0,0 +1,39 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.from +description: > + Modifications to input array after iteration are handled correctly. +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 6. If usingIterator is not undefined, then + a. Let values be ? IteratorToList(? GetIteratorFromMethod(source, usingIterator)). + b. Let len be the number of elements in values. + ... + e. Repeat, while k < len, + ... + vi. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +features: [TypedArray] +---*/ + +let values = [0, { + valueOf() { + // Removes all array elements. Caller must have saved all elements. + values.length = 0; + return 100; + } +}, 2]; + +// `from` called with array which uses the built-in array iterator. +let ta = Int32Array.from(values); + +assert.sameValue(ta.length, 3); +assert.sameValue(ta[0], 0); +assert.sameValue(ta[1], 100); +assert.sameValue(ta[2], 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/length.js b/js/src/tests/test262/built-ins/TypedArray/from/length.js index 6ec675f750..27d8ecb128 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/length.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/length.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2015 André Bargull. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. @@ -24,10 +25,11 @@ includes: [propertyHelper.js, testTypedArray.js] features: [TypedArray] ---*/ -assert.sameValue(TypedArray.from.length, 1); - -verifyNotEnumerable(TypedArray.from, "length"); -verifyNotWritable(TypedArray.from, "length"); -verifyConfigurable(TypedArray.from, "length"); +verifyProperty(TypedArray.from, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/mapfn-is-not-callable.js b/js/src/tests/test262/built-ins/TypedArray/from/mapfn-is-not-callable.js index ece0766bee..42fa25ef61 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/mapfn-is-not-callable.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/mapfn-is-not-callable.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/js/src/tests/test262/built-ins/TypedArray/from/name.js b/js/src/tests/test262/built-ins/TypedArray/from/name.js index 9fa98be4e7..888eecdb3f 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/name.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/name.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2015 André Bargull. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. @@ -20,10 +21,11 @@ includes: [propertyHelper.js, testTypedArray.js] features: [TypedArray] ---*/ -assert.sameValue(TypedArray.from.name, "from"); - -verifyNotEnumerable(TypedArray.from, "name"); -verifyNotWritable(TypedArray.from, "name"); -verifyConfigurable(TypedArray.from, "name"); +verifyProperty(TypedArray.from, "name", { + value: "from", + writable: false, + enumerable: false, + configurable: true +}); reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/from/not-a-constructor.js index 41a794dfca..72a0817679 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/not-a-constructor.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/not-a-constructor.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2020 Rick Waldron. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. @@ -25,7 +26,7 @@ assert.sameValue(isConstructor(TypedArray.from), false, 'isConstructor(TypedArra assert.throws(TypeError, () => { new TypedArray.from([]); -}, '`new TypedArray.from([])` throws TypeError'); +}); reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/from/prop-desc.js b/js/src/tests/test262/built-ins/TypedArray/from/prop-desc.js index 7dd61adf7d..bc9f0ca5ee 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/prop-desc.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/prop-desc.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/js/src/tests/test262/built-ins/TypedArray/from/this-is-not-constructor.js b/js/src/tests/test262/built-ins/TypedArray/from/this-is-not-constructor.js index 7838753ba5..821152f3c1 100644 --- a/js/src/tests/test262/built-ins/TypedArray/from/this-is-not-constructor.js +++ b/js/src/tests/test262/built-ins/TypedArray/from/this-is-not-constructor.js @@ -1,3 +1,4 @@ +// |reftest| shell-option(--enable-float16array) // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- |