2f5e0bac8d
This adds support for lowering of nodes having the {JSCreateArray} operator even if they have exceptional control projections (e.g. are placed inside a try-block). R=mvstanton@chromium.org TEST=mjsunit/compiler/array-constructor Change-Id: I2fe34dbb3729b4763471f2638a960b01c531c038 Reviewed-on: https://chromium-review.googlesource.com/554732 Reviewed-by: Jaroslav Sevcik <jarin@chromium.org> Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#46315}
101 lines
2.6 KiB
JavaScript
101 lines
2.6 KiB
JavaScript
// Copyright 2017 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: --allow-natives-syntax
|
|
|
|
// Test Array call with known Boolean.
|
|
(() => {
|
|
function foo(x) { return Array(!!x); }
|
|
|
|
assertEquals([true], foo(true));
|
|
assertEquals([false], foo(false));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals([true], foo(true));
|
|
assertEquals([false], foo(false));
|
|
})();
|
|
|
|
// Test Array construct with known Boolean.
|
|
(() => {
|
|
function foo(x) { return new Array(!!x); }
|
|
|
|
assertEquals([true], foo(true));
|
|
assertEquals([false], foo(false));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals([true], foo(true));
|
|
assertEquals([false], foo(false));
|
|
})();
|
|
|
|
// Test Array call with known String.
|
|
(() => {
|
|
function foo(x) { return Array("" + x); }
|
|
|
|
assertEquals(["a"], foo("a"));
|
|
assertEquals(["b"], foo("b"));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(["a"], foo("a"));
|
|
assertEquals(["b"], foo("b"));
|
|
})();
|
|
|
|
// Test Array construct with known String.
|
|
(() => {
|
|
function foo(x) { return new Array("" + x); }
|
|
|
|
assertEquals(["a"], foo("a"));
|
|
assertEquals(["b"], foo("b"));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(["a"], foo("a"));
|
|
assertEquals(["b"], foo("b"));
|
|
})();
|
|
|
|
// Test Array call with known fixed small integer.
|
|
(() => {
|
|
function foo() { return Array(2); }
|
|
|
|
assertEquals(2, foo().length);
|
|
assertEquals(2, foo().length);
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(2, foo().length);
|
|
})();
|
|
|
|
// Test Array construct with known fixed small integer.
|
|
(() => {
|
|
function foo() { return new Array(2); }
|
|
|
|
assertEquals(2, foo().length);
|
|
assertEquals(2, foo().length);
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals(2, foo().length);
|
|
})();
|
|
|
|
// Test Array call with multiple parameters.
|
|
(() => {
|
|
function foo(x, y, z) { return Array(x, y, z); }
|
|
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
})();
|
|
|
|
// Test Array construct with multiple parameters.
|
|
(() => {
|
|
function foo(x, y, z) { return new Array(x, y, z); }
|
|
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals([1, 2, 3], foo(1, 2, 3));
|
|
})();
|
|
|
|
// Test Array construct inside try-catch block.
|
|
(() => {
|
|
function foo(x) { try { return new Array(x) } catch (e) { return e } }
|
|
|
|
assertEquals([], foo(0));
|
|
assertEquals([], foo(0));
|
|
%OptimizeFunctionOnNextCall(foo);
|
|
assertEquals([], foo(0));
|
|
assertInstanceof(foo(-1), RangeError);
|
|
})();
|