blob: 73718eec7b559eea74606c0e6990079b0785d098 [file] [log] [blame]
Ben Murdoch61f157c2016-09-16 13:49:30 +01001// 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
7var Debug = debug.Debug;
8var listenerComplete = false;
9var exception = null;
10var count = 0;
11var log = [];
12var done = false;
13
14function LogX(x) {
15 var stored_count = count;
16 return function() {
17 log.push(`[${stored_count}] ${x}`);
18 };
19}
20
21function DebuggerStatement() {
22 log.push(`[${count}] debugger`);
23 if (count++ < 3) {
24 debugger;
25 }
26}
27
28function 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.
47Debug.setListener(listener);
48
49DebuggerStatement();
50LogX("start")();
51
52// Make sure that the debug event listener was invoked.
53assertTrue(listenerComplete);
54
55%RunMicrotasks();
56
57var 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
66assertEquals(expectation, log);