diff options
author | Michaël Zasso <targos@protonmail.com> | 2017-06-06 10:28:14 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2017-06-07 10:33:31 +0200 |
commit | 3dc8c3bed4cf3a77607edbb0b015e33f8b60fc09 (patch) | |
tree | 9dee56e142638b34f1eccbd0ad88c3bce5377c29 /deps/v8/test/mjsunit/basic-promise.js | |
parent | 91a1bbe3055a660194ca4d403795aa0c03e9d056 (diff) | |
download | node-new-3dc8c3bed4cf3a77607edbb0b015e33f8b60fc09.tar.gz |
deps: update V8 to 5.9.211.32
PR-URL: https://github.com/nodejs/node/pull/13263
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/v8/test/mjsunit/basic-promise.js')
-rw-r--r-- | deps/v8/test/mjsunit/basic-promise.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/deps/v8/test/mjsunit/basic-promise.js b/deps/v8/test/mjsunit/basic-promise.js new file mode 100644 index 0000000000..9905fa475f --- /dev/null +++ b/deps/v8/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 +})(); |