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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime-test.cc ('k') | test/mjsunit/mjsunit.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/basic-promise.js
diff --git a/test/mjsunit/basic-promise.js b/test/mjsunit/basic-promise.js
new file mode 100644
index 0000000000000000000000000000000000000000..9905fa475fa88db9f23e64b9eb71efd29b7db428
--- /dev/null
+++ b/test/mjsunit/basic-promise.js
@@ -0,0 +1,50 @@
+// Copyright 2017 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --allow-natives-syntax
+
+// We have to patch mjsunit because normal assertion failures just throw
+// exceptions which are swallowed in a then clause.
+failWithMessage = (msg) => %AbortJS(msg);
+
+let decrement = () => { %DecrementWaitCount(); }
+let increment = () => { %IncrementWaitCount(); }
+
+function WaitForPromise(p) {
+ increment();
+ p.then(decrement, decrement);
+}
+
+function newPromise() {
+ var outerResolve;
+ var outerReject;
+ let promise = new Promise((resolve, reject) => {
+ outerResolve = resolve;
+ outerReject = reject;
+ });
+ WaitForPromise(promise); // explicitly wait for promise to resolve.
+ return {
+ resolve: outerResolve,
+ reject: outerReject,
+ then: (f, g) => promise.then(f, g)
+ };
+}
+
+(function ResolveOK() {
+ let promise = newPromise();
+ promise.then(msg => {print("resolved: " + msg); assertEquals("ok", msg); },
+ ex => {print("rejected: " + ex); %AbortJS("" + ex); });
+
+ promise.resolve("ok");
+ promise.reject(11); // ignored
+})();
+
+(function RejectOK() {
+ let promise = newPromise();
+ promise.then(msg => {print("resolved: " + msg); %AbortJS("fail"); },
+ ex => {print("rejected: " + ex); assertEquals(42, ex); });
+
+ promise.reject(42);
+ promise.resolve("fail"); // ignored
+})();
« 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