Commit 23bb8fa9 authored by bmeurer's avatar bmeurer Committed by Commit bot

[test] Increase test coverage for Array constructor inlining.

This still doesn't cover all the paths yet, since some paths are
impossible to trigger at this point due to the way the CanInlineCall
predicate works on the AllocationSite, which says multiple things:

 - In case of Array(len), the len was always a Smi so far.
 - In case of Array(...args), storing the args didn't change the
   elements kind.
 - In case of Array(len), the len was always less than the initial
   maximum fast element array size.

These conditions are tailored towards Crankshaft and don't really
make a lot of sense in the TurboFan world. We'd need more fine
grained protections, which we will achieve by refactoring the Array
constructor.

BUG=chromium:715404,v8:6262
TBR=machenbach@chromium.org

Review-Url: https://codereview.chromium.org/2843033002
Cr-Commit-Position: refs/heads/master@{#44901}
parent a1a30904
// 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));
})();
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