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.
5 // Flags: --harmony-promises --expose-debug-as debug
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 an Exception debug event with a promise to be triggered.
16 var p = new Promise(function(resolve, reject) {
21 function MyPromise(resolver) {
22 var reject = function() {
23 log.push("throw reject");
24 throw new Error("reject"); // event
26 var resolve = function() { };
27 log.push("construct");
28 resolver(resolve, reject);
31 MyPromise.prototype = p;
32 p.constructor = MyPromise;
36 log.push("throw caught");
37 throw new Error("caught");
40 function listener(event, exec_state, event_data, data) {
42 if (event == Debug.DebugEvent.Exception) {
43 assertEquals(["resolve", "construct", "end main",
44 "throw caught", "throw reject"], log);
45 assertEquals("reject", event_data.exception().message);
46 assertEquals(q, event_data.promise());
47 assertTrue(exec_state.frame(0).sourceLineText().indexOf('// event') > 0);
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);
58 Debug.setBreakOnUncaughtException();
59 Debug.setListener(listener);