Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1 | // Copyright 2014 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 --expose-debug-as debug |
| 6 | |
| 7 | Debug = debug.Debug |
| 8 | var exception = null; |
| 9 | var break_count = 0; |
| 10 | var expected_breaks = -1; |
| 11 | |
| 12 | function listener(event, exec_state, event_data, data) { |
| 13 | try { |
| 14 | if (event == Debug.DebugEvent.Break) { |
| 15 | assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace"); |
| 16 | if (!break_count) { |
| 17 | // Count number of expected breakpoints in this source file. |
| 18 | var source_text = exec_state.frame(0).func().script().source(); |
| 19 | expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length; |
| 20 | print("Expected breaks: " + expected_breaks); |
| 21 | } |
| 22 | var source = exec_state.frame(0).sourceLineText(); |
| 23 | print("paused at: " + source); |
| 24 | assertTrue(source.indexOf("// Break " + break_count + ".") > 0, |
| 25 | "Unexpected pause at: " + source + "\n" + |
| 26 | "Expected: // Break " + break_count + "."); |
| 27 | if (source.indexOf("StepOver.") !== -1) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | exec_state.prepareStep(Debug.StepAction.StepNext); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 29 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 30 | exec_state.prepareStep(Debug.StepAction.StepIn); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 31 | } |
| 32 | ++break_count; |
| 33 | } |
| 34 | } catch (e) { |
| 35 | exception = e; |
| 36 | print(e, e.stack); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | Debug.setListener(listener); |
| 41 | |
| 42 | Promise.resolve(42) |
| 43 | .then(promise1) |
| 44 | .then(Object) // Should skip stepping into native. |
| 45 | .then(Boolean) // Should skip stepping into native. |
| 46 | .then(promise2) |
| 47 | .catch(promise3) |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 48 | .then(promise4) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 49 | .catch(function(e) { |
| 50 | %AbortJS("FAIL: uncaught exception " + e); |
| 51 | }); |
| 52 | |
| 53 | function promise1() { |
| 54 | debugger; // Break 0. |
| 55 | return exception || 1; // Break 1. |
| 56 | } // Break 2. |
| 57 | |
| 58 | function promise2() { |
| 59 | throw new Error; // Break 3. |
| 60 | } |
| 61 | |
| 62 | function promise3() { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 63 | return break_count; // Break 4. |
| 64 | } // Break 5. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 65 | |
| 66 | function promise4() { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 67 | finalize(); // Break 6. StepOver. |
| 68 | return 0; // Break 7. |
| 69 | } // Break 8. StepOver. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 70 | |
| 71 | function finalize() { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 72 | Promise.resolve().then(function() { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 73 | if (expected_breaks !== break_count) { |
| 74 | %AbortJS("FAIL: expected <" + expected_breaks + "> breaks instead of <" + |
| 75 | break_count + ">"); |
| 76 | } |
| 77 | if (exception !== null) { |
| 78 | %AbortJS("FAIL: exception: " + exception); |
| 79 | } |
| 80 | }); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 81 | } |