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 has no reject handler. |
| 9 // 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 = undefined; |
| 23 var resolve = function() { }; |
| 24 log.push("construct"); |
| 25 resolver(resolve, reject); |
| 26 }; |
| 27 |
| 28 MyPromise.prototype = p; |
| 29 p.constructor = MyPromise; |
| 30 |
| 31 var q = p.chain( |
| 32 function() { |
| 33 log.push("throw caught"); |
| 34 throw new Error("caught"); |
| 35 }); |
| 36 |
| 37 function listener(event, exec_state, event_data, data) { |
| 38 try { |
| 39 if (event == Debug.DebugEvent.PendingExceptionInPromise) { |
| 40 assertEquals(["resolve", "construct", "end main", "throw caught"], log); |
| 41 assertEquals("caught", event_data.exception().message); |
| 42 } else if (event == Debug.DebugEvent.Exception) { |
| 43 assertUnreachable(); |
| 44 } |
| 45 } catch (e) { |
| 46 // Signal a failure with exit code 1. This is necessary since the |
| 47 // debugger swallows exceptions and we expect the chained function |
| 48 // and this listener to be executed after the main script is finished. |
| 49 print("Unexpected exception: " + e + "\n" + e.stack); |
| 50 quit(1); |
| 51 } |
| 52 } |
| 53 |
| 54 Debug.setBreakOnUncaughtException(); |
| 55 Debug.setListener(listener); |
| 56 |
| 57 log.push("end main"); |
OLD | NEW |