v8/test/mjsunit/harmony/array-flatten.js
Mathias Bynens 697d39abff [esnext] Implement Array.prototype.{flatten,flatMap} 🥙
Proposal repo: https://tc39.github.io/proposal-flatMap/

Bug: v8:7220
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I61661fc6d5c39d084ce5c96a9e150e5c26799e2d
Also-By: bmeurer@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/957043
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51967}
2018-03-15 17:26:12 +00:00

39 lines
1.6 KiB
JavaScript

// 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);