Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 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 | Debug = debug.Debug; |
| 8 | var listened = false; |
| 9 | |
| 10 | function listener(event, exec_state, event_data, data) { |
| 11 | if (event != Debug.DebugEvent.Break) return; |
| 12 | try { |
| 13 | var foo_arguments = exec_state.frame(1).evaluate("arguments").value(); |
| 14 | var bar_arguments = exec_state.frame(0).evaluate("arguments").value(); |
| 15 | assertArrayEquals(foo_expected, foo_arguments); |
| 16 | assertArrayEquals(bar_expected, bar_arguments); |
| 17 | listened = true; |
| 18 | } catch (e) { |
| 19 | print(e); |
| 20 | print(e.stack); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | Debug.setListener(listener); |
| 25 | |
| 26 | function foo(a) { |
| 27 | function bar(a,b,c) { |
| 28 | debugger; |
| 29 | return a + b + c; |
| 30 | } |
| 31 | return bar(1,2,a); |
| 32 | } |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 33 | %PrepareFunctionForOptimization(foo); |
Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 34 | |
| 35 | listened = false; |
| 36 | foo_expected = [3]; |
| 37 | bar_expected = [1,2,3]; |
| 38 | assertEquals(6, foo(3)); |
| 39 | assertTrue(listened); |
| 40 | |
| 41 | listened = false; |
| 42 | foo_expected = [3]; |
| 43 | bar_expected = [1,2,3]; |
| 44 | assertEquals(6, foo(3)); |
| 45 | assertTrue(listened); |
| 46 | |
| 47 | listened = false; |
| 48 | foo_expected = [3]; |
| 49 | bar_expected = [1,2,3]; |
| 50 | %OptimizeFunctionOnNextCall(foo); |
| 51 | assertEquals(6, foo(3)); |
| 52 | assertTrue(listened); |
| 53 | |
| 54 | listened = false; |
| 55 | foo_expected = [3,4,5]; |
| 56 | bar_expected = [1,2,3]; |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 57 | %PrepareFunctionForOptimization(foo); |
Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 58 | %OptimizeFunctionOnNextCall(foo); |
| 59 | assertEquals(6, foo(3,4,5)); |
| 60 | assertTrue(listened); |
| 61 | |
| 62 | Debug.setListener(null); |