From a8f7012587250b32ffb43a3cbd8da8a9f9d1565e Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Tue, 22 May 2018 15:47:50 -0400 Subject: [PATCH] Array.prototype.flatten => Array.prototype.flat (#1569) --- features.txt | 4 ++-- .../{flatten => flat}/array-like-objects.js | 10 +++++----- .../{flatten => flat}/bound-function-call.js | 8 ++++---- .../{flatten => flat}/empty-array-elements.js | 12 +++++------ .../empty-object-elements.js | 12 +++++------ test/built-ins/Array/prototype/flat/length.js | 19 ++++++++++++++++++ test/built-ins/Array/prototype/flat/name.js | 20 +++++++++++++++++++ .../non-numeric-depth-should-not-throw.js | 16 +++++++-------- .../non-object-ctor-throws.js | 12 +++++------ .../prototype/flat/null-undefined-elements.js | 20 +++++++++++++++++++ .../null-undefined-input-throws.js | 10 +++++----- .../{flatten => flat}/positive-infinity.js | 6 +++--- .../prototype/{flatten => flat}/prop-desc.js | 14 ++++++------- .../symbol-object-create-null-depth-throws.js | 8 ++++---- .../Array/prototype/flatten/length.js | 19 ------------------ .../built-ins/Array/prototype/flatten/name.js | 20 ------------------- .../flatten/null-undefined-elements.js | 20 ------------------- 17 files changed, 115 insertions(+), 115 deletions(-) rename test/built-ins/Array/prototype/{flatten => flat}/array-like-objects.js (78%) rename test/built-ins/Array/prototype/{flatten => flat}/bound-function-call.js (61%) rename test/built-ins/Array/prototype/{flatten => flat}/empty-array-elements.js (68%) rename test/built-ins/Array/prototype/{flatten => flat}/empty-object-elements.js (61%) create mode 100644 test/built-ins/Array/prototype/flat/length.js create mode 100644 test/built-ins/Array/prototype/flat/name.js rename test/built-ins/Array/prototype/{flatten => flat}/non-numeric-depth-should-not-throw.js (80%) rename test/built-ins/Array/prototype/{flatten => flat}/non-object-ctor-throws.js (84%) create mode 100644 test/built-ins/Array/prototype/flat/null-undefined-elements.js rename test/built-ins/Array/prototype/{flatten => flat}/null-undefined-input-throws.js (73%) rename test/built-ins/Array/prototype/{flatten => flat}/positive-infinity.js (64%) rename test/built-ins/Array/prototype/{flatten => flat}/prop-desc.js (52%) rename test/built-ins/Array/prototype/{flatten => flat}/symbol-object-create-null-depth-throws.js (73%) delete mode 100644 test/built-ins/Array/prototype/flatten/length.js delete mode 100644 test/built-ins/Array/prototype/flatten/name.js delete mode 100644 test/built-ins/Array/prototype/flatten/null-undefined-elements.js diff --git a/features.txt b/features.txt index c1a145619e..257f379ee6 100644 --- a/features.txt +++ b/features.txt @@ -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 diff --git a/test/built-ins/Array/prototype/flatten/array-like-objects.js b/test/built-ins/Array/prototype/flat/array-like-objects.js similarity index 78% rename from test/built-ins/Array/prototype/flatten/array-like-objects.js rename to test/built-ins/Array/prototype/flat/array-like-objects.js index f9ed97b058..4cd131b85b 100644 --- a/test/built-ins/Array/prototype/flatten/array-like-objects.js +++ b/test/built-ins/Array/prototype/flat/array-like-objects.js @@ -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'); diff --git a/test/built-ins/Array/prototype/flatten/bound-function-call.js b/test/built-ins/Array/prototype/flat/bound-function-call.js similarity index 61% rename from test/built-ins/Array/prototype/flatten/bound-function-call.js rename to test/built-ins/Array/prototype/flat/bound-function-call.js index fd35f0975f..efff7d963c 100644 --- a/test/built-ins/Array/prototype/flatten/bound-function-call.js +++ b/test/built-ins/Array/prototype/flat/bound-function-call.js @@ -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'); diff --git a/test/built-ins/Array/prototype/flatten/empty-array-elements.js b/test/built-ins/Array/prototype/flat/empty-array-elements.js similarity index 68% rename from test/built-ins/Array/prototype/flatten/empty-array-elements.js rename to test/built-ins/Array/prototype/flat/empty-array-elements.js index 379b1e48cd..c78eb3c660 100644 --- a/test/built-ins/Array/prototype/flatten/empty-array-elements.js +++ b/test/built-ins/Array/prototype/flat/empty-array-elements.js @@ -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]); diff --git a/test/built-ins/Array/prototype/flatten/empty-object-elements.js b/test/built-ins/Array/prototype/flat/empty-object-elements.js similarity index 61% rename from test/built-ins/Array/prototype/flatten/empty-object-elements.js rename to test/built-ins/Array/prototype/flat/empty-object-elements.js index e1fcb18d31..dc3e92eb4f 100644 --- a/test/built-ins/Array/prototype/flatten/empty-object-elements.js +++ b/test/built-ins/Array/prototype/flat/empty-object-elements.js @@ -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]); diff --git a/test/built-ins/Array/prototype/flat/length.js b/test/built-ins/Array/prototype/flat/length.js new file mode 100644 index 0000000000..4c0896f349 --- /dev/null +++ b/test/built-ins/Array/prototype/flat/length.js @@ -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'); diff --git a/test/built-ins/Array/prototype/flat/name.js b/test/built-ins/Array/prototype/flat/name.js new file mode 100644 index 0000000000..312827bc1a --- /dev/null +++ b/test/built-ins/Array/prototype/flat/name.js @@ -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'); diff --git a/test/built-ins/Array/prototype/flatten/non-numeric-depth-should-not-throw.js b/test/built-ins/Array/prototype/flat/non-numeric-depth-should-not-throw.js similarity index 80% rename from test/built-ins/Array/prototype/flatten/non-numeric-depth-should-not-throw.js rename to test/built-ins/Array/prototype/flat/non-numeric-depth-should-not-throw.js index 5f6f59d2f0..68f229a243 100644 --- a/test/built-ins/Array/prototype/flatten/non-numeric-depth-should-not-throw.js +++ b/test/built-ins/Array/prototype/flat/non-numeric-depth-should-not-throw.js @@ -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'); diff --git a/test/built-ins/Array/prototype/flatten/non-object-ctor-throws.js b/test/built-ins/Array/prototype/flat/non-object-ctor-throws.js similarity index 84% rename from test/built-ins/Array/prototype/flatten/non-object-ctor-throws.js rename to test/built-ins/Array/prototype/flat/non-object-ctor-throws.js index fc8e876859..eb4f5ca092 100644 --- a/test/built-ins/Array/prototype/flatten/non-object-ctor-throws.js +++ b/test/built-ins/Array/prototype/flat/non-object-ctor-throws.js @@ -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'); diff --git a/test/built-ins/Array/prototype/flat/null-undefined-elements.js b/test/built-ins/Array/prototype/flat/null-undefined-elements.js new file mode 100644 index 0000000000..a252f10bc8 --- /dev/null +++ b/test/built-ins/Array/prototype/flat/null-undefined-elements.js @@ -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])); diff --git a/test/built-ins/Array/prototype/flatten/null-undefined-input-throws.js b/test/built-ins/Array/prototype/flat/null-undefined-input-throws.js similarity index 73% rename from test/built-ins/Array/prototype/flatten/null-undefined-input-throws.js rename to test/built-ins/Array/prototype/flat/null-undefined-input-throws.js index d3a5a59adc..ee590d27a1 100644 --- a/test/built-ins/Array/prototype/flatten/null-undefined-input-throws.js +++ b/test/built-ins/Array/prototype/flat/null-undefined-input-throws.js @@ -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'); diff --git a/test/built-ins/Array/prototype/flatten/positive-infinity.js b/test/built-ins/Array/prototype/flat/positive-infinity.js similarity index 64% rename from test/built-ins/Array/prototype/flatten/positive-infinity.js rename to test/built-ins/Array/prototype/flat/positive-infinity.js index 0c4dfcd593..381200976a 100644 --- a/test/built-ins/Array/prototype/flatten/positive-infinity.js +++ b/test/built-ins/Array/prototype/flat/positive-infinity.js @@ -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'); diff --git a/test/built-ins/Array/prototype/flatten/prop-desc.js b/test/built-ins/Array/prototype/flat/prop-desc.js similarity index 52% rename from test/built-ins/Array/prototype/flatten/prop-desc.js rename to test/built-ins/Array/prototype/flat/prop-desc.js index f7f386148b..c538b2b7b7 100644 --- a/test/built-ins/Array/prototype/flatten/prop-desc.js +++ b/test/built-ins/Array/prototype/flat/prop-desc.js @@ -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'); diff --git a/test/built-ins/Array/prototype/flatten/symbol-object-create-null-depth-throws.js b/test/built-ins/Array/prototype/flat/symbol-object-create-null-depth-throws.js similarity index 73% rename from test/built-ins/Array/prototype/flatten/symbol-object-create-null-depth-throws.js rename to test/built-ins/Array/prototype/flat/symbol-object-create-null-depth-throws.js index af58ce6b7d..a631efb34d 100644 --- a/test/built-ins/Array/prototype/flatten/symbol-object-create-null-depth-throws.js +++ b/test/built-ins/Array/prototype/flat/symbol-object-create-null-depth-throws.js @@ -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'); diff --git a/test/built-ins/Array/prototype/flatten/length.js b/test/built-ins/Array/prototype/flatten/length.js deleted file mode 100644 index 0e13e5ec52..0000000000 --- a/test/built-ins/Array/prototype/flatten/length.js +++ /dev/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'); diff --git a/test/built-ins/Array/prototype/flatten/name.js b/test/built-ins/Array/prototype/flatten/name.js deleted file mode 100644 index 6d89ae6b7d..0000000000 --- a/test/built-ins/Array/prototype/flatten/name.js +++ /dev/null @@ -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'); diff --git a/test/built-ins/Array/prototype/flatten/null-undefined-elements.js b/test/built-ins/Array/prototype/flatten/null-undefined-elements.js deleted file mode 100644 index 8211fdcc28..0000000000 --- a/test/built-ins/Array/prototype/flatten/null-undefined-elements.js +++ /dev/null @@ -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]));