mirror of https://github.com/tc39/test262.git
Array.prototype.flatten => Array.prototype.flat (#1569)
This commit is contained in:
parent
8579ac0356
commit
a8f7012587
|
@ -55,9 +55,9 @@ regexp-unicode-property-escapes
|
|||
Atomics
|
||||
SharedArrayBuffer
|
||||
|
||||
# Array.prototype.flatten and Array.prototype.flatMap
|
||||
# Array.prototype.flat and Array.prototype.flatMap
|
||||
# https://github.com/tc39/proposal-flatMap
|
||||
Array.prototype.flatten
|
||||
Array.prototype.flat
|
||||
Array.prototype.flatMap
|
||||
|
||||
# String Trimming
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
array-like objects can be flattened
|
||||
includes: [compareArray.js]
|
||||
features: [Array.prototype.flatten]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
function getArgumentsObject() {
|
||||
|
@ -13,19 +13,19 @@ function getArgumentsObject() {
|
|||
}
|
||||
|
||||
var a = getArgumentsObject([1], [2]);
|
||||
var actual = [].flatten.call(a);
|
||||
var actual = [].flat.call(a);
|
||||
assert.compareArray(actual, [1, 2], 'arguments objects');
|
||||
|
||||
var a = {
|
||||
length: 1,
|
||||
0: [1],
|
||||
};
|
||||
var actual = [].flatten.call(a);
|
||||
var actual = [].flat.call(a);
|
||||
assert.compareArray(actual, [1], 'array-like objects');
|
||||
|
||||
var a = {
|
||||
length: undefined,
|
||||
0: [1],
|
||||
};
|
||||
var actual = [].flatten.call(a);
|
||||
var actual = [].flat.call(a);
|
||||
assert.compareArray(actual, [], 'array-like objects; undefined length');
|
|
@ -1,17 +1,17 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
using bound functions
|
||||
includes: [compareArray.js]
|
||||
features: [Array.prototype.flatten]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
var a = [
|
||||
[0],
|
||||
[1]
|
||||
];
|
||||
var actual = [].flatten.bind(a)();
|
||||
var actual = [].flat.bind(a)();
|
||||
|
||||
assert.compareArray(actual, [0, 1], 'bound flatten');
|
||||
assert.compareArray(actual, [0, 1], 'bound flat');
|
|
@ -1,24 +1,24 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
arrays with empty arrays elements
|
||||
includes: [compareArray.js]
|
||||
features: [Array.prototype.flatten]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
var a = {};
|
||||
assert.compareArray([].flatten(), []);
|
||||
assert.compareArray([].flat(), []);
|
||||
assert.compareArray([
|
||||
[],
|
||||
[]
|
||||
].flatten(), []);
|
||||
].flat(), []);
|
||||
assert.compareArray([
|
||||
[],
|
||||
[1]
|
||||
].flatten(), [1]);
|
||||
].flat(), [1]);
|
||||
assert.compareArray([
|
||||
[],
|
||||
[1, a]
|
||||
].flatten(), [1, a]);
|
||||
].flat(), [1, a]);
|
|
@ -1,22 +1,22 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
arrays with empty object elements
|
||||
includes: [compareArray.js]
|
||||
features: [Array.prototype.flatten]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
var a = {},
|
||||
b = {};
|
||||
|
||||
assert.compareArray([a].flatten(), [a]);
|
||||
assert.compareArray([a, [b]].flatten(), [a, b]);
|
||||
assert.compareArray([a].flat(), [a]);
|
||||
assert.compareArray([a, [b]].flat(), [a, b]);
|
||||
assert.compareArray([
|
||||
[a], b
|
||||
].flatten(), [a, b]);
|
||||
].flat(), [a, b]);
|
||||
assert.compareArray([
|
||||
[a],
|
||||
[b]
|
||||
].flatten(), [a, b]);
|
||||
].flat(), [a, b]);
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flat
|
||||
description: Array.prototype.flat.length value and descriptor.
|
||||
info: >
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Array.prototype.flat.length, 0,
|
||||
'The value of `Array.prototype.flat.length` is `0`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Array.prototype.flat, 'length');
|
||||
verifyNotWritable(Array.prototype.flat, 'length');
|
||||
verifyConfigurable(Array.prototype.flat, 'length');
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
Array.prototype.flat.name value and descriptor.
|
||||
info: >
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Array.prototype.flat.name, 'flat',
|
||||
'The value of `Array.prototype.flat.name` is `"flat"`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Array.prototype.flat, 'name');
|
||||
verifyNotWritable(Array.prototype.flat, 'name');
|
||||
verifyConfigurable(Array.prototype.flat, 'name');
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
if the argument is a string or object, the depthNum is 0
|
||||
includes: [compareArray.js]
|
||||
features: [Array.prototype.flatten]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
var a = [1, [2]];
|
||||
|
@ -13,31 +13,31 @@ var expected = a;
|
|||
|
||||
// non integral string depthNum is converted to 0
|
||||
var depthNum = 'TestString';
|
||||
var actual = a.flatten(depthNum);
|
||||
var actual = a.flat(depthNum);
|
||||
assert(compareArray(actual, expected), 'non integral string depthNum');
|
||||
|
||||
// object type depthNum is converted to 0
|
||||
var depthNum = {};
|
||||
var actual = a.flatten(depthNum);
|
||||
var actual = a.flat(depthNum);
|
||||
assert(compareArray(actual, expected), 'object type depthNum');
|
||||
|
||||
// negative infinity depthNum is converted to 0
|
||||
var depthNum = Number.NEGATIVE_INFINITY;
|
||||
var actual = a.flatten(depthNum);
|
||||
var actual = a.flat(depthNum);
|
||||
assert(compareArray(actual, expected), 'negative infinity depthNum');
|
||||
|
||||
// positive zero depthNum is converted to 0
|
||||
var depthNum = +0;
|
||||
var actual = a.flatten(depthNum);
|
||||
var actual = a.flat(depthNum);
|
||||
assert(compareArray(actual, expected), 'positive zero depthNum');
|
||||
|
||||
// negative zero depthNum is converted to 0
|
||||
var depthNum = -0;
|
||||
var actual = a.flatten(depthNum);
|
||||
var actual = a.flat(depthNum);
|
||||
assert(compareArray(actual, expected), 'negative zero depthNum');
|
||||
|
||||
// integral string depthNum is converted to an integer
|
||||
var depthNum = '1';
|
||||
var actual = a.flatten(depthNum);
|
||||
var actual = a.flat(depthNum);
|
||||
var expected = [1, 2]
|
||||
assert(compareArray(actual, expected), 'integral string depthNum');
|
|
@ -1,33 +1,33 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
Behavior when `constructor` property is neither an Object nor undefined
|
||||
- if IsConstructor(C) is false, throw a TypeError exception.
|
||||
features: [Array.prototype.flatten]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
var a = [];
|
||||
a.constructor = null;
|
||||
assert.throws(TypeError, function() {
|
||||
a.flatten();
|
||||
a.flat();
|
||||
}, 'null value');
|
||||
|
||||
var a = [];
|
||||
a.constructor = 1;
|
||||
assert.throws(TypeError, function() {
|
||||
a.flatten();
|
||||
a.flat();
|
||||
}, 'number value');
|
||||
|
||||
var a = [];
|
||||
a.constructor = 'string';
|
||||
assert.throws(TypeError, function() {
|
||||
a.flatten();
|
||||
a.flat();
|
||||
}, 'string value');
|
||||
|
||||
var a = [];
|
||||
a.constructor = true;
|
||||
assert.throws(TypeError, function() {
|
||||
a.flatten();
|
||||
a.flat();
|
||||
}, 'boolean value');
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
arrays with null, and undefined
|
||||
includes: [compareArray.js]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
var a = [void 0];
|
||||
|
||||
assert(compareArray([1, null, void 0].flat(), [1, null, undefined]));
|
||||
assert(compareArray([1, [null, void 0]].flat(), [1, null, undefined]));
|
||||
assert(compareArray([
|
||||
[null, void 0],
|
||||
[null, void 0]
|
||||
].flat(), [null, undefined, null, undefined]));
|
||||
assert(compareArray([1, [null, a]].flat(1), [1, null, a]));
|
||||
assert(compareArray([1, [null, a]].flat(2), [1, null, undefined]));
|
|
@ -1,20 +1,20 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
null or undefined should throw TypeError Exception
|
||||
features: [Array.prototype.flatten]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
[].flatten.call(null);
|
||||
[].flat.call(null);
|
||||
}, 'null value');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
[].flatten.call();
|
||||
[].flat.call();
|
||||
}, 'missing');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
[].flatten.call(void 0);
|
||||
[].flat.call(void 0);
|
||||
}, 'undefined');
|
|
@ -1,12 +1,12 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
if the argument is a positive infinity, the depthNum is max depth of the array
|
||||
includes: [compareArray.js]
|
||||
features: [Array.prototype.flatten]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
var a = [1, [2, [3, [4]]]]
|
||||
assert(compareArray(a.flatten(Number.POSITIVE_INFINITY), [1, 2, 3, 4]), 'positive infinity depthNum');
|
||||
assert(compareArray(a.flat(Number.POSITIVE_INFINITY), [1, 2, 3, 4]), 'positive infinity depthNum');
|
|
@ -1,21 +1,21 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
esid: sec-array.prototype.flat
|
||||
es6id: 22.1.3
|
||||
description: Property type and descriptor.
|
||||
info: >
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
features: [Array.prototype.flatten]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof Array.prototype.flatten,
|
||||
typeof Array.prototype.flat,
|
||||
'function',
|
||||
'`typeof Array.prototype.flatten` is `function`'
|
||||
'`typeof Array.prototype.flat` is `function`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Array.prototype, 'flatten');
|
||||
verifyWritable(Array.prototype, 'flatten');
|
||||
verifyConfigurable(Array.prototype, 'flatten');
|
||||
verifyNotEnumerable(Array.prototype, 'flat');
|
||||
verifyWritable(Array.prototype, 'flat');
|
||||
verifyConfigurable(Array.prototype, 'flat');
|
|
@ -1,16 +1,16 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
esid: sec-array.prototype.flat
|
||||
description: >
|
||||
if the argument is a Symbol or Object null, it throws exception
|
||||
features: [Array.prototype.flatten]
|
||||
features: [Array.prototype.flat]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
[].flatten(Symbol());
|
||||
[].flat(Symbol());
|
||||
}, 'symbol value');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
[].flatten(Object.create(null));
|
||||
[].flat(Object.create(null));
|
||||
}, 'object create null');
|
|
@ -1,19 +0,0 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
description: Array.prototype.flatten.length value and descriptor.
|
||||
info: >
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
features: [Array.prototype.flatten]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Array.prototype.flatten.length, 0,
|
||||
'The value of `Array.prototype.flatten.length` is `0`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Array.prototype.flatten, 'length');
|
||||
verifyNotWritable(Array.prototype.flatten, 'length');
|
||||
verifyConfigurable(Array.prototype.flatten, 'length');
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
description: >
|
||||
Array.prototype.flatten.name value and descriptor.
|
||||
info: >
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
features: [Array.prototype.flatten]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Array.prototype.flatten.name, 'flatten',
|
||||
'The value of `Array.prototype.flatten.name` is `"flatten"`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Array.prototype.flatten, 'name');
|
||||
verifyNotWritable(Array.prototype.flatten, 'name');
|
||||
verifyConfigurable(Array.prototype.flatten, 'name');
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-array.prototype.flatten
|
||||
description: >
|
||||
arrays with null, and undefined
|
||||
includes: [compareArray.js]
|
||||
features: [Array.prototype.flatten]
|
||||
---*/
|
||||
|
||||
var a = [void 0];
|
||||
|
||||
assert(compareArray([1, null, void 0].flatten(), [1, null, undefined]));
|
||||
assert(compareArray([1, [null, void 0]].flatten(), [1, null, undefined]));
|
||||
assert(compareArray([
|
||||
[null, void 0],
|
||||
[null, void 0]
|
||||
].flatten(), [null, undefined, null, undefined]));
|
||||
assert(compareArray([1, [null, a]].flatten(1), [1, null, a]));
|
||||
assert(compareArray([1, [null, a]].flatten(2), [1, null, undefined]));
|
Loading…
Reference in New Issue