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 we listen to all exceptions and |
| 8 // there is a catch handler for the exception thrown in a Promise. |
| 9 // Expectation: |
| 10 // - only the normal Exception debug event is triggered. |
| 11 |
| 12 Debug = debug.Debug; |
| 13 |
| 14 var log = []; |
| 15 var step = 0; |
| 16 |
| 17 var p = new Promise(function(resolve, reject) { |
| 18 log.push("resolve"); |
| 19 resolve(); |
| 20 }); |
| 21 |
| 22 var q = p.chain( |
| 23 function() { |
| 24 log.push("throw"); |
| 25 throw new Error("caught"); |
| 26 }); |
| 27 |
| 28 q.catch( |
| 29 function(e) { |
| 30 assertEquals("caught", e.message); |
| 31 }); |
| 32 |
| 33 function listener(event, exec_state, event_data, data) { |
| 34 try { |
| 35 // Ignore exceptions during startup in stress runs. |
| 36 if (step >= 1) return; |
| 37 assertEquals(["resolve", "end main", "throw"], log); |
| 38 assertTrue(event != Debug.DebugEvent.PendingExceptionInPromise); |
| 39 if (event == Debug.DebugEvent.Exception) { |
| 40 assertEquals("caught", event_data.exception().message); |
| 41 assertEquals(undefined, event_data.promise()); |
| 42 step++; |
| 43 } |
| 44 } catch (e) { |
| 45 // Signal a failure with exit code 1. This is necessary since the |
| 46 // debugger swallows exceptions and we expect the chained function |
| 47 // and this listener to be executed after the main script is finished. |
| 48 print("Unexpected exception: " + e + "\n" + e.stack); |
| 49 quit(1); |
| 50 } |
| 51 } |
| 52 |
| 53 Debug.setBreakOnException(); |
| 54 Debug.setListener(listener); |
| 55 |
| 56 log.push("end main"); |
OLD | NEW |