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

Side by Side Diff: test/mjsunit/es6/throw-caught-by-default-reject-handler.js

Issue 461023002: Ignore default reject handler when looking for reject handlers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 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 7 // Test debug events when we only listen to uncaught exceptions and
8 // there is a catch handler for the to-be-rejected Promise. 8 // there is a catch handler for the to-be-rejected Promise.
9 // We expect an Exception debug event with a promise to be triggered. 9 // We expect an Exception debug event with a promise to be triggered.
10 10
11 Debug = debug.Debug; 11 Debug = debug.Debug;
12 12
13 var expected_events = 1; 13 var expected_events = 2;
14 var log = []; 14 var log = [];
15 15
16 var reject_closure; 16 var resolve, reject;
17 17 var p0 = new Promise(function(res, rej) { resolve = res; reject = rej; });
18 var p = new Promise(function(resolve, reject) { 18 var p1 = p0.then(function() {
19 log.push("postpone p"); 19 log.push("p0.then");
20 reject_closure = reject; 20 throw new Error("123"); // event
21 });
22 var p2 = p1.then(function() {
23 log.push("p1.then");
21 }); 24 });
22 25
23 var q = new Promise(function(resolve, reject) { 26 var q = new Promise(function(res, rej) {
24 log.push("resolve q"); 27 log.push("resolve q");
25 resolve(); 28 res();
26 }); 29 });
27 30
28 q.then(function() { 31 q.then(function() {
29 log.push("reject p"); 32 log.push("resolve p");
30 reject_closure(new Error("uncaught reject p")); // event 33 resolve();
31 }) 34 })
32 35
33 36
34 function listener(event, exec_state, event_data, data) { 37 function listener(event, exec_state, event_data, data) {
35 try { 38 try {
36 if (event == Debug.DebugEvent.Exception) { 39 if (event == Debug.DebugEvent.Exception) {
37 expected_events--; 40 expected_events--;
38 assertTrue(expected_events >= 0); 41 assertTrue(expected_events >= 0);
39 assertEquals("uncaught reject p", event_data.exception().message); 42 assertTrue(event_data.uncaught());
40 assertTrue(event_data.promise() instanceof Promise); 43 assertTrue(event_data.promise() instanceof Promise);
41 assertSame(p, event_data.promise()); 44 if (expected_events == 1) {
42 assertTrue(event_data.uncaught()); 45 // p1 is rejected, uncaught except for its default reject handler.
43 // Assert that the debug event is triggered at the throw site. 46 assertTrue(
44 assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0); 47 exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
48 assertSame(p1, event_data.promise());
49 } else {
50 // p2 is rejected by p1's default reject handler.
aandrey 2014/08/13 11:03:04 do we want the debugger to stop twice in this exam
Yang 2014/08/13 11:13:49 I'm not sure. Maybe we should suppress rejections
aandrey 2014/08/13 11:22:03 I'm not sure either, but DevTools will ignore paus
51 assertEquals(0, exec_state.frameCount());
52 assertSame(p2, event_data.promise());
53 }
45 } 54 }
46 } catch (e) { 55 } catch (e) {
47 %AbortJS(e + "\n" + e.stack); 56 %AbortJS(e + "\n" + e.stack);
48 } 57 }
49 } 58 }
50 59
51 Debug.setBreakOnUncaughtException(); 60 Debug.setBreakOnUncaughtException();
52 Debug.setListener(listener); 61 Debug.setListener(listener);
53 62
54 log.push("end main"); 63 log.push("end main");
55 64
56 function testDone(iteration) { 65 function testDone(iteration) {
57 function checkResult() { 66 function checkResult() {
58 try { 67 try {
59 assertTrue(iteration < 10); 68 assertTrue(iteration < 10);
60 if (expected_events === 0) { 69 if (expected_events === 0) {
61 assertEquals(["postpone p", "resolve q", "end main", "reject p"], log); 70 assertEquals(["resolve q", "end main", "resolve p", "p0.then"], log);
aandrey 2014/08/13 11:03:04 ditto
Yang 2014/08/13 11:13:49 Acknowledged.
62 } else { 71 } else {
63 testDone(iteration + 1); 72 testDone(iteration + 1);
64 } 73 }
65 } catch (e) { 74 } catch (e) {
66 %AbortJS(e + "\n" + e.stack); 75 %AbortJS(e + "\n" + e.stack);
67 } 76 }
68 } 77 }
69 78
70 // Run testDone through the Object.observe processing loop. 79 // Run testDone through the Object.observe processing loop.
71 var dummy = {}; 80 var dummy = {};
72 Object.observe(dummy, checkResult); 81 Object.observe(dummy, checkResult);
73 dummy.dummy = dummy; 82 dummy.dummy = dummy;
74 } 83 }
75 84
76 testDone(0); 85 testDone(0);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698