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 an exception is thrown inside a Promise, which is
8 // caught by a custom promise, which has no reject handler.
9 // We expect two Exception debug events:
10 // 1) when the exception is thrown in the promise q.
11 // 2) when calling the undefined custom reject closure in MyPromise throws.
15 var expected_events = 2;
18 var p = new Promise(function(resolve, reject) {
23 function MyPromise(resolver) {
24 var reject = undefined;
25 var resolve = function() { };
26 log.push("construct");
27 resolver(resolve, reject);
30 MyPromise.prototype = new Promise(function() {});
31 p.constructor = MyPromise;
35 log.push("throw caught");
36 throw new Error("caught"); // event
39 function listener(event, exec_state, event_data, data) {
41 if (event == Debug.DebugEvent.Exception) {
43 assertTrue(expected_events >= 0);
44 if (expected_events == 1) {
46 exec_state.frame(0).sourceLineText().indexOf('// event') > 0);
47 assertEquals("caught", event_data.exception().message);
48 } else if (expected_events == 0) {
49 // All of the frames on the stack are from native Javascript.
50 assertEquals(0, exec_state.frameCount());
51 assertEquals("undefined is not a function",
52 event_data.exception().message);
56 assertSame(q, event_data.promise());
59 %AbortJS(e + "\n" + e.stack);
63 Debug.setBreakOnUncaughtException();
64 Debug.setListener(listener);
68 function testDone(iteration) {
69 function checkResult() {
71 assertTrue(iteration < 10);
72 if (expected_events === 0) {
73 assertEquals(["resolve", "construct", "end main", "throw caught"], log);
75 testDone(iteration + 1);
78 %AbortJS(e + "\n" + e.stack);
82 // Run testDone through the Object.observe processing loop.
84 Object.observe(dummy, checkResult);