diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt')
21 files changed, 986 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-custom-accumulator.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-custom-accumulator.js new file mode 100644 index 0000000000..9de661f3cd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-custom-accumulator.js @@ -0,0 +1,61 @@ +// 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.reduceright +description: > + callbackfn arguments using custom accumulator +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.reduceRight(function(accumulator) { + results.push(arguments); + return accumulator + 1; + }, 7); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 4, "results[0].length"); + assert.sameValue(results[0][0], 7, "results[0][0] - accumulator"); + assert.sameValue(results[0][1], 44n, "results[0][1] - kValue"); + assert.sameValue(results[0][2], 2, "results[0][2] - k"); + assert.sameValue(results[0][3], sample, "results[0][3] - this"); + + assert.sameValue(results[1].length, 4, "results[1].length"); + assert.sameValue(results[1][0], 8, "results[1][0] - accumulator"); + assert.sameValue(results[1][1], 43n, "results[1][1] - kValue"); + assert.sameValue(results[1][2], 1, "results[1][2] - k"); + assert.sameValue(results[1][3], sample, "results[1][3] - this"); + + assert.sameValue(results[2].length, 4, "results[2].length"); + assert.sameValue(results[2][0], 9, "results[2][0] - accumulator"); + assert.sameValue(results[2][1], 42n, "results[2][1] - kValue"); + assert.sameValue(results[2][2], 0, "results[2][2] - k"); + assert.sameValue(results[2][3], sample, "results[2][3] - this"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-default-accumulator.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-default-accumulator.js new file mode 100644 index 0000000000..9f57accb0a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-default-accumulator.js @@ -0,0 +1,64 @@ +// 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.reduceright +description: > + callbackfn arguments using default accumulator (value at last index) +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.reduceRight(function(accumulator) { + results.push(arguments); + return accumulator + 1n; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0].length, 4, "results[1].length"); + assert.sameValue(results[0][0], 44n, "results[1][0] - accumulator"); + assert.sameValue(results[0][1], 43n, "results[1][1] - kValue"); + assert.sameValue(results[0][2], 1, "results[1][2] - k"); + assert.sameValue(results[0][3], sample, "results[1][3] - this"); + + assert.sameValue(results[1].length, 4, "results[2].length"); + assert.sameValue(results[1][0], 45n, "results[2][0] - accumulator"); + assert.sameValue(results[1][1], 42n, "results[2][1] - kValue"); + assert.sameValue(results[1][2], 0, "results[2][2] - k"); + assert.sameValue(results[1][3], sample, "results[2][3] - this"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000..c6ed68fa27 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,44 @@ +// 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.reduceright +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.reduceRight(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }, 0); + + assert.sameValue(loops, 2); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-is-not-callable-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-is-not-callable-throws.js new file mode 100644 index 0000000000..8ff2828a6c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-is-not-callable-throws.js @@ -0,0 +1,69 @@ +// 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.reduceright +description: > + Throws TypeError if callbackfn is not callable +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.reduceRight(); + }, "no arg"); + + assert.throws(TypeError, function() { + sample.reduceRight(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.reduceRight(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.reduceRight({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.reduceRight(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.reduceRight(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.reduceRight(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.reduceRight(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.reduceRight(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.reduceRight(Symbol("")); + }, "symbol"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-no-iteration-over-non-integer-properties.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-no-iteration-over-non-integer-properties.js new file mode 100644 index 0000000000..4f3c3ac19e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-no-iteration-over-non-integer-properties.js @@ -0,0 +1,51 @@ +// 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.reduceright +description: > + Does not iterate over non-integer properties +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.reduceRight(function() { + results.push(arguments); + }, 0); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][2], 1, "results[0][2] - k"); + assert.sameValue(results[1][2], 0, "results[1][2] - k"); + + assert.sameValue(results[0][1], 8n, "results[0][1] - kValue"); + assert.sameValue(results[1][1], 7n, "results[1][1] - kValue"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-not-called-on-empty.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000..54962728ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,42 @@ +// 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.reduceright +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().reduceRight(function() { + called++; + }, undefined); + + assert.sameValue(called, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-return-does-not-change-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000..6644e5e9eb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,23 @@ +// 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.reduceright +description: > + The callbackfn return does not change the `this` instance +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n, 1n, 0n]); + + sample.reduceRight(function() { + return 42; + }, 7); + + assert.sameValue(sample[0], 0n, "[0] == 0"); + assert.sameValue(sample[1], 1n, "[1] == 1"); + assert.sameValue(sample[2], 0n, "[2] == 0"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-returns-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000..31e90e15e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,45 @@ +// 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.reduceright +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(Test262Error, function() { + sample.reduceRight(function() { + throw new Test262Error(); + }); + }); + + assert.throws(Test262Error, function() { + sample.reduceRight(function() { + throw new Test262Error(); + }, 0); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-set-value-during-iteration.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-set-value-during-iteration.js new file mode 100644 index 0000000000..5105c5c7b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-set-value-during-iteration.js @@ -0,0 +1,51 @@ +// 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.reduceright +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.reduceRight(function(acc, val, i) { + if (i < sample.length - 1) { + assert.sameValue( + sample[i + 1], newVal - 1n, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 2, 7n), + true, + "re-set a value for sample[2]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + }, 0); + + assert.sameValue(sample[0], 2n, "changed values after iteration [0] == 2"); + assert.sameValue(sample[1], 1n, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 7n, "changed values after iteration [2] == 7"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-this.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-this.js new file mode 100644 index 0000000000..d49c171623 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-this.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.reduceright +description: > + callbackfn `this` value +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results = []; + + sample.reduceRight(function() { + results.push(this); + }, 0); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(results[0], expected, "[0]"); + assert.sameValue(results[1], expected, "[1]"); + assert.sameValue(results[2], expected, "[2]"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/detached-buffer.js new file mode 100644 index 0000000000..8f9c3043fc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/detached-buffer.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.reduceright +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reduceRight(callbackfn); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-return-initialvalue.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-return-initialvalue.js new file mode 100644 index 0000000000..509ef7c349 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-return-initialvalue.js @@ -0,0 +1,44 @@ +// 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.reduceright +description: > + Returns given initialValue on empty instances without calling callbackfn +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA().reduceRight(function() { + called = true; + }, 42); + + assert.sameValue(result, 42); + assert.sameValue(called, false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-with-no-initialvalue-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-with-no-initialvalue-throws.js new file mode 100644 index 0000000000..b20f594790 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-with-no-initialvalue-throws.js @@ -0,0 +1,36 @@ +// 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.reduceright +description: > + If len is 0 and initialValue is not present, throw a TypeError exception. +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + assert.throws(TypeError, function() { + new TA().reduceRight(function() { + called++; + }); + }); + + assert.sameValue(called, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/get-length-uses-internal-arraylength.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000..7f82e9fe2b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,48 @@ +// 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.reduceright +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +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]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.reduceRight(function() { + calls++; + }, 0); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/result-is-last-callbackfn-return.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/result-is-last-callbackfn-return.js new file mode 100644 index 0000000000..8df0ab71de --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/result-is-last-callbackfn-return.js @@ -0,0 +1,63 @@ +// 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.reduceright +description: > + Returns last accumulator value +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var calls, result; + + calls = 0; + result = new TA([1n, 2n, 3n]).reduceRight(function() { + calls++; + + if (calls == 2) { + return 42; + } + }); + assert.sameValue(result, 42, "using default accumulator"); + + calls = 0; + result = new TA([1n, 2n, 3n]).reduceRight(function() { + calls++; + + if (calls == 3) { + return 7; + } + }, 0); + assert.sameValue(result, 7, "using custom accumulator"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/result-of-any-type.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/result-of-any-type.js new file mode 100644 index 0000000000..fc8909a781 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/result-of-any-type.js @@ -0,0 +1,71 @@ +// 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.reduceright +description: > + Result can be of any type without any number conversions +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + [ + ["test262", "string"], + ["", "empty string"], + [undefined, "undefined"], + [null, "null"], + [-0, "-0"], + [42, "integer"], + [NaN, "NaN"], + [Infinity, "Infinity"], + [0.6, "float number"], + [true, "true"], + [false, "false"], + [Symbol(""), "symbol"], + [{}, "object"] + ].forEach(function(item) { + var result; + + result = sample.reduceRight(function() { + return item[0]; + }); + assert.sameValue(result, item[0], item[1] + " - using default accumulator"); + + result = sample.reduceRight(function() { + return item[0]; + }, 0); + + assert.sameValue(result, item[0], item[1] + " - using custom accumulator"); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..2f14282ea0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/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.reduceright +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.reduceRight, + 'function', + 'implements TypedArray.prototype.reduceRight' +); + +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.reduceRight(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.reduceRight(() => {}); + + 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 reduceRight operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.reduceRight(() => {}); + throw new Test262Error('reduceRight completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/return-first-value-without-callbackfn.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/return-first-value-without-callbackfn.js new file mode 100644 index 0000000000..1ee5b0002e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/return-first-value-without-callbackfn.js @@ -0,0 +1,45 @@ +// 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.reduceright +description: > + Returns [0] without calling callbackfn if length is 1 and initialValue is not + present. +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA([42n]).reduceRight(function() { + called = true; + }); + + assert.sameValue(result, 42n); + assert.sameValue(called, false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/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/reduceRight/BigInt/values-are-not-cached.js b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000..b24d37651a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/reduceRight/BigInt/values-are-not-cached.js @@ -0,0 +1,44 @@ +// 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.reduceright +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([44n, 43n, 42n]); + + sample.reduceRight(function(a, v, i) { + if (i > 0) { + sample[i-1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + }, 0); +}); + +reportCompare(0, 0); |