Commit 72f1abfb authored by Mathias Bynens's avatar Mathias Bynens Committed by Commit Bot

[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:

https://github.com/tc39/proposal-flatMap/commit/093eacc7fe0906e70f7626bf6c7d6e9dfc53cce9

Bug: v8:7220
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Ie8049ae4d4589a4ae7fe3d203053cef798c135e4
Reviewed-on: https://chromium-review.googlesource.com/1069467Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53294}
parent 6b2c305c
......@@ -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) \
......
// 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');
......
// 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-flatten
assertEquals(Array.prototype.flatten.length, 0);
assertEquals(Array.prototype.flatten.name, 'flatten');
const input = [1, [2], [[3]]];
assertEquals(input.flatten(), [1, 2, [3]]);
assertEquals(input.flatten(1), [1, 2, [3]]);
assertEquals(input.flatten(true), [1, 2, [3]]);
assertEquals(input.flatten(undefined), [1, 2, [3]]);
assertEquals(input.flatten(-Infinity), [1, [2], [[3]]]);
assertEquals(input.flatten(-1), [1, [2], [[3]]]);
assertEquals(input.flatten(-0), [1, [2], [[3]]]);
assertEquals(input.flatten(0), [1, [2], [[3]]]);
assertEquals(input.flatten(false), [1, [2], [[3]]]);
assertEquals(input.flatten(null), [1, [2], [[3]]]);
assertEquals(input.flatten(''), [1, [2], [[3]]]);
assertEquals(input.flatten('foo'), [1, [2], [[3]]]);
assertEquals(input.flatten(/./), [1, [2], [[3]]]);
assertEquals(input.flatten([]), [1, [2], [[3]]]);
assertEquals(input.flatten({}), [1, [2], [[3]]]);
assertEquals(
input.flatten(new Proxy({}, {})), [1, [2], [[3]]]);
assertEquals(input.flatten((x) => x), [1, [2], [[3]]]);
assertEquals(
input.flatten(String), [1, [2], [[3]]]);
assertEquals(input.flatten(2), [1, 2, 3]);
assertEquals(input.flatten(Infinity), [1, 2, 3]);
assertThrows(() => { input.flatten(Symbol()); }, TypeError);
assertThrows(() => { input.flatten(Object.create(null)); }, TypeError);
......@@ -49,14 +49,18 @@ FEATURE_FLAGS = {
'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")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment