Array.prototype.flatten => Array.prototype.flat (#1569)

This commit is contained in:
Rick Waldron 2018-05-22 15:47:50 -04:00 committed by Leo Balter
parent 8579ac0356
commit a8f7012587
17 changed files with 115 additions and 115 deletions

View File

@ -55,9 +55,9 @@ regexp-unicode-property-escapes
Atomics Atomics
SharedArrayBuffer SharedArrayBuffer
# Array.prototype.flatten and Array.prototype.flatMap # Array.prototype.flat and Array.prototype.flatMap
# https://github.com/tc39/proposal-flatMap # https://github.com/tc39/proposal-flatMap
Array.prototype.flatten Array.prototype.flat
Array.prototype.flatMap Array.prototype.flatMap
# String Trimming # String Trimming

View File

@ -1,11 +1,11 @@
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved. // Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-array.prototype.flatten esid: sec-array.prototype.flat
description: > description: >
array-like objects can be flattened array-like objects can be flattened
includes: [compareArray.js] includes: [compareArray.js]
features: [Array.prototype.flatten] features: [Array.prototype.flat]
---*/ ---*/
function getArgumentsObject() { function getArgumentsObject() {
@ -13,19 +13,19 @@ function getArgumentsObject() {
} }
var a = getArgumentsObject([1], [2]); var a = getArgumentsObject([1], [2]);
var actual = [].flatten.call(a); var actual = [].flat.call(a);
assert.compareArray(actual, [1, 2], 'arguments objects'); assert.compareArray(actual, [1, 2], 'arguments objects');
var a = { var a = {
length: 1, length: 1,
0: [1], 0: [1],
}; };
var actual = [].flatten.call(a); var actual = [].flat.call(a);
assert.compareArray(actual, [1], 'array-like objects'); assert.compareArray(actual, [1], 'array-like objects');
var a = { var a = {
length: undefined, length: undefined,
0: [1], 0: [1],
}; };
var actual = [].flatten.call(a); var actual = [].flat.call(a);
assert.compareArray(actual, [], 'array-like objects; undefined length'); assert.compareArray(actual, [], 'array-like objects; undefined length');

View File

@ -1,17 +1,17 @@
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved. // Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-array.prototype.flatten esid: sec-array.prototype.flat
description: > description: >
using bound functions using bound functions
includes: [compareArray.js] includes: [compareArray.js]
features: [Array.prototype.flatten] features: [Array.prototype.flat]
---*/ ---*/
var a = [ var a = [
[0], [0],
[1] [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');

View File

@ -1,24 +1,24 @@
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved. // Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-array.prototype.flatten esid: sec-array.prototype.flat
description: > description: >
arrays with empty arrays elements arrays with empty arrays elements
includes: [compareArray.js] includes: [compareArray.js]
features: [Array.prototype.flatten] features: [Array.prototype.flat]
---*/ ---*/
var a = {}; var a = {};
assert.compareArray([].flatten(), []); assert.compareArray([].flat(), []);
assert.compareArray([ assert.compareArray([
[], [],
[] []
].flatten(), []); ].flat(), []);
assert.compareArray([ assert.compareArray([
[], [],
[1] [1]
].flatten(), [1]); ].flat(), [1]);
assert.compareArray([ assert.compareArray([
[], [],
[1, a] [1, a]
].flatten(), [1, a]); ].flat(), [1, a]);

View File

@ -1,22 +1,22 @@
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved. // Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-array.prototype.flatten esid: sec-array.prototype.flat
description: > description: >
arrays with empty object elements arrays with empty object elements
includes: [compareArray.js] includes: [compareArray.js]
features: [Array.prototype.flatten] features: [Array.prototype.flat]
---*/ ---*/
var a = {}, var a = {},
b = {}; b = {};
assert.compareArray([a].flatten(), [a]); assert.compareArray([a].flat(), [a]);
assert.compareArray([a, [b]].flatten(), [a, b]); assert.compareArray([a, [b]].flat(), [a, b]);
assert.compareArray([ assert.compareArray([
[a], b [a], b
].flatten(), [a, b]); ].flat(), [a, b]);
assert.compareArray([ assert.compareArray([
[a], [a],
[b] [b]
].flatten(), [a, b]); ].flat(), [a, b]);

View File

@ -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');

View File

@ -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');

View File

@ -1,11 +1,11 @@
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved. // Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-array.prototype.flatten esid: sec-array.prototype.flat
description: > description: >
if the argument is a string or object, the depthNum is 0 if the argument is a string or object, the depthNum is 0
includes: [compareArray.js] includes: [compareArray.js]
features: [Array.prototype.flatten] features: [Array.prototype.flat]
---*/ ---*/
var a = [1, [2]]; var a = [1, [2]];
@ -13,31 +13,31 @@ var expected = a;
// non integral string depthNum is converted to 0 // non integral string depthNum is converted to 0
var depthNum = 'TestString'; var depthNum = 'TestString';
var actual = a.flatten(depthNum); var actual = a.flat(depthNum);
assert(compareArray(actual, expected), 'non integral string depthNum'); assert(compareArray(actual, expected), 'non integral string depthNum');
// object type depthNum is converted to 0 // object type depthNum is converted to 0
var depthNum = {}; var depthNum = {};
var actual = a.flatten(depthNum); var actual = a.flat(depthNum);
assert(compareArray(actual, expected), 'object type depthNum'); assert(compareArray(actual, expected), 'object type depthNum');
// negative infinity depthNum is converted to 0 // negative infinity depthNum is converted to 0
var depthNum = Number.NEGATIVE_INFINITY; var depthNum = Number.NEGATIVE_INFINITY;
var actual = a.flatten(depthNum); var actual = a.flat(depthNum);
assert(compareArray(actual, expected), 'negative infinity depthNum'); assert(compareArray(actual, expected), 'negative infinity depthNum');
// positive zero depthNum is converted to 0 // positive zero depthNum is converted to 0
var depthNum = +0; var depthNum = +0;
var actual = a.flatten(depthNum); var actual = a.flat(depthNum);
assert(compareArray(actual, expected), 'positive zero depthNum'); assert(compareArray(actual, expected), 'positive zero depthNum');
// negative zero depthNum is converted to 0 // negative zero depthNum is converted to 0
var depthNum = -0; var depthNum = -0;
var actual = a.flatten(depthNum); var actual = a.flat(depthNum);
assert(compareArray(actual, expected), 'negative zero depthNum'); assert(compareArray(actual, expected), 'negative zero depthNum');
// integral string depthNum is converted to an integer // integral string depthNum is converted to an integer
var depthNum = '1'; var depthNum = '1';
var actual = a.flatten(depthNum); var actual = a.flat(depthNum);
var expected = [1, 2] var expected = [1, 2]
assert(compareArray(actual, expected), 'integral string depthNum'); assert(compareArray(actual, expected), 'integral string depthNum');

View File

@ -1,33 +1,33 @@
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved. // Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-array.prototype.flatten esid: sec-array.prototype.flat
description: > description: >
Behavior when `constructor` property is neither an Object nor undefined Behavior when `constructor` property is neither an Object nor undefined
- if IsConstructor(C) is false, throw a TypeError exception. - if IsConstructor(C) is false, throw a TypeError exception.
features: [Array.prototype.flatten] features: [Array.prototype.flat]
---*/ ---*/
var a = []; var a = [];
a.constructor = null; a.constructor = null;
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
a.flatten(); a.flat();
}, 'null value'); }, 'null value');
var a = []; var a = [];
a.constructor = 1; a.constructor = 1;
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
a.flatten(); a.flat();
}, 'number value'); }, 'number value');
var a = []; var a = [];
a.constructor = 'string'; a.constructor = 'string';
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
a.flatten(); a.flat();
}, 'string value'); }, 'string value');
var a = []; var a = [];
a.constructor = true; a.constructor = true;
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
a.flatten(); a.flat();
}, 'boolean value'); }, 'boolean value');

View File

@ -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]));

View File

@ -1,20 +1,20 @@
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved. // Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-array.prototype.flatten esid: sec-array.prototype.flat
description: > description: >
null or undefined should throw TypeError Exception null or undefined should throw TypeError Exception
features: [Array.prototype.flatten] features: [Array.prototype.flat]
---*/ ---*/
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
[].flatten.call(null); [].flat.call(null);
}, 'null value'); }, 'null value');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
[].flatten.call(); [].flat.call();
}, 'missing'); }, 'missing');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
[].flatten.call(void 0); [].flat.call(void 0);
}, 'undefined'); }, 'undefined');

View File

@ -1,12 +1,12 @@
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved. // Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-array.prototype.flatten esid: sec-array.prototype.flat
description: > description: >
if the argument is a positive infinity, the depthNum is max depth of the array if the argument is a positive infinity, the depthNum is max depth of the array
includes: [compareArray.js] includes: [compareArray.js]
features: [Array.prototype.flatten] features: [Array.prototype.flat]
---*/ ---*/
var a = [1, [2, [3, [4]]]] 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');

View File

@ -1,21 +1,21 @@
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved. // Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // 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 es6id: 22.1.3
description: Property type and descriptor. description: Property type and descriptor.
info: > info: >
17 ECMAScript Standard Built-in Objects 17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js] includes: [propertyHelper.js]
features: [Array.prototype.flatten] features: [Array.prototype.flat]
---*/ ---*/
assert.sameValue( assert.sameValue(
typeof Array.prototype.flatten, typeof Array.prototype.flat,
'function', 'function',
'`typeof Array.prototype.flatten` is `function`' '`typeof Array.prototype.flat` is `function`'
); );
verifyNotEnumerable(Array.prototype, 'flatten'); verifyNotEnumerable(Array.prototype, 'flat');
verifyWritable(Array.prototype, 'flatten'); verifyWritable(Array.prototype, 'flat');
verifyConfigurable(Array.prototype, 'flatten'); verifyConfigurable(Array.prototype, 'flat');

View File

@ -1,16 +1,16 @@
// Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved. // Copyright (C) 2018 Shilpi Jain and Michael Ficarra. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
esid: sec-array.prototype.flatten esid: sec-array.prototype.flat
description: > description: >
if the argument is a Symbol or Object null, it throws exception if the argument is a Symbol or Object null, it throws exception
features: [Array.prototype.flatten] features: [Array.prototype.flat]
---*/ ---*/
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
[].flatten(Symbol()); [].flat(Symbol());
}, 'symbol value'); }, 'symbol value');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
[].flatten(Object.create(null)); [].flat(Object.create(null));
}, 'object create null'); }, 'object create null');

View File

@ -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');

View File

@ -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');

View File

@ -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]));