b62a7f18cb
It shipped in Chrome 69. Bug: v8:7220, v8:8562 Change-Id: I09d5ee9e98fc32ae3163c8983d552b99ac4f08e6 Reviewed-on: https://chromium-review.googlesource.com/c/1450781 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Mathias Bynens <mathias@chromium.org> Cr-Commit-Position: refs/heads/master@{#59309}
64 lines
2.1 KiB
JavaScript
64 lines
2.1 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.
|
|
|
|
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);
|
|
}
|
|
|
|
{
|
|
const input = { 0: 'a', 1: 'b', 2: 'c', length: 'wat' };
|
|
assertEquals(Array.prototype.flat.call(input, Infinity), []);
|
|
}
|
|
|
|
{
|
|
let count = 0;
|
|
const input = {
|
|
get length() { ++count; return 0; }
|
|
};
|
|
const result = Array.prototype.flat.call(input, Infinity);
|
|
assertEquals(count, 1);
|
|
}
|
|
|
|
{
|
|
const descriptor = Object.getOwnPropertyDescriptor(
|
|
Array.prototype,
|
|
'flat'
|
|
);
|
|
assertEquals(descriptor.value, Array.prototype.flat);
|
|
assertEquals(descriptor.writable, true);
|
|
assertEquals(descriptor.enumerable, false);
|
|
assertEquals(descriptor.configurable, true);
|
|
}
|