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 | var boom = { valueOf: function() { throw "boom" } }; |
| 8 | |
| 9 | function mult_left_plain(x) { |
| 10 | try { |
| 11 | return 2 * x; |
| 12 | } catch (e) { |
| 13 | return e; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | %OptimizeFunctionOnNextCall(mult_left_plain); |
| 18 | assertEquals("boom", mult_left_plain(boom)); |
| 19 | assertEquals(46, mult_left_plain(23)); |
| 20 | |
| 21 | function mult_right_plain(x) { |
| 22 | try { |
| 23 | return x * 3; |
| 24 | } catch (e) { |
| 25 | return e; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | %OptimizeFunctionOnNextCall(mult_right_plain); |
| 30 | assertEquals("boom", mult_right_plain(boom)); |
| 31 | assertEquals(69, mult_right_plain(23)); |
| 32 | |
| 33 | function mult_none_plain(x,y) { |
| 34 | try { |
| 35 | return x * y; |
| 36 | } catch (e) { |
| 37 | return e; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | %OptimizeFunctionOnNextCall(mult_none_plain); |
| 42 | assertEquals("boom", mult_none_plain(boom, boom)); |
| 43 | assertEquals("boom", mult_none_plain(boom, 2)); |
| 44 | assertEquals("boom", mult_none_plain(2, boom)); |
| 45 | assertEquals(966, mult_none_plain(23, 42)); |