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: --expose-debug-as debug --allow-natives-syntax
7 // Test debug events when we only listen to uncaught exceptions and
8 // there is only a default reject handler for the to-be-rejected Promise.
9 // We expect two Exception debug events:
10 // - when the first Promise is rejected and only has default reject handlers.
11 // - when the default reject handler passes the rejection on.
15 var expected_events = 2;
19 var p0 = new Promise(function(res, rej) { resolve = res; reject = rej; });
20 var p1 = p0.then(function() {
22 throw new Error("123"); // event
24 var p2 = p1.then(function() {
28 var q = new Promise(function(res, rej) {
29 log.push("resolve q");
34 log.push("resolve p");
39 function listener(event, exec_state, event_data, data) {
41 if (event == Debug.DebugEvent.Exception) {
43 assertTrue(expected_events >= 0);
44 assertTrue(event_data.uncaught());
45 assertTrue(event_data.promise() instanceof Promise);
46 if (expected_events == 1) {
47 // p1 is rejected, uncaught except for its default reject handler.
49 exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
50 assertSame(p1, event_data.promise());
52 // p2 is rejected by p1's default reject handler.
53 assertEquals(0, exec_state.frameCount());
54 assertSame(p2, event_data.promise());
58 %AbortJS(e + "\n" + e.stack);
62 Debug.setBreakOnUncaughtException();
63 Debug.setListener(listener);
67 function testDone(iteration) {
68 function checkResult() {
70 assertTrue(iteration < 10);
71 if (expected_events === 0) {
72 assertEquals(["resolve q", "end main", "resolve p", "p0.then"], log);
74 testDone(iteration + 1);
77 %AbortJS(e + "\n" + e.stack);
81 // Run testDone through the Object.observe processing loop.
83 Object.observe(dummy, checkResult);