OLD | NEW |
(Empty) | |
| 1 // 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: --harmony-promises --expose-debug-as debug |
| 6 |
| 7 // Test debug events when an exception is thrown inside a Promise, which is |
| 8 // caught by a custom promise, which throws a new exception in its reject |
| 9 // handler. We expect a PendingExceptionInPromise event to be triggered. |
| 10 |
| 11 Debug = debug.Debug; |
| 12 |
| 13 var log = []; |
| 14 var step = 0; |
| 15 |
| 16 var p = new Promise(function(resolve, reject) { |
| 17 log.push("resolve"); |
| 18 resolve(); |
| 19 }); |
| 20 |
| 21 function MyPromise(resolver) { |
| 22 var reject = function() { |
| 23 log.push("throw reject"); |
| 24 throw new Error("reject"); |
| 25 }; |
| 26 var resolve = function() { }; |
| 27 log.push("construct"); |
| 28 resolver(resolve, reject); |
| 29 }; |
| 30 |
| 31 MyPromise.prototype = p; |
| 32 p.constructor = MyPromise; |
| 33 |
| 34 var q = p.chain( |
| 35 function() { |
| 36 log.push("throw caught"); |
| 37 throw new Error("caught"); |
| 38 }); |
| 39 |
| 40 function listener(event, exec_state, event_data, data) { |
| 41 try { |
| 42 if (event == Debug.DebugEvent.PendingExceptionInPromise) { |
| 43 assertEquals(["resolve", "construct", "end main", |
| 44 "throw caught", "throw reject"], log); |
| 45 assertEquals("caught", event_data.exception().message); |
| 46 } else if (event == Debug.DebugEvent.Exception) { |
| 47 assertUnreachable(); |
| 48 } |
| 49 } catch (e) { |
| 50 // Signal a failure with exit code 1. This is necessary since the |
| 51 // debugger swallows exceptions and we expect the chained function |
| 52 // and this listener to be executed after the main script is finished. |
| 53 print("Unexpected exception: " + e + "\n" + e.stack); |
| 54 quit(1); |
| 55 } |
| 56 } |
| 57 |
| 58 Debug.setBreakOnUncaughtException(); |
| 59 Debug.setListener(listener); |
| 60 |
| 61 log.push("end main"); |
OLD | NEW |