OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 | |
6 | |
7 Debug = debug.Debug | |
8 | |
9 var exception = null; | |
10 var log = []; | |
11 | |
12 function listener(event, exec_state, event_data, data) { | |
13 if (event != Debug.DebugEvent.Exception) return; | |
14 try { | |
15 var line = exec_state.frame(0).sourceLineText(); | |
16 var match = /Exception (\w)/.exec(line); | |
17 assertNotNull(match); | |
18 assertEquals(match[1], event_data.exception()); | |
19 log.push(match[1]); | |
20 } catch (e) { | |
21 exception = e; | |
22 } | |
23 } | |
24 | |
25 | |
26 function* g() { | |
27 try { | |
28 throw "a"; // Ordinary throw. Exception a | |
29 } catch (e) {} | |
30 try { | |
31 yield 1; // Caught internally. Exception b | |
32 } catch (e) {} | |
33 yield 2; | |
34 yield 3; // Caught externally. Exception c | |
35 yield 4; | |
36 } | |
37 | |
38 Debug.setListener(listener); | |
39 Debug.setBreakOnException(); | |
40 var g_obj = g(); | |
41 assertEquals(1, g_obj.next().value); | |
42 assertEquals(2, g_obj.throw("b").value); | |
43 assertEquals(3, g_obj.next().value); | |
44 assertThrows(() => g_obj.throw("c")); | |
45 assertThrows(() => g_obj.throw("d")); // Closed generator. Exception d | |
46 Debug.setListener(null); | |
47 Debug.clearBreakOnException(); | |
48 assertEquals(["a", "b", "c", "d"], log); | |
49 assertNull(exception); | |
OLD | NEW |