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: --expose-debug-as debug
6
7// Test debug events when we only listen to uncaught exceptions and
8// an exception is thrown in the Promise constructor, but caught in an
9// inner try-catch.  The Promise is rejected afterwards.
10// We expect an Exception debug event with a promise to be triggered.
11
12Debug = debug.Debug;
13
14var step = 0;
15var exception = null;
16
17function listener(event, exec_state, event_data, data) {
18  try {
19    if (event == Debug.DebugEvent.Exception) {
20      assertEquals(0, step);
21      assertEquals("uncaught", event_data.exception().message);
22      assertTrue(event_data.promise() instanceof Promise);
23      assertTrue(event_data.uncaught());
24      // Assert that the debug event is triggered at the throw site.
25      assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
26      step++;
27    }
28  } catch (e) {
29    exception = e;
30  }
31}
32
33Debug.setBreakOnUncaughtException();
34Debug.setListener(listener);
35
36var p = new Promise(function(resolve, reject) {
37  try {  // This try-catch must not prevent this uncaught reject event.
38    throw new Error("caught");
39  } catch (e) { }
40  reject(new Error("uncaught"));  // event
41});
42
43assertEquals(1, step);
44assertNull(exception);
45