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

Side by Side Diff: test/mjsunit/es6/debug-promises/throw-with-undefined-reject.js

Issue 1780823003: Check that Promise subclasses have callable resolve/reject (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix debug tests Created 4 years, 9 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
« no previous file with comments | « src/messages.h ('k') | test/test262/test262.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 --promise-extra 5 // A non-callable reject function throws eagerly
6
7 // Test debug events when an exception is thrown inside a Promise, which is
adamk 2016/03/10 02:53:06 Was this test simply impossible to get as far with
Dan Ehrenberg 2016/03/10 20:00:42 There's no such thing as "having no reject handler
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.
12
13 Debug = debug.Debug;
14
15 var expected_events = 2;
16 var log = [];
17 6
18 var p = new Promise(function(resolve, reject) { 7 var p = new Promise(function(resolve, reject) {
19 log.push("resolve"); 8 log.push("resolve");
20 resolve(); 9 resolve();
21 }); 10 });
22 11
23 function MyPromise(resolver) { 12 function MyPromise(resolver) {
24 var reject = undefined; 13 var reject = undefined;
25 var resolve = function() { }; 14 var resolve = function() { };
26 log.push("construct");
27 resolver(resolve, reject); 15 resolver(resolve, reject);
28 }; 16 };
29 17
30 MyPromise.prototype = new Promise(function() {}); 18 MyPromise.prototype = new Promise(function() {});
31 MyPromise.__proto__ = Promise; 19 MyPromise.__proto__ = Promise;
32 p.constructor = MyPromise; 20 p.constructor = MyPromise;
33 21
34 var q = p.chain( 22 assertThrows(()=> p.then(function() { }), TypeError);
35 function() {
36 log.push("throw caught");
37 throw new Error("caught"); // event
38 });
39
40 function listener(event, exec_state, event_data, data) {
41 try {
42 if (event == Debug.DebugEvent.Exception) {
43 expected_events--;
44 assertTrue(expected_events >= 0);
45 if (expected_events == 1) {
46 assertTrue(
47 exec_state.frame(0).sourceLineText().indexOf('// event') > 0);
48 assertEquals("caught", event_data.exception().message);
49 } else if (expected_events == 0) {
50 // All of the frames on the stack are from native Javascript.
51 assertEquals(0, exec_state.frameCount());
52 assertEquals("(var).reject is not a function",
53 event_data.exception().message);
54 } else {
55 assertUnreachable();
56 }
57 assertSame(q, event_data.promise());
58 }
59 } catch (e) {
60 %AbortJS(e + "\n" + e.stack);
61 }
62 }
63
64 Debug.setBreakOnUncaughtException();
65 Debug.setListener(listener);
66
67 log.push("end main");
68
69 function testDone(iteration) {
70 function checkResult() {
71 try {
72 assertTrue(iteration < 10);
73 if (expected_events === 0) {
74 assertEquals(["resolve", "construct", "end main", "throw caught"], log);
75 } else {
76 testDone(iteration + 1);
77 }
78 } catch (e) {
79 %AbortJS(e + "\n" + e.stack);
80 }
81 }
82
83 %EnqueueMicrotask(checkResult);
84 }
85
86 testDone(0);
OLDNEW
« no previous file with comments | « src/messages.h ('k') | test/test262/test262.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698