blob: 9aff8c8f7de599961399559bfd5dcc676aa561ce [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 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// If a Promise's then method is overridden, that should be respected
8// even if the promise is already resolved. x's resolution function is
9// only called by Promise.resolve(); there shouldn't be a resolution
10// check before when calling x.then.
11
12
13// Async assert framework copied from mjsunit/es6/promises.js
14
15var asyncAssertsExpected = 0;
16
17function assertAsyncRan() { ++asyncAssertsExpected }
18
19function assertLater(f, name) {
20 assertFalse(f()); // should not be true synchronously
21 ++asyncAssertsExpected;
22 var iterations = 0;
23 function runAssertion() {
24 if (f()) {
25 print(name, "succeeded");
26 --asyncAssertsExpected;
27 } else if (iterations++ < 10) {
28 %EnqueueMicrotask(runAssertion);
29 } else {
30 %AbortJS(name + " FAILED!");
31 }
32 }
33 %EnqueueMicrotask(runAssertion);
34}
35
36function assertAsyncDone(iteration) {
37 var iteration = iteration || 0;
38 %EnqueueMicrotask(function() {
39 if (asyncAssertsExpected === 0)
40 assertAsync(true, "all")
41 else if (iteration > 10) // Shouldn't take more.
42 assertAsync(false, "all... " + asyncAssertsExpected)
43 else
44 assertAsyncDone(iteration + 1)
45 });
46}
47
48// End async assert framework
49
50var y;
51var x = Promise.resolve();
52x.then = () => { y = true; }
53Promise.resolve().then(() => x);
54assertLater(() => y === true, "y === true");
55
56assertAsyncDone();