OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax |
| 6 |
| 7 // Test Array call with known Boolean. |
| 8 (() => { |
| 9 function foo(x) { return Array(!!x); } |
| 10 |
| 11 assertEquals([true], foo(true)); |
| 12 assertEquals([false], foo(false)); |
| 13 %OptimizeFunctionOnNextCall(foo); |
| 14 assertEquals([true], foo(true)); |
| 15 assertEquals([false], foo(false)); |
| 16 })(); |
| 17 |
| 18 // Test Array construct with known Boolean. |
| 19 (() => { |
| 20 function foo(x) { return new Array(!!x); } |
| 21 |
| 22 assertEquals([true], foo(true)); |
| 23 assertEquals([false], foo(false)); |
| 24 %OptimizeFunctionOnNextCall(foo); |
| 25 assertEquals([true], foo(true)); |
| 26 assertEquals([false], foo(false)); |
| 27 })(); |
| 28 |
| 29 // Test Array call with known String. |
| 30 (() => { |
| 31 function foo(x) { return Array("" + x); } |
| 32 |
| 33 assertEquals(["a"], foo("a")); |
| 34 assertEquals(["b"], foo("b")); |
| 35 %OptimizeFunctionOnNextCall(foo); |
| 36 assertEquals(["a"], foo("a")); |
| 37 assertEquals(["b"], foo("b")); |
| 38 })(); |
| 39 |
| 40 // Test Array construct with known String. |
| 41 (() => { |
| 42 function foo(x) { return new Array("" + x); } |
| 43 |
| 44 assertEquals(["a"], foo("a")); |
| 45 assertEquals(["b"], foo("b")); |
| 46 %OptimizeFunctionOnNextCall(foo); |
| 47 assertEquals(["a"], foo("a")); |
| 48 assertEquals(["b"], foo("b")); |
| 49 })(); |
| 50 |
| 51 // Test Array call with known fixed small integer. |
| 52 (() => { |
| 53 function foo() { return Array(2); } |
| 54 |
| 55 assertEquals(2, foo().length); |
| 56 assertEquals(2, foo().length); |
| 57 %OptimizeFunctionOnNextCall(foo); |
| 58 assertEquals(2, foo().length); |
| 59 })(); |
| 60 |
| 61 // Test Array construct with known fixed small integer. |
| 62 (() => { |
| 63 function foo() { return new Array(2); } |
| 64 |
| 65 assertEquals(2, foo().length); |
| 66 assertEquals(2, foo().length); |
| 67 %OptimizeFunctionOnNextCall(foo); |
| 68 assertEquals(2, foo().length); |
| 69 })(); |
| 70 |
| 71 // Test Array call with multiple parameters. |
| 72 (() => { |
| 73 function foo(x, y, z) { return Array(x, y, z); } |
| 74 |
| 75 assertEquals([1, 2, 3], foo(1, 2, 3)); |
| 76 assertEquals([1, 2, 3], foo(1, 2, 3)); |
| 77 %OptimizeFunctionOnNextCall(foo); |
| 78 assertEquals([1, 2, 3], foo(1, 2, 3)); |
| 79 })(); |
| 80 |
| 81 // Test Array construct with multiple parameters. |
| 82 (() => { |
| 83 function foo(x, y, z) { return new Array(x, y, z); } |
| 84 |
| 85 assertEquals([1, 2, 3], foo(1, 2, 3)); |
| 86 assertEquals([1, 2, 3], foo(1, 2, 3)); |
| 87 %OptimizeFunctionOnNextCall(foo); |
| 88 assertEquals([1, 2, 3], foo(1, 2, 3)); |
| 89 })(); |
OLD | NEW |