OLD | NEW |
| (Empty) |
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: --expose-debug-as debug --allow-natives-syntax | |
6 | |
7 var Debug = debug.Debug; | |
8 var listenerComplete = false; | |
9 var exception = null; | |
10 var count = 0; | |
11 var log = []; | |
12 var done = false; | |
13 | |
14 function LogX(x) { | |
15 var stored_count = count; | |
16 return function() { | |
17 log.push(`[${stored_count}] ${x}`); | |
18 }; | |
19 } | |
20 | |
21 function DebuggerStatement() { | |
22 log.push(`[${count}] debugger`); | |
23 if (count++ < 3) { | |
24 debugger; | |
25 } | |
26 } | |
27 | |
28 function listener(event, exec_state, event_data, data) { | |
29 if (event != Debug.DebugEvent.Break) return; | |
30 try { | |
31 var p = Promise.resolve(); | |
32 var q = p.then(LogX("then 1")); | |
33 p.then(LogX("then 2")); | |
34 q.then(LogX("then 3")); | |
35 q.then(DebuggerStatement); | |
36 var r = q.then(() => { throw 1; }); | |
37 r.catch(LogX("catch")); | |
38 listenerComplete = true; | |
39 } catch (e) { | |
40 exception = e; | |
41 print(e, e.stack); | |
42 quit(1); | |
43 }; | |
44 }; | |
45 | |
46 // Add the debug event listener. | |
47 Debug.setListener(listener); | |
48 | |
49 DebuggerStatement(); | |
50 LogX("start")(); | |
51 | |
52 // Make sure that the debug event listener was invoked. | |
53 assertTrue(listenerComplete); | |
54 | |
55 %RunMicrotasks(); | |
56 | |
57 var expectation = | |
58 [ "[0] debugger", "[1] start", "[1] then 1", | |
59 "[1] then 2", "[1] then 3", "[1] debugger", | |
60 "[2] then 1", "[2] then 2", "[1] catch", | |
61 "[2] then 3", "[2] debugger", "[3] then 1", | |
62 "[3] then 2", "[2] catch", "[3] then 3", | |
63 "[3] debugger", "[3] catch", | |
64 ]; | |
65 | |
66 assertEquals(expectation, log); | |
OLD | NEW |