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