| 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: --harmony-async-await | |
| 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 async function thrower() { | |
| 25 throw "a"; // Exception a | |
| 26 } | |
| 27 | |
| 28 async function caught_throw() { | |
| 29 try { | |
| 30 await thrower(); | |
| 31 } catch (e) { | |
| 32 assertEquals("a", e); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 | |
| 37 // Caught throw, events on any exception. | |
| 38 log = []; | |
| 39 Debug.setListener(listener); | |
| 40 Debug.setBreakOnException(); | |
| 41 caught_throw(); | |
| 42 %RunMicrotasks(); | |
| 43 Debug.setListener(null); | |
| 44 Debug.clearBreakOnException(); | |
| 45 assertEquals(["a"], log); | |
| 46 assertNull(exception); | |
| 47 | |
| 48 // Caught throw, events on uncaught exception. | |
| 49 log = []; | |
| 50 Debug.setListener(listener); | |
| 51 Debug.setBreakOnUncaughtException(); | |
| 52 caught_throw(); | |
| 53 %RunMicrotasks(); | |
| 54 Debug.setListener(null); | |
| 55 Debug.clearBreakOnUncaughtException(); | |
| 56 assertEquals([], log); | |
| 57 assertNull(exception); | |
| 58 | |
| 59 var reject = Promise.reject("b"); | |
| 60 | |
| 61 async function caught_reject() { | |
| 62 try { | |
| 63 await reject; | |
| 64 } catch (e) { | |
| 65 assertEquals("b", e); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 // Caught reject, events on any exception. | |
| 70 log = []; | |
| 71 Debug.setListener(listener); | |
| 72 Debug.setBreakOnException(); | |
| 73 caught_reject(); | |
| 74 %RunMicrotasks(); | |
| 75 Debug.setListener(null); | |
| 76 Debug.clearBreakOnException(); | |
| 77 assertEquals([], log); | |
| 78 assertNull(exception); | |
| 79 | |
| 80 // Caught reject, events on uncaught exception. | |
| 81 log = []; | |
| 82 Debug.setListener(listener); | |
| 83 Debug.setBreakOnUncaughtException(); | |
| 84 caught_reject(); | |
| 85 %RunMicrotasks(); | |
| 86 Debug.setListener(null); | |
| 87 Debug.clearBreakOnUncaughtException(); | |
| 88 assertEquals([], log); | |
| 89 assertNull(exception); | |
| 90 | |
| 91 log = []; | |
| 92 Debug.setListener(listener); | |
| 93 Debug.setBreakOnException(); | |
| 94 | |
| 95 // "rethrown" uncaught exceptions in return don't cause another event | |
| 96 async function propagate_inner() { return thrower(); } | |
| 97 async function propagate_outer() { return propagate_inner(); } | |
| 98 | |
| 99 propagate_outer(); | |
| 100 %RunMicrotasks(); | |
| 101 assertEquals(["a"], log); | |
| 102 assertNull(exception); | |
| 103 | |
| 104 // Also don't propagate if an await interceded | |
| 105 log = []; | |
| 106 async function propagate_await() { await 1; return thrower(); } | |
| 107 async function propagate_await_outer() { return propagate_await(); } | |
| 108 propagate_await_outer(); | |
| 109 %RunMicrotasks(); | |
| 110 assertEquals(["a"], log); | |
| 111 assertNull(exception); | |
| 112 | |
| 113 Debug.clearBreakOnException(); | |
| 114 Debug.setBreakOnUncaughtException(); | |
| 115 | |
| 116 log = []; | |
| 117 Promise.resolve().then(() => Promise.reject()).catch(() => log.push("d")); // Ex
ception c | |
| 118 %RunMicrotasks(); | |
| 119 assertEquals(["d"], log); | |
| 120 assertNull(exception); | |
| 121 | |
| 122 Debug.clearBreakOnUncaughtException(); | |
| 123 Debug.setListener(null); | |
| 124 | |
| 125 // If devtools is turned on in the middle, then catch prediction | |
| 126 // could be wrong (here, it mispredicts the exception as caught), | |
| 127 // but shouldn't crash. | |
| 128 | |
| 129 log = []; | |
| 130 | |
| 131 var resolve; | |
| 132 var turnOnListenerPromise = new Promise(r => resolve = r); | |
| 133 async function confused() { | |
| 134 await turnOnListenerPromise; | |
| 135 throw foo | |
| 136 } | |
| 137 confused(); | |
| 138 Promise.resolve().then(() => { | |
| 139 Debug.setListener(listener); | |
| 140 Debug.setBreakOnUncaughtException(); | |
| 141 resolve(); | |
| 142 }); | |
| 143 | |
| 144 assertEquals([], log); | |
| OLD | NEW |