Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: test/mjsunit/es6/debug-promises/promise-all-uncaught.js

Issue 2244003003: Change which ExceptionEvents are triggered by Promises (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed typos Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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: --expose-debug-as debug --allow-natives-syntax 5 // Flags: --expose-debug-as debug --allow-natives-syntax
6 6
7 // Test debug events when we only listen to uncaught exceptions and a 7 // Test debug events when we only listen to uncaught exceptions and a
8 // Promise p3 created by Promise.all has no catch handler, and is rejected 8 // Promise p3 created by Promise.all has no catch handler, and is rejected
9 // because one of the Promises p2 passed to Promise.all is rejected. We 9 // because one of the Promises p2 passed to Promise.all is rejected.
10 // expect two Exception debug events to be triggered, for p2 and p3 each, 10 // We expect one event for p2; the system recognizes the rejection of p3
11 // because neither has an user-defined catch handler. 11 // to be redundant and based on the rejection of p2 and does not trigger
12 // an additional rejection.
12 13
13 var Debug = debug.Debug; 14 var Debug = debug.Debug;
14 15
15 var expected_events = 2; 16 var expected_events = 1;
16 var log = []; 17 var log = [];
17 18
18 var p1 = Promise.resolve(); 19 var p1 = Promise.resolve();
19 p1.name = "p1"; 20 p1.name = "p1";
20 21
21 var p2 = p1.then(function() { 22 var p2 = p1.then(function() {
22 log.push("throw"); 23 log.push("throw");
23 throw new Error("uncaught"); // event 24 throw new Error("uncaught"); // event
24 }); 25 });
25 26
26 p2.name = "p2"; 27 p2.name = "p2";
27 28
28 var p3 = Promise.all([p2]); 29 var p3 = Promise.all([p2]);
29 p3.name = "p3"; 30 p3.name = "p3";
30 31
31 function listener(event, exec_state, event_data, data) { 32 function listener(event, exec_state, event_data, data) {
32 if (event != Debug.DebugEvent.Exception) return; 33 if (event != Debug.DebugEvent.Exception) return;
33 try { 34 try {
34 expected_events--; 35 expected_events--;
35 assertTrue(expected_events >= 0); 36 assertTrue(expected_events >= 0);
36 assertEquals("uncaught", event_data.exception().message); 37 assertEquals("uncaught", event_data.exception().message);
37 assertTrue(event_data.promise() instanceof Promise); 38 assertTrue(event_data.promise() instanceof Promise);
38 if (expected_events === 1) { 39 // Assert that the debug event is triggered at the throw site.
39 // Assert that the debug event is triggered at the throw site. 40 assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
40 assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); 41 assertEquals("p2", event_data.promise().name);
41 assertEquals("p2", event_data.promise().name);
42 } else {
43 assertEquals("p3", event_data.promise().name);
44 }
45 assertTrue(event_data.uncaught()); 42 assertTrue(event_data.uncaught());
46 } catch (e) { 43 } catch (e) {
47 %AbortJS(e + "\n" + e.stack); 44 %AbortJS(e + "\n" + e.stack);
48 } 45 }
49 } 46 }
50 47
51 Debug.setBreakOnUncaughtException(); 48 Debug.setBreakOnUncaughtException();
52 Debug.setListener(listener); 49 Debug.setListener(listener);
53 50
54 log.push("end main"); 51 log.push("end main");
55 52
56 function testDone(iteration) { 53 function testDone(iteration) {
57 function checkResult() { 54 function checkResult() {
58 try { 55 try {
59 assertTrue(iteration < 10); 56 assertTrue(iteration < 10);
60 if (expected_events === 0) { 57 if (expected_events === 0) {
61 assertEquals(["end main", "throw"], log); 58 assertEquals(["end main", "throw"], log);
62 } else { 59 } else {
63 testDone(iteration + 1); 60 testDone(iteration + 1);
64 } 61 }
65 } catch (e) { 62 } catch (e) {
66 %AbortJS(e + "\n" + e.stack); 63 %AbortJS(e + "\n" + e.stack);
67 } 64 }
68 } 65 }
69 66
70 %EnqueueMicrotask(checkResult); 67 %EnqueueMicrotask(checkResult);
71 } 68 }
72 69
73 testDone(0); 70 testDone(0);
OLDNEW
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | test/mjsunit/es6/debug-promises/promise-race-uncaught.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698