v8/test/mjsunit/basic-promise.js
Mircea Trofin 619dfed4f7 Revert "Reland "Introducing an event loop mechanism for d8.""
This reverts commit 45bbf8041d.

Reason for revert: Still some flakes.

Original change's description:
> Reland "Introducing an event loop mechanism for d8."
> 
> This reverts commit 02595c60a3.
> 
> Original CL: https://chromium-review.googlesource.com/c/494968/
> 
> Bug: 
> Change-Id: I7441ed91ebb4a087cdf437ae3239f9b021110a11
> Reviewed-on: https://chromium-review.googlesource.com/500947
> Reviewed-by: Bill Budge <bbudge@chromium.org>
> Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#45212}

TBR=bradnelson@chromium.org,bbudge@chromium.org,mtrofin@chromium.org,jochen@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Bug: 
Change-Id: Idf2ea0431865104042a68bd2dac944a9725bf3f9
Reviewed-on: https://chromium-review.googlesource.com/501370
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45215}
2017-05-10 04:50:19 +00:00

51 lines
1.4 KiB
JavaScript

// 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
})();