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 test(expected, f) { |
| 8 | assertEquals(expected, f()); |
| 9 | assertEquals(expected, f()); |
| 10 | %OptimizeFunctionOnNextCall(f); |
| 11 | assertEquals(expected, f()); |
| 12 | assertEquals(expected, f()); |
| 13 | } |
| 14 | |
| 15 | function testThrows(f) { |
| 16 | assertThrows(f); |
| 17 | assertThrows(f); |
| 18 | %OptimizeFunctionOnNextCall(f); |
| 19 | assertThrows(f); |
| 20 | assertThrows(f); |
| 21 | } |
| 22 | |
| 23 | // --- Constant case. |
| 24 | a = 11; |
| 25 | |
| 26 | function f1() { return a; } |
| 27 | test(11, f1); |
| 28 | |
| 29 | delete a; |
| 30 | |
| 31 | testThrows(f1); |
| 32 | |
| 33 | |
| 34 | // --- SMI case. |
| 35 | |
| 36 | b = 11; |
| 37 | b = 12; |
| 38 | b = 13; |
| 39 | |
| 40 | function f2() { return b; } |
| 41 | test(13, f2); |
| 42 | |
| 43 | delete b; |
| 44 | |
| 45 | testThrows(f2); |
| 46 | |
| 47 | |
| 48 | // --- double case. |
| 49 | |
| 50 | c = 11; |
| 51 | c = 12.25; |
| 52 | c = 13.25; |
| 53 | |
| 54 | function f3() { return c; } |
| 55 | test(13.25, f3); |
| 56 | |
| 57 | delete c; |
| 58 | |
| 59 | testThrows(f3); |
| 60 | |
| 61 | |
| 62 | // --- tagged case. |
| 63 | |
| 64 | d = 11; |
| 65 | d = 12.25; |
| 66 | d = "hello"; |
| 67 | |
| 68 | function f4() { return d; } |
| 69 | test("hello", f4); |
| 70 | |
| 71 | delete d; |
| 72 | |
| 73 | testThrows(f4); |