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 (function() { |
| 8 "use strict"; |
| 9 function bar() { return this; } |
| 10 |
| 11 function foo(x) { |
| 12 return bar.bind(x); |
| 13 } |
| 14 |
| 15 assertEquals(0, foo(0)()); |
| 16 assertEquals(1, foo(1)()); |
| 17 %OptimizeFunctionOnNextCall(foo); |
| 18 assertEquals("", foo("")()); |
| 19 })(); |
| 20 |
| 21 (function() { |
| 22 "use strict"; |
| 23 function bar(x) { return x; } |
| 24 |
| 25 function foo(x) { |
| 26 return bar.bind(undefined, x); |
| 27 } |
| 28 |
| 29 assertEquals(0, foo(0)()); |
| 30 assertEquals(1, foo(1)()); |
| 31 %OptimizeFunctionOnNextCall(foo); |
| 32 assertEquals("", foo("")()); |
| 33 })(); |
| 34 |
| 35 (function() { |
| 36 function bar(x) { return x; } |
| 37 |
| 38 function foo(x) { |
| 39 return bar.bind(undefined, x); |
| 40 } |
| 41 |
| 42 assertEquals(0, foo(0)()); |
| 43 assertEquals(1, foo(1)()); |
| 44 %OptimizeFunctionOnNextCall(foo); |
| 45 assertEquals("", foo("")()); |
| 46 })(); |
| 47 |
| 48 (function() { |
| 49 "use strict"; |
| 50 function bar(x, y) { return x + y; } |
| 51 |
| 52 function foo(x, y) { |
| 53 return bar.bind(undefined, x, y); |
| 54 } |
| 55 |
| 56 assertEquals(0, foo(0, 0)()); |
| 57 assertEquals(2, foo(1, 1)()); |
| 58 %OptimizeFunctionOnNextCall(foo); |
| 59 assertEquals("ab", foo("a", "b")()); |
| 60 assertEquals(0, foo(0, 1).length); |
| 61 assertEquals("bound bar", foo(1, 2).name) |
| 62 })(); |
| 63 |
| 64 (function() { |
| 65 function bar(x, y) { return x + y; } |
| 66 |
| 67 function foo(x, y) { |
| 68 return bar.bind(undefined, x, y); |
| 69 } |
| 70 |
| 71 assertEquals(0, foo(0, 0)()); |
| 72 assertEquals(2, foo(1, 1)()); |
| 73 %OptimizeFunctionOnNextCall(foo); |
| 74 assertEquals("ab", foo("a", "b")()); |
| 75 assertEquals(0, foo(0, 1).length); |
| 76 assertEquals("bound bar", foo(1, 2).name) |
| 77 })(); |
OLD | NEW |