Skip to content

Commit 72f1abf

Browse files
mathiasbynensCommit Bot
authored andcommitted
[esnext] Rename Array#flatten to flat
The TC39 committee reached consensus to rename `flatten` to `flat` during the May 22nd meeting. The corresponding patch to the proposal is here: tc39/proposal-flatMap@093eacc Bug: v8:7220 Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng Change-Id: Ie8049ae4d4589a4ae7fe3d203053cef798c135e4 Reviewed-on: https://chromium-review.googlesource.com/1069467 Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Commit-Queue: Mathias Bynens <mathias@chromium.org> Cr-Commit-Position: refs/heads/master@{#53294}
1 parent 6b2c305 commit 72f1abf

8 files changed

Lines changed: 55 additions & 51 deletions

File tree

src/bootstrapper.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4276,13 +4276,13 @@ void Genesis::InitializeGlobal_harmony_array_prototype_values() {
42764276
NONE);
42774277
}
42784278

4279-
void Genesis::InitializeGlobal_harmony_array_flatten() {
4280-
if (!FLAG_harmony_array_flatten) return;
4279+
void Genesis::InitializeGlobal_harmony_array_flat() {
4280+
if (!FLAG_harmony_array_flat) return;
42814281
Handle<JSFunction> array_constructor(native_context()->array_function());
42824282
Handle<JSObject> array_prototype(
42834283
JSObject::cast(array_constructor->instance_prototype()));
4284-
SimpleInstallFunction(array_prototype, "flatten",
4285-
Builtins::kArrayPrototypeFlatten, 0, false, DONT_ENUM);
4284+
SimpleInstallFunction(array_prototype, "flat", Builtins::kArrayPrototypeFlat,
4285+
0, false, DONT_ENUM);
42864286
SimpleInstallFunction(array_prototype, "flatMap",
42874287
Builtins::kArrayPrototypeFlatMap, 1, false, DONT_ENUM);
42884288
}

src/builtins/builtins-array-gen.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3921,8 +3921,8 @@ TF_BUILTIN(FlatMapIntoArray, ArrayFlattenAssembler) {
39213921
mapper_function, this_arg));
39223922
}
39233923

3924-
// https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flatten
3925-
TF_BUILTIN(ArrayPrototypeFlatten, CodeStubAssembler) {
3924+
// https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flat
3925+
TF_BUILTIN(ArrayPrototypeFlat, CodeStubAssembler) {
39263926
Node* const argc =
39273927
ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount));
39283928
CodeStubArguments args(this, argc);

src/builtins/builtins-definitions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ namespace internal {
360360
TFS(FlattenIntoArray, kTarget, kSource, kSourceLength, kStart, kDepth) \
361361
TFS(FlatMapIntoArray, kTarget, kSource, kSourceLength, kStart, kDepth, \
362362
kMapperFunction, kThisArg) \
363-
/* https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flatten */ \
364-
TFJ(ArrayPrototypeFlatten, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
363+
/* https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flat */ \
364+
TFJ(ArrayPrototypeFlat, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
365365
/* https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flatMap */ \
366366
TFJ(ArrayPrototypeFlatMap, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
367367
\

src/flag-definitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ DEFINE_IMPLICATION(harmony_class_fields, harmony_private_fields)
212212
V(harmony_do_expressions, "harmony do-expressions") \
213213
V(harmony_class_fields, "harmony fields in class literals") \
214214
V(harmony_static_fields, "harmony static fields in class literals") \
215-
V(harmony_array_flatten, "harmony Array.prototype.flat{ten,Map}")
215+
V(harmony_array_flat, "harmony Array.prototype.{flat,flatMap}")
216216

217217
#ifdef V8_INTL_SUPPORT
218218
#define HARMONY_INPROGRESS(V) \

test/mjsunit/harmony/array-flat.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2018 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --harmony-array-flat
6+
7+
assertEquals(Array.prototype.flat.length, 0);
8+
assertEquals(Array.prototype.flat.name, 'flat');
9+
10+
const input = [1, [2], [[3]]];
11+
12+
assertEquals(input.flat(), [1, 2, [3]]);
13+
assertEquals(input.flat(1), [1, 2, [3]]);
14+
assertEquals(input.flat(true), [1, 2, [3]]);
15+
assertEquals(input.flat(undefined), [1, 2, [3]]);
16+
17+
assertEquals(input.flat(-Infinity), [1, [2], [[3]]]);
18+
assertEquals(input.flat(-1), [1, [2], [[3]]]);
19+
assertEquals(input.flat(-0), [1, [2], [[3]]]);
20+
assertEquals(input.flat(0), [1, [2], [[3]]]);
21+
assertEquals(input.flat(false), [1, [2], [[3]]]);
22+
assertEquals(input.flat(null), [1, [2], [[3]]]);
23+
assertEquals(input.flat(''), [1, [2], [[3]]]);
24+
assertEquals(input.flat('foo'), [1, [2], [[3]]]);
25+
assertEquals(input.flat(/./), [1, [2], [[3]]]);
26+
assertEquals(input.flat([]), [1, [2], [[3]]]);
27+
assertEquals(input.flat({}), [1, [2], [[3]]]);
28+
assertEquals(
29+
input.flat(new Proxy({}, {})), [1, [2], [[3]]]);
30+
assertEquals(input.flat((x) => x), [1, [2], [[3]]]);
31+
assertEquals(
32+
input.flat(String), [1, [2], [[3]]]);
33+
34+
assertEquals(input.flat(2), [1, 2, 3]);
35+
assertEquals(input.flat(Infinity), [1, 2, 3]);
36+
37+
assertThrows(() => { input.flat(Symbol()); }, TypeError);
38+
assertThrows(() => { input.flat(Object.create(null)); }, TypeError);

test/mjsunit/harmony/array-flatMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// Flags: --harmony-array-flatten --allow-natives-syntax
5+
// Flags: --harmony-array-flat --allow-natives-syntax
66

77
assertEquals(Array.prototype.flatMap.length, 1);
88
assertEquals(Array.prototype.flatMap.name, 'flatMap');

test/mjsunit/harmony/array-flatten.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

test/test262/testcfg.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,18 @@
4949
'class-fields-public': '--harmony-public-fields',
5050
'optional-catch-binding': '--harmony-optional-catch-binding',
5151
'class-fields-private': '--harmony-private-fields',
52-
'Array.prototype.flatten': '--harmony-array-flatten',
53-
'Array.prototype.flatMap': '--harmony-array-flatten',
52+
'Array.prototype.flat': '--harmony-array-flat',
53+
'Array.prototype.flatMap': '--harmony-array-flat',
5454
'String.prototype.matchAll': '--harmony-string-matchall',
5555
'Symbol.matchAll': '--harmony-string-matchall',
5656
'numeric-separator-literal': '--harmony-numeric-separator',
5757
}
5858

59-
SKIPPED_FEATURES = set([])
59+
SKIPPED_FEATURES = set([
60+
# `flatten` has been renamed to `flat`. TODO(mths): Remove this once
61+
# https://github.com/tc39/test262/pull/1569 is rolled in.
62+
'Array.prototype.flatten',
63+
])
6064

6165
DATA = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
6266

0 commit comments

Comments
 (0)