Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // Copyright 2015 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 test1(s) { |
| 8 | return s.toString; |
| 9 | } |
| 10 | assertSame(test1(false), Boolean.prototype.toString); |
| 11 | assertSame(test1(true), Boolean.prototype.toString); |
| 12 | %OptimizeFunctionOnNextCall(test1); |
| 13 | assertSame(test1(false), Boolean.prototype.toString); |
| 14 | assertSame(test1(true), Boolean.prototype.toString); |
| 15 | |
| 16 | function test2(s) { |
| 17 | return s.valueOf; |
| 18 | } |
| 19 | assertSame(test2(false), Boolean.prototype.valueOf); |
| 20 | assertSame(test2(true), Boolean.prototype.valueOf); |
| 21 | %OptimizeFunctionOnNextCall(test2); |
| 22 | assertSame(test2(false), Boolean.prototype.valueOf); |
| 23 | assertSame(test2(true), Boolean.prototype.valueOf); |
| 24 | |
| 25 | Boolean.prototype.foo = 42; |
| 26 | function test3(s) { |
| 27 | return s["foo"]; |
| 28 | } |
| 29 | assertEquals(test3(false), 42); |
| 30 | assertEquals(test3(true), 42); |
| 31 | %OptimizeFunctionOnNextCall(test3); |
| 32 | assertEquals(test3(false), 42); |
| 33 | assertEquals(test3(true), 42); |
| 34 | |
| 35 | Boolean.prototype.bar = function bar() { "use strict"; return this; } |
| 36 | function test4(s) { |
| 37 | return s.bar(); |
| 38 | } |
| 39 | assertEquals(test4(false), false); |
| 40 | assertEquals(test4(true), true); |
| 41 | %OptimizeFunctionOnNextCall(test4); |
| 42 | assertEquals(test4(false), false); |
| 43 | assertEquals(test4(true), true); |