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 log.push(match[1]); | |
19 } catch (e) { | |
20 exception = e; | |
21 } | |
22 } | |
23 | |
24 | |
25 function* g() { | |
26 try { | |
27 throw 0; // Ordinary throw. Exception a | |
28 } catch (e) {} | |
29 try { | |
30 yield 1; // Caught internally. Exception b | |
31 } catch (e) {} | |
32 yield 2; | |
33 yield 3; // Caught externally. Exception c | |
34 yield 4; | |
35 } | |
36 | |
37 Debug.setListener(listener); | |
38 Debug.setBreakOnException(); | |
39 var g_obj = g(); | |
40 assertEquals(1, g_obj.next().value); | |
41 assertEquals(2, g_obj.throw("a").value); | |
neis
2016/07/05 09:30:51
The arguments to throw are a little confusing. May
| |
42 assertEquals(3, g_obj.next().value); | |
43 assertThrows(() => g_obj.throw("b")); | |
44 assertThrows(() => g_obj.throw("c")); // Closed generator. Exception d | |
45 Debug.setListener(null); | |
46 Debug.clearBreakOnException(); | |
47 assertEquals(["a", "b", "c", "d"], log); | |
48 assertNull(exception); | |
OLD | NEW |