mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 22:15:24 +02:00
Add tests for TypedArrays reduce and reduceRight
This commit is contained in:
parent
800300e120
commit
dfbf33b3ac
57
test/built-ins/TypedArray/prototype/reduce/callbackfn-arguments-custom-accumulator.js
vendored
Normal file
57
test/built-ins/TypedArray/prototype/reduce/callbackfn-arguments-custom-accumulator.js
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
// 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.reduce
|
||||
description: >
|
||||
callbackfn arguments using custom accumulator
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( 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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
|
||||
var results = [];
|
||||
|
||||
sample.reduce(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], 42, "results[0][1] - kValue");
|
||||
assert.sameValue(results[0][2], 0, "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], 43, "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], 44, "results[2][1] - kValue");
|
||||
assert.sameValue(results[2][2], 2, "results[2][2] - k");
|
||||
assert.sameValue(results[2][3], sample, "results[2][3] - this");
|
||||
});
|
58
test/built-ins/TypedArray/prototype/reduce/callbackfn-arguments-default-accumulator.js
vendored
Normal file
58
test/built-ins/TypedArray/prototype/reduce/callbackfn-arguments-default-accumulator.js
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
// 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.reduce
|
||||
description: >
|
||||
callbackfn arguments using default accumulator (value at index 0)
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
...
|
||||
7. Else initialValue is not present,
|
||||
a. Let kPresent be false.
|
||||
b. Repeat, while kPresent is false and k < len
|
||||
...
|
||||
iii. If kPresent is true, then
|
||||
1. Let accumulator be ? Get(O, Pk).
|
||||
...
|
||||
8. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
...
|
||||
i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue,
|
||||
k, O »).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
|
||||
var results = [];
|
||||
|
||||
sample.reduce(function(accumulator) {
|
||||
results.push(arguments);
|
||||
return accumulator - 1;
|
||||
});
|
||||
|
||||
assert.sameValue(results.length, 2, "results.length");
|
||||
|
||||
assert.sameValue(results[0].length, 4, "results[1].length");
|
||||
assert.sameValue(results[0][0], 42, "results[1][0] - accumulator");
|
||||
assert.sameValue(results[0][1], 43, "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], 41, "results[2][0] - accumulator");
|
||||
assert.sameValue(results[1][1], 44, "results[2][1] - kValue");
|
||||
assert.sameValue(results[1][2], 2, "results[2][2] - k");
|
||||
assert.sameValue(results[1][3], sample, "results[2][3] - this");
|
||||
});
|
43
test/built-ins/TypedArray/prototype/reduce/callbackfn-detachbuffer.js
vendored
Normal file
43
test/built-ins/TypedArray/prototype/reduce/callbackfn-detachbuffer.js
vendored
Normal file
@ -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-%typedarray%.prototype.reduce
|
||||
description: >
|
||||
Instance buffer can be detached during loop
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( 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, testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var loops = 0;
|
||||
var sample = new TA(2);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce(function() {
|
||||
if (loops === 1) {
|
||||
throw new Test262Error("callbackfn called twice");
|
||||
}
|
||||
$DETACHBUFFER(sample.buffer);
|
||||
loops++;
|
||||
}, 0);
|
||||
});
|
||||
|
||||
assert.sameValue(loops, 1, "callbackfn called only once");
|
||||
});
|
67
test/built-ins/TypedArray/prototype/reduce/callbackfn-is-not-callable-throws.js
vendored
Normal file
67
test/built-ins/TypedArray/prototype/reduce/callbackfn-is-not-callable-throws.js
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
// 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.reduce
|
||||
description: >
|
||||
Throws TypeError if callbackfn is not callable
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( 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: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(1);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce();
|
||||
}, "no arg");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce(undefined);
|
||||
}, "undefined");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce(null);
|
||||
}, "null");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce({});
|
||||
}, "{}");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce(1);
|
||||
}, "1");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce(NaN);
|
||||
}, "NaN");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce("");
|
||||
}, "string");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce(false);
|
||||
}, "false");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce(true);
|
||||
}, "true");
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduce(Symbol(""));
|
||||
}, "symbol");
|
||||
});
|
@ -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.reduce
|
||||
description: >
|
||||
Does not iterate over non-integer properties
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( 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: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([7, 8]);
|
||||
|
||||
var results = [];
|
||||
|
||||
sample.foo = 42;
|
||||
sample[Symbol("1")] = 43;
|
||||
|
||||
sample.reduce(function() {
|
||||
results.push(arguments);
|
||||
}, 0);
|
||||
|
||||
assert.sameValue(results.length, 2, "results.length");
|
||||
|
||||
assert.sameValue(results[0][2], 0, "results[0][2] - k");
|
||||
assert.sameValue(results[1][2], 1, "results[1][2] - k");
|
||||
|
||||
assert.sameValue(results[0][1], 7, "results[0][1] - kValue");
|
||||
assert.sameValue(results[1][1], 8, "results[1][1] - kValue");
|
||||
});
|
38
test/built-ins/TypedArray/prototype/reduce/callbackfn-not-called-on-empty.js
vendored
Normal file
38
test/built-ins/TypedArray/prototype/reduce/callbackfn-not-called-on-empty.js
vendored
Normal file
@ -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.reduce
|
||||
description: >
|
||||
callbackfn is not called on empty instances
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
...
|
||||
4. If len is 0 and initialValue is not present, throw a TypeError exception.
|
||||
...
|
||||
8. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
...
|
||||
i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue,
|
||||
k, O »).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = 0;
|
||||
|
||||
new TA().reduce(function() {
|
||||
called++;
|
||||
}, undefined);
|
||||
|
||||
assert.sameValue(called, 0);
|
||||
});
|
20
test/built-ins/TypedArray/prototype/reduce/callbackfn-return-does-not-change-instance.js
vendored
Normal file
20
test/built-ins/TypedArray/prototype/reduce/callbackfn-return-does-not-change-instance.js
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// 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.reduce
|
||||
description: >
|
||||
The callbackfn return does not change the `this` instance
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([0, 1, 0]);
|
||||
|
||||
sample.reduce(function() {
|
||||
return 42;
|
||||
}, 7);
|
||||
|
||||
assert.sameValue(sample[0], 0, "[0] == 0");
|
||||
assert.sameValue(sample[1], 1, "[1] == 1");
|
||||
assert.sameValue(sample[2], 0, "[2] == 0");
|
||||
});
|
42
test/built-ins/TypedArray/prototype/reduce/callbackfn-returns-abrupt.js
vendored
Normal file
42
test/built-ins/TypedArray/prototype/reduce/callbackfn-returns-abrupt.js
vendored
Normal file
@ -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.reduce
|
||||
description: >
|
||||
Returns abrupt from callbackfn
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( 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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(2);
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.reduce(function() {
|
||||
throw new Test262Error();
|
||||
});
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.reduce(function() {
|
||||
throw new Test262Error();
|
||||
}, 0);
|
||||
});
|
||||
});
|
49
test/built-ins/TypedArray/prototype/reduce/callbackfn-set-value-during-iteration.js
vendored
Normal file
49
test/built-ins/TypedArray/prototype/reduce/callbackfn-set-value-during-iteration.js
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
// 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.reduce
|
||||
description: >
|
||||
Integer indexed values changed during iteration
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
includes: [testTypedArray.js]
|
||||
features: [Reflect.set]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
var newVal = 0;
|
||||
|
||||
sample.reduce(function(acc, val, i) {
|
||||
if (i > 0) {
|
||||
assert.sameValue(
|
||||
sample[i - 1], newVal - 1,
|
||||
"get the changed value during the loop"
|
||||
);
|
||||
assert.sameValue(
|
||||
Reflect.set(sample, 0, 7),
|
||||
true,
|
||||
"re-set a value for sample[0]"
|
||||
);
|
||||
}
|
||||
assert.sameValue(
|
||||
Reflect.set(sample, i, newVal),
|
||||
true,
|
||||
"set value during iteration"
|
||||
);
|
||||
|
||||
newVal++;
|
||||
}, 0);
|
||||
|
||||
assert.sameValue(sample[0], 7, "changed values after iteration [0] == 7");
|
||||
assert.sameValue(sample[1], 1, "changed values after iteration [1] == 1");
|
||||
assert.sameValue(sample[2], 2, "changed values after iteration [2] == 2");
|
||||
});
|
43
test/built-ins/TypedArray/prototype/reduce/callbackfn-this.js
vendored
Normal file
43
test/built-ins/TypedArray/prototype/reduce/callbackfn-this.js
vendored
Normal file
@ -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-%typedarray%.prototype.reduce
|
||||
description: >
|
||||
callbackfn `this` value
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( 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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var expected = (function() { return this; })();
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(3);
|
||||
|
||||
var results = [];
|
||||
|
||||
sample.reduce(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]");
|
||||
});
|
40
test/built-ins/TypedArray/prototype/reduce/empty-instance-return-initialvalue.js
vendored
Normal file
40
test/built-ins/TypedArray/prototype/reduce/empty-instance-return-initialvalue.js
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
// 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.reduce
|
||||
description: >
|
||||
Returns given initialValue on empty instances without calling callbackfn
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
...
|
||||
7. Else initialValue is not present,
|
||||
...
|
||||
b. Repeat, while kPresent is false and k < len
|
||||
...
|
||||
iii. If kPresent is true, then
|
||||
1. Let accumulator be ? Get(O, Pk).
|
||||
iv. Increase k by 1.
|
||||
...
|
||||
8. Repeat, while k < len
|
||||
...
|
||||
9. Return accumulator.
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = false;
|
||||
var result = new TA().reduce(function() {
|
||||
called = true;
|
||||
}, 42);
|
||||
|
||||
assert.sameValue(result, 42);
|
||||
assert.sameValue(called, false);
|
||||
});
|
33
test/built-ins/TypedArray/prototype/reduce/empty-instance-with-no-initialvalue-throws.js
vendored
Normal file
33
test/built-ins/TypedArray/prototype/reduce/empty-instance-with-no-initialvalue-throws.js
vendored
Normal file
@ -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-%typedarray%.prototype.reduce
|
||||
description: >
|
||||
If len is 0 and initialValue is not present, throw a TypeError exception.
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
...
|
||||
4. If len is 0 and initialValue is not present, throw a TypeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = 0;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new TA().reduce(function() {
|
||||
called++;
|
||||
});
|
||||
});
|
||||
|
||||
assert.sameValue(called, 0);
|
||||
});
|
45
test/built-ins/TypedArray/prototype/reduce/get-length-uses-internal-arraylength.js
vendored
Normal file
45
test/built-ins/TypedArray/prototype/reduce/get-length-uses-internal-arraylength.js
vendored
Normal file
@ -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.reduce
|
||||
description: Get "length" uses internal ArrayLength
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
1. Let O be ? ToObject(this value).
|
||||
2. Let len be ? ToLength(? Get(O, "length")).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var getCalls = 0;
|
||||
var desc = {
|
||||
get: function getLen() {
|
||||
getCalls++;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(TypedArray.prototype, "length", desc);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43]);
|
||||
var calls = 0;
|
||||
|
||||
Object.defineProperty(TA.prototype, "length", desc);
|
||||
Object.defineProperty(sample, "length", desc);
|
||||
|
||||
sample.reduce(function() {
|
||||
calls++;
|
||||
}, 0);
|
||||
|
||||
assert.sameValue(getCalls, 0, "ignores length properties");
|
||||
assert.sameValue(calls, 2, "iterations are not affected by custom length");
|
||||
});
|
58
test/built-ins/TypedArray/prototype/reduce/result-is-last-callbackfn-return.js
vendored
Normal file
58
test/built-ins/TypedArray/prototype/reduce/result-is-last-callbackfn-return.js
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
// 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.reduce
|
||||
description: >
|
||||
Returns last accumulator value
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
...
|
||||
7. Else initialValue is not present,
|
||||
...
|
||||
b. Repeat, while kPresent is false and k < len
|
||||
...
|
||||
iii. If kPresent is true, then
|
||||
1. Let accumulator be ? Get(O, Pk).
|
||||
iv. Increase k by 1.
|
||||
...
|
||||
8. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator,
|
||||
kValue, k, O »).
|
||||
9. Return accumulator.
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var calls, result;
|
||||
|
||||
calls = 0;
|
||||
result = new TA([1, 2, 3]).reduce(function() {
|
||||
calls++;
|
||||
|
||||
if (calls == 2) {
|
||||
return 42;
|
||||
}
|
||||
});
|
||||
assert.sameValue(result, 42, "using default accumulator");
|
||||
|
||||
calls = 0;
|
||||
result = new TA([1, 2, 3]).reduce(function() {
|
||||
calls++;
|
||||
|
||||
if (calls == 3) {
|
||||
return 7;
|
||||
}
|
||||
}, 0);
|
||||
assert.sameValue(result, 7, "using custom accumulator");
|
||||
});
|
67
test/built-ins/TypedArray/prototype/reduce/result-of-any-type.js
vendored
Normal file
67
test/built-ins/TypedArray/prototype/reduce/result-of-any-type.js
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
// 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.reduce
|
||||
description: >
|
||||
Result can be of any type without any number conversions
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
...
|
||||
7. Else initialValue is not present,
|
||||
...
|
||||
b. Repeat, while kPresent is false and k < len
|
||||
...
|
||||
iii. If kPresent is true, then
|
||||
1. Let accumulator be ? Get(O, Pk).
|
||||
iv. Increase k by 1.
|
||||
...
|
||||
8. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator,
|
||||
kValue, k, O »).
|
||||
9. Return accumulator.
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
[
|
||||
["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.reduce(function() {
|
||||
return item[0];
|
||||
});
|
||||
assert.sameValue(result, item[0], item[1] + " - using default accumulator");
|
||||
|
||||
result = sample.reduce(function() {
|
||||
return item[0];
|
||||
}, 0);
|
||||
|
||||
assert.sameValue(result, item[0], item[1] + " - using custom accumulator");
|
||||
});
|
||||
});
|
41
test/built-ins/TypedArray/prototype/reduce/return-first-value-without-callbackfn.js
vendored
Normal file
41
test/built-ins/TypedArray/prototype/reduce/return-first-value-without-callbackfn.js
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
// 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.reduce
|
||||
description: >
|
||||
Returns [0] without calling callbackfn if length is 1 and initialValue is not
|
||||
present.
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
...
|
||||
7. Else initialValue is not present,
|
||||
...
|
||||
b. Repeat, while kPresent is false and k < len
|
||||
...
|
||||
iii. If kPresent is true, then
|
||||
1. Let accumulator be ? Get(O, Pk).
|
||||
iv. Increase k by 1.
|
||||
...
|
||||
8. Repeat, while k < len
|
||||
...
|
||||
9. Return accumulator.
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = false;
|
||||
var result = new TA([42]).reduce(function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
assert.sameValue(result, 42);
|
||||
assert.sameValue(called, false);
|
||||
});
|
40
test/built-ins/TypedArray/prototype/reduce/values-are-not-cached.js
vendored
Normal file
40
test/built-ins/TypedArray/prototype/reduce/values-are-not-cached.js
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
// 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.reduce
|
||||
description: >
|
||||
Integer indexed values are not cached before iteration
|
||||
info: >
|
||||
22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
%TypedArray%.prototype.reduce is a distinct function that implements the same
|
||||
algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the
|
||||
this object's [[ArrayLength]] internal slot is accessed in place of performing
|
||||
a [[Get]] of "length".
|
||||
|
||||
22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] )
|
||||
|
||||
...
|
||||
8. Repeat, while k < len
|
||||
...
|
||||
c. If kPresent is true, then
|
||||
i. Let kValue be ? Get(O, Pk).
|
||||
ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue,
|
||||
k, O »).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
|
||||
sample.reduce(function(a, v, i) {
|
||||
if (i < sample.length - 1) {
|
||||
sample[i+1] = 42;
|
||||
}
|
||||
|
||||
assert.sameValue(
|
||||
v, 42, "method does not cache values before callbackfn calls"
|
||||
);
|
||||
}, 0);
|
||||
});
|
58
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-arguments-custom-accumulator.js
vendored
Normal file
58
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-arguments-custom-accumulator.js
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
// 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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
|
||||
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], 44, "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], 43, "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], 42, "results[2][1] - kValue");
|
||||
assert.sameValue(results[2][2], 0, "results[2][2] - k");
|
||||
assert.sameValue(results[2][3], sample, "results[2][3] - this");
|
||||
});
|
61
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-arguments-default-accumulator.js
vendored
Normal file
61
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-arguments-default-accumulator.js
vendored
Normal file
@ -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 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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
|
||||
var results = [];
|
||||
|
||||
sample.reduceRight(function(accumulator) {
|
||||
results.push(arguments);
|
||||
return accumulator + 1;
|
||||
});
|
||||
|
||||
assert.sameValue(results.length, 2, "results.length");
|
||||
|
||||
assert.sameValue(results[0].length, 4, "results[1].length");
|
||||
assert.sameValue(results[0][0], 44, "results[1][0] - accumulator");
|
||||
assert.sameValue(results[0][1], 43, "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], 45, "results[2][0] - accumulator");
|
||||
assert.sameValue(results[1][1], 42, "results[2][1] - kValue");
|
||||
assert.sameValue(results[1][2], 0, "results[2][2] - k");
|
||||
assert.sameValue(results[1][3], sample, "results[2][3] - this");
|
||||
});
|
43
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-detachbuffer.js
vendored
Normal file
43
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-detachbuffer.js
vendored
Normal file
@ -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-%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, testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var loops = 0;
|
||||
var sample = new TA(2);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
sample.reduceRight(function() {
|
||||
if (loops === 1) {
|
||||
throw new Test262Error("callbackfn called twice");
|
||||
}
|
||||
$DETACHBUFFER(sample.buffer);
|
||||
loops++;
|
||||
}, 0);
|
||||
});
|
||||
|
||||
assert.sameValue(loops, 1, "callbackfn called only once");
|
||||
});
|
67
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-is-not-callable-throws.js
vendored
Normal file
67
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-is-not-callable-throws.js
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
// 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: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(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");
|
||||
});
|
@ -0,0 +1,49 @@
|
||||
// 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: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([7, 8]);
|
||||
|
||||
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], 8, "results[0][1] - kValue");
|
||||
assert.sameValue(results[1][1], 7, "results[1][1] - kValue");
|
||||
});
|
39
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-not-called-on-empty.js
vendored
Normal file
39
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-not-called-on-empty.js
vendored
Normal file
@ -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.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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = 0;
|
||||
|
||||
new TA().reduceRight(function() {
|
||||
called++;
|
||||
}, undefined);
|
||||
|
||||
assert.sameValue(called, 0);
|
||||
});
|
20
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-return-does-not-change-instance.js
vendored
Normal file
20
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-return-does-not-change-instance.js
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// 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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([0, 1, 0]);
|
||||
|
||||
sample.reduceRight(function() {
|
||||
return 42;
|
||||
}, 7);
|
||||
|
||||
assert.sameValue(sample[0], 0, "[0] == 0");
|
||||
assert.sameValue(sample[1], 1, "[1] == 1");
|
||||
assert.sameValue(sample[2], 0, "[2] == 0");
|
||||
});
|
42
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-returns-abrupt.js
vendored
Normal file
42
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-returns-abrupt.js
vendored
Normal file
@ -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: >
|
||||
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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(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);
|
||||
});
|
||||
});
|
49
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-set-value-during-iteration.js
vendored
Normal file
49
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-set-value-during-iteration.js
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
// 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: [testTypedArray.js]
|
||||
features: [Reflect.set]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
var newVal = 0;
|
||||
|
||||
sample.reduceRight(function(acc, val, i) {
|
||||
if (i < sample.length - 1) {
|
||||
assert.sameValue(
|
||||
sample[i + 1], newVal - 1,
|
||||
"get the changed value during the loop"
|
||||
);
|
||||
assert.sameValue(
|
||||
Reflect.set(sample, 2, 7),
|
||||
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], 2, "changed values after iteration [0] == 2");
|
||||
assert.sameValue(sample[1], 1, "changed values after iteration [1] == 1");
|
||||
assert.sameValue(sample[2], 7, "changed values after iteration [2] == 7");
|
||||
});
|
44
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-this.js
vendored
Normal file
44
test/built-ins/TypedArray/prototype/reduceRight/callbackfn-this.js
vendored
Normal file
@ -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: >
|
||||
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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var expected = (function() { return this; })();
|
||||
|
||||
testWithTypedArrayConstructors(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]");
|
||||
});
|
41
test/built-ins/TypedArray/prototype/reduceRight/empty-instance-return-initialvalue.js
vendored
Normal file
41
test/built-ins/TypedArray/prototype/reduceRight/empty-instance-return-initialvalue.js
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
// 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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = false;
|
||||
var result = new TA().reduceRight(function() {
|
||||
called = true;
|
||||
}, 42);
|
||||
|
||||
assert.sameValue(result, 42);
|
||||
assert.sameValue(called, false);
|
||||
});
|
33
test/built-ins/TypedArray/prototype/reduceRight/empty-instance-with-no-initialvalue-throws.js
vendored
Normal file
33
test/built-ins/TypedArray/prototype/reduceRight/empty-instance-with-no-initialvalue-throws.js
vendored
Normal file
@ -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-%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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = 0;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new TA().reduceRight(function() {
|
||||
called++;
|
||||
});
|
||||
});
|
||||
|
||||
assert.sameValue(called, 0);
|
||||
});
|
45
test/built-ins/TypedArray/prototype/reduceRight/get-length-uses-internal-arraylength.js
vendored
Normal file
45
test/built-ins/TypedArray/prototype/reduceRight/get-length-uses-internal-arraylength.js
vendored
Normal file
@ -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: 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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var getCalls = 0;
|
||||
var desc = {
|
||||
get: function getLen() {
|
||||
getCalls++;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(TypedArray.prototype, "length", desc);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43]);
|
||||
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");
|
||||
});
|
60
test/built-ins/TypedArray/prototype/reduceRight/result-is-last-callbackfn-return.js
vendored
Normal file
60
test/built-ins/TypedArray/prototype/reduceRight/result-is-last-callbackfn-return.js
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
// 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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var calls, result;
|
||||
|
||||
calls = 0;
|
||||
result = new TA([1, 2, 3]).reduceRight(function() {
|
||||
calls++;
|
||||
|
||||
if (calls == 2) {
|
||||
return 42;
|
||||
}
|
||||
});
|
||||
assert.sameValue(result, 42, "using default accumulator");
|
||||
|
||||
calls = 0;
|
||||
result = new TA([1, 2, 3]).reduceRight(function() {
|
||||
calls++;
|
||||
|
||||
if (calls == 3) {
|
||||
return 7;
|
||||
}
|
||||
}, 0);
|
||||
assert.sameValue(result, 7, "using custom accumulator");
|
||||
});
|
69
test/built-ins/TypedArray/prototype/reduceRight/result-of-any-type.js
vendored
Normal file
69
test/built-ins/TypedArray/prototype/reduceRight/result-of-any-type.js
vendored
Normal file
@ -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: >
|
||||
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: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43, 44]);
|
||||
[
|
||||
["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");
|
||||
});
|
||||
});
|
42
test/built-ins/TypedArray/prototype/reduceRight/return-first-value-without-callbackfn.js
vendored
Normal file
42
test/built-ins/TypedArray/prototype/reduceRight/return-first-value-without-callbackfn.js
vendored
Normal file
@ -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: >
|
||||
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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var called = false;
|
||||
var result = new TA([42]).reduceRight(function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
assert.sameValue(result, 42);
|
||||
assert.sameValue(called, false);
|
||||
});
|
41
test/built-ins/TypedArray/prototype/reduceRight/values-are-not-cached.js
vendored
Normal file
41
test/built-ins/TypedArray/prototype/reduceRight/values-are-not-cached.js
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
// 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: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([44, 43, 42]);
|
||||
|
||||
sample.reduceRight(function(a, v, i) {
|
||||
if (i > 0) {
|
||||
sample[i-1] = 42;
|
||||
}
|
||||
|
||||
assert.sameValue(
|
||||
v, 42, "method does not cache values before callbackfn calls"
|
||||
);
|
||||
}, 0);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user