OLD | NEW |
| (Empty) |
1 // Copyright 2016 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: --harmony-async-await --allow-natives-syntax | |
6 | |
7 function assertEqualsAsync(expected, run, msg) { | |
8 var actual; | |
9 var hadValue = false; | |
10 var hadError = false; | |
11 var promise = run(); | |
12 | |
13 if (typeof promise !== "object" || typeof promise.then !== "function") { | |
14 throw new MjsUnitAssertionError( | |
15 "Expected " + run.toString() + | |
16 " to return a Promise, but it returned " + PrettyPrint(promise)); | |
17 } | |
18 | |
19 promise.then(function(value) { hadValue = true; actual = value; }, | |
20 function(error) { hadError = true; actual = error; }); | |
21 | |
22 assertFalse(hadValue || hadError); | |
23 | |
24 %RunMicrotasks(); | |
25 | |
26 if (hadError) throw actual; | |
27 | |
28 assertTrue( | |
29 hadValue, "Expected '" + run.toString() + "' to produce a value"); | |
30 | |
31 assertEquals(expected, actual, msg); | |
32 }; | |
33 | |
34 var O = { | |
35 [Symbol.toStringTag]: "LexicalThis", | |
36 run(n) { | |
37 return async passFail => `${n}. ${passFail}: ${this}`; | |
38 }, | |
39 }; | |
40 | |
41 assertEqualsAsync("1. PASS: [object LexicalThis]", () => O.run(1)("PASS")); | |
42 | |
43 var O2 = { | |
44 [Symbol.toStringTag]: "LexicalThis", | |
45 run: O.run(2) | |
46 }; | |
47 | |
48 assertEqualsAsync("2. PASS: [object LexicalThis]", () => O2.run("PASS")); | |
OLD | NEW |