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

Side by Side Diff: test/mjsunit/harmony/promise-prototype-finally.js

Issue 2695753002: [ESnext] Implement Promise.prototype.finally (Closed)
Patch Set: add comments Created 3 years, 10 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
« src/flag-definitions.h ('K') | « src/objects-printer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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: --harmony-promise-finally --allow-natives-syntax
6
7 var asyncAssertsExpected = 0;
8
9 function assertAsyncRan() {
10 ++asyncAssertsExpected;
11 }
12
13 function assertAsync(b, s) {
14 if (b) {
15 print(s, "succeeded");
16 } else {
17 %AbortJS(s + " FAILED!");
18 }
19 --asyncAssertsExpected;
20 }
21
22 function assertEqualsAsync(b, s) {
23 if (b === s) {
24 print(b, "===", s, "succeeded");
25 } else {
26 %AbortJS(b + "===" + s + " FAILED!");
27 }
28 --asyncAssertsExpected;
29 }
30
31 function assertAsyncDone(iteration) {
32 var iteration = iteration || 0;
33 %EnqueueMicrotask(function() {
34 if (asyncAssertsExpected === 0)
35 assertAsync(true, "all");
36 else if (
37 iteration > 10 // Shouldn't take more.
38 )
39 assertAsync(false, "all... " + asyncAssertsExpected);
40 else
41 assertAsyncDone(iteration + 1);
42 });
43 }
44
45 (function() {
46 Promise.resolve(3)
47 .then(x => {
48 assertEqualsAsync(3, x);
49 return x;
50 })
neis 2017/02/15 12:40:40 Is this .then call useful at all?
gsathya 2017/02/16 15:05:30 Removed
neis 2017/02/17 10:22:54 Still there.
gsathya 2017/02/17 11:26:16 Can you comment on the latest patch set? I can't f
51 .finally()
52 .then(
53 x => {
54 assertEqualsAsync(3, x);
55 },
56 assertUnreachable
neis 2017/02/15 12:40:40 assertUnreachable here is wrong since it would jus
gsathya 2017/02/16 15:05:30 assertUnreachable now aborts the test
57 );
58 assertAsyncRan();
59 assertAsyncRan();
60 })();
61
62 (function() {
63 Promise.reject(3)
64 .catch(e => {
65 assertEqualsAsync(3, e);
66 throw e;
67 })
68 .finally()
69 .then(assertUnreachable, reason => {
70 assertEqualsAsync(3, reason);
71 });
72 assertAsyncRan();
73 assertAsyncRan();
74 })();
75
76 (function() {
77 Promise.resolve(3)
78 .then(x => {
79 assertEqualsAsync(3, x);
80 return x;
81 })
82 .finally(function onFinally() {
83 assertAsync(arguments.length === 0);
neis 2017/02/15 12:40:39 Equals?
gsathya 2017/02/16 15:05:30 assertAsync is fine here since we check if true? O
neis 2017/02/17 10:22:54 Yeah I don't see why you don't use assertEqualsAsy
gsathya 2017/02/17 11:26:15 Done.
84 throw 1;
85 })
86 .then(assertUnreachable, function onRejected(reason) {
87 assertEqualsAsync(1, reason);
88 });
89 assertAsyncRan();
90 assertAsyncRan();
91 assertAsyncRan();
92 })();
93
94 (function() {
95 Promise.reject(3)
96 .finally(function onFinally() {
97 assertAsync(arguments.length === 0);
98 throw 1;
99 })
100 .then(assertUnreachable, function onRejected(reason) {
101 assertEqualsAsync(1, reason);
102 });
103 assertAsyncRan();
104 assertAsyncRan();
105 })();
106
107 (function() {
108 Promise.resolve(3)
109 .then(x => {
110 assertEqualsAsync(3, x);
111 return x;
112 })
113 .finally(function onFinally() {
114 assertAsync(arguments.length === 0);
115 return 4;
116 })
117 .then(
118 function onFulfilled(x) {
119 assertEqualsAsync(x, 3);
120 },
121 assertUnreachable
122 );
123 assertAsyncRan();
124 assertAsyncRan();
125 assertAsyncRan();
126 })();
127
128 (function() {
129 Promise.reject(3)
130 .catch(e => {
131 assertEqualsAsync(3, e);
132 throw e;
133 })
134 .finally(function onFinally() {
135 assertAsync(arguments.length === 0);
136 throw 4;
137 })
138 .then(assertUnreachable, function onRejected(e) {
139 assertEqualsAsync(4, e);
140 });
141 assertAsyncRan();
142 assertAsyncRan();
143 assertAsyncRan();
144 })();
145
146 (function() {
147 Promise.resolve(3)
148 .then(x => {
149 assertEqualsAsync(3, x);
150 return x;
151 })
152 .finally(function onFinally() {
153 assertAsync(arguments.length === 0);
154 return Promise.reject(4);
155 })
156 .then(assertUnreachable, e => {
157 assertEqualsAsync(4, e);
158 });
159 assertAsyncRan();
160 assertAsyncRan();
161 assertAsyncRan();
162 })();
163
164 assertAsyncDone();
neis 2017/02/15 12:40:39 Please add some tests that check that .finally jus
gsathya 2017/02/16 15:05:30 Added a whole bunch of tests. PTAL.
neis 2017/02/17 10:22:54 I'm still missing a test passing an argument to .f
gsathya 2017/02/17 11:26:15 You mean, makes sure that it's not being passed on
OLDNEW
« src/flag-definitions.h ('K') | « src/objects-printer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698