Skip to content
Permalink
Browse files

[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}
  • Loading branch information
mathiasbynens authored and Commit Bot committed May 23, 2018
1 parent 6b2c305 commit 72f1abfbec0b8c798bc4cf150c774b5411d522ae
@@ -4276,13 +4276,13 @@ void Genesis::InitializeGlobal_harmony_array_prototype_values() {
NONE);
}

void Genesis::InitializeGlobal_harmony_array_flatten() {
if (!FLAG_harmony_array_flatten) return;
void Genesis::InitializeGlobal_harmony_array_flat() {
if (!FLAG_harmony_array_flat) return;
Handle<JSFunction> array_constructor(native_context()->array_function());
Handle<JSObject> array_prototype(
JSObject::cast(array_constructor->instance_prototype()));
SimpleInstallFunction(array_prototype, "flatten",
Builtins::kArrayPrototypeFlatten, 0, false, DONT_ENUM);
SimpleInstallFunction(array_prototype, "flat", Builtins::kArrayPrototypeFlat,
0, false, DONT_ENUM);
SimpleInstallFunction(array_prototype, "flatMap",
Builtins::kArrayPrototypeFlatMap, 1, false, DONT_ENUM);
}
@@ -3921,8 +3921,8 @@ TF_BUILTIN(FlatMapIntoArray, ArrayFlattenAssembler) {
mapper_function, this_arg));
}

// https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flatten
TF_BUILTIN(ArrayPrototypeFlatten, CodeStubAssembler) {
// https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flat
TF_BUILTIN(ArrayPrototypeFlat, CodeStubAssembler) {
Node* const argc =
ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount));
CodeStubArguments args(this, argc);
@@ -360,8 +360,8 @@ namespace internal {
TFS(FlattenIntoArray, kTarget, kSource, kSourceLength, kStart, kDepth) \
TFS(FlatMapIntoArray, kTarget, kSource, kSourceLength, kStart, kDepth, \
kMapperFunction, kThisArg) \
/* https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flatten */ \
TFJ(ArrayPrototypeFlatten, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flat */ \
TFJ(ArrayPrototypeFlat, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flatMap */ \
TFJ(ArrayPrototypeFlatMap, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
\
@@ -212,7 +212,7 @@ DEFINE_IMPLICATION(harmony_class_fields, harmony_private_fields)
V(harmony_do_expressions, "harmony do-expressions") \
V(harmony_class_fields, "harmony fields in class literals") \
V(harmony_static_fields, "harmony static fields in class literals") \
V(harmony_array_flatten, "harmony Array.prototype.flat{ten,Map}")
V(harmony_array_flat, "harmony Array.prototype.{flat,flatMap}")

#ifdef V8_INTL_SUPPORT
#define HARMONY_INPROGRESS(V) \
@@ -0,0 +1,38 @@
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --harmony-array-flat

assertEquals(Array.prototype.flat.length, 0);
assertEquals(Array.prototype.flat.name, 'flat');

const input = [1, [2], [[3]]];

assertEquals(input.flat(), [1, 2, [3]]);
assertEquals(input.flat(1), [1, 2, [3]]);
assertEquals(input.flat(true), [1, 2, [3]]);
assertEquals(input.flat(undefined), [1, 2, [3]]);

assertEquals(input.flat(-Infinity), [1, [2], [[3]]]);
assertEquals(input.flat(-1), [1, [2], [[3]]]);
assertEquals(input.flat(-0), [1, [2], [[3]]]);
assertEquals(input.flat(0), [1, [2], [[3]]]);
assertEquals(input.flat(false), [1, [2], [[3]]]);
assertEquals(input.flat(null), [1, [2], [[3]]]);
assertEquals(input.flat(''), [1, [2], [[3]]]);
assertEquals(input.flat('foo'), [1, [2], [[3]]]);
assertEquals(input.flat(/./), [1, [2], [[3]]]);
assertEquals(input.flat([]), [1, [2], [[3]]]);
assertEquals(input.flat({}), [1, [2], [[3]]]);
assertEquals(
input.flat(new Proxy({}, {})), [1, [2], [[3]]]);
assertEquals(input.flat((x) => x), [1, [2], [[3]]]);
assertEquals(
input.flat(String), [1, [2], [[3]]]);

assertEquals(input.flat(2), [1, 2, 3]);
assertEquals(input.flat(Infinity), [1, 2, 3]);

assertThrows(() => { input.flat(Symbol()); }, TypeError);
assertThrows(() => { input.flat(Object.create(null)); }, TypeError);
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --harmony-array-flatten --allow-natives-syntax
// Flags: --harmony-array-flat --allow-natives-syntax

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

This file was deleted.

@@ -49,14 +49,18 @@
'class-fields-public': '--harmony-public-fields',
'optional-catch-binding': '--harmony-optional-catch-binding',
'class-fields-private': '--harmony-private-fields',
'Array.prototype.flatten': '--harmony-array-flatten',
'Array.prototype.flatMap': '--harmony-array-flatten',
'Array.prototype.flat': '--harmony-array-flat',
'Array.prototype.flatMap': '--harmony-array-flat',
'String.prototype.matchAll': '--harmony-string-matchall',
'Symbol.matchAll': '--harmony-string-matchall',
'numeric-separator-literal': '--harmony-numeric-separator',
}

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

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

0 comments on commit 72f1abf

Please sign in to comment.
You can’t perform that action at this time.