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

Side by Side Diff: test/mjsunit/basic-promise.js

Issue 2752043002: [promises] Add %WaitForPromise runtime call to allow tests to reliably wait for promises to be fini… (Closed)
Patch Set: Don't touch runtime-promise.cc Created 3 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/runtime/runtime-test.cc ('k') | test/mjsunit/mjsunit.js » ('j') | 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 2017 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: --allow-natives-syntax
6
7 // We have to patch mjsunit because normal assertion failures just throw
8 // exceptions which are swallowed in a then clause.
9 failWithMessage = (msg) => %AbortJS(msg);
10
11 let decrement = () => { %DecrementWaitCount(); }
12 let increment = () => { %IncrementWaitCount(); }
13
14 function WaitForPromise(p) {
15 increment();
16 p.then(decrement, decrement);
17 }
18
19 function newPromise() {
20 var outerResolve;
21 var outerReject;
22 let promise = new Promise((resolve, reject) => {
23 outerResolve = resolve;
24 outerReject = reject;
25 });
26 WaitForPromise(promise); // explicitly wait for promise to resolve.
27 return {
28 resolve: outerResolve,
29 reject: outerReject,
30 then: (f, g) => promise.then(f, g)
31 };
32 }
33
34 (function ResolveOK() {
35 let promise = newPromise();
36 promise.then(msg => {print("resolved: " + msg); assertEquals("ok", msg); },
37 ex => {print("rejected: " + ex); %AbortJS("" + ex); });
38
39 promise.resolve("ok");
40 promise.reject(11); // ignored
41 })();
42
43 (function RejectOK() {
44 let promise = newPromise();
45 promise.then(msg => {print("resolved: " + msg); %AbortJS("fail"); },
46 ex => {print("rejected: " + ex); assertEquals(42, ex); });
47
48 promise.reject(42);
49 promise.resolve("fail"); // ignored
50 })();
OLDNEW
« no previous file with comments | « src/runtime/runtime-test.cc ('k') | test/mjsunit/mjsunit.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698