| 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 --allow-natives-syntax | |
| 6 | |
| 7 // Test debug events when we listen to all exceptions and | |
| 8 // there is a catch handler for the exception thrown in a Promise, first | |
| 9 // caught by a try-finally, and immediately rethrown. | |
| 10 // We expect a normal Exception debug event to be triggered. | |
| 11 | |
| 12 Debug = debug.Debug; | |
| 13 | |
| 14 var expected_events = 1; | |
| 15 var log = []; | |
| 16 | |
| 17 var p = new Promise(function(resolve, reject) { | |
| 18 log.push("resolve"); | |
| 19 resolve(); | |
| 20 }); | |
| 21 | |
| 22 var q = p.then( | |
| 23 function() { | |
| 24 log.push("throw"); | |
| 25 try { | |
| 26 throw new Error("caught"); | |
| 27 } finally { | |
| 28 } | |
| 29 }); | |
| 30 | |
| 31 q.catch( | |
| 32 function(e) { | |
| 33 assertEquals("caught", e.message); | |
| 34 }); | |
| 35 | |
| 36 function listener(event, exec_state, event_data, data) { | |
| 37 try { | |
| 38 if (event == Debug.DebugEvent.Exception) { | |
| 39 expected_events--; | |
| 40 assertTrue(expected_events >= 0); | |
| 41 assertEquals("caught", event_data.exception().message); | |
| 42 assertSame(q, event_data.promise()); | |
| 43 assertFalse(event_data.uncaught()); | |
| 44 } | |
| 45 } catch (e) { | |
| 46 %AbortJS(e + "\n" + e.stack); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 Debug.setBreakOnException(); | |
| 51 Debug.setListener(listener); | |
| 52 | |
| 53 log.push("end main"); | |
| 54 | |
| 55 function testDone(iteration) { | |
| 56 function checkResult() { | |
| 57 try { | |
| 58 assertTrue(iteration < 10); | |
| 59 if (expected_events === 0) { | |
| 60 assertEquals(["resolve", "end main", "throw"], log); | |
| 61 } else { | |
| 62 testDone(iteration + 1); | |
| 63 } | |
| 64 } catch (e) { | |
| 65 %AbortJS(e + "\n" + e.stack); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 %EnqueueMicrotask(checkResult); | |
| 70 } | |
| 71 | |
| 72 testDone(0); | |
| OLD | NEW |