OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-async-await --allow-natives-syntax | 5 // Flags: --harmony-async-await --allow-natives-syntax |
6 | 6 |
7 function assertEqualsAsync(expected, run, msg) { | 7 function assertEqualsAsync(expected, run, msg) { |
8 var actual; | 8 var actual; |
9 var hadValue = false; | 9 var hadValue = false; |
10 var hadError = false; | 10 var hadError = false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 function getStack(error) { | 44 function getStack(error) { |
45 var stack = error.stack.split('\n'). | 45 var stack = error.stack.split('\n'). |
46 filter(function(line) { | 46 filter(function(line) { |
47 return /^\s*at @?[a-zA-Z0-9_]/.test(line); | 47 return /^\s*at @?[a-zA-Z0-9_]/.test(line); |
48 }). | 48 }). |
49 map(line => line.replace(/^\s*at (@?[a-zA-Z0-9_\.\[\]]+)(.*)/, "$1")); | 49 map(line => line.replace(/^\s*at (@?[a-zA-Z0-9_\.\[\]]+)(.*)/, "$1")); |
50 | 50 |
51 // remove `Promise.then()` invocation by assertEqualsAsync() | 51 // remove `Promise.then()` invocation by assertEqualsAsync() |
52 if (stack[1] === "assertEqualsAsync") return []; | 52 if (stack[2] === "assertEqualsAsync") return []; |
53 | 53 |
54 return stack.reverse(); | 54 return stack.reverse(); |
55 } | 55 } |
56 | 56 |
57 var log = []; | 57 var log = []; |
58 class FakePromise extends Promise { | 58 class FakePromise extends Promise { |
59 constructor(executor) { | 59 constructor(executor) { |
60 var stack = getStack(new Error("Getting Callstack")); | 60 var stack = getStack(new Error("Getting Callstack")); |
61 if (stack.length) { | 61 if (stack.length) { |
62 var first = -1; | 62 var first = -1; |
(...skipping 26 matching lines...) Expand all Loading... |
89 assertEquals([], log); | 89 assertEquals([], log); |
90 | 90 |
91 log.length = 0; | 91 log.length = 0; |
92 assertEqualsAsync( | 92 assertEqualsAsync( |
93 "foo", | 93 "foo", |
94 test(function testThenOnReturnedPromise() { | 94 test(function testThenOnReturnedPromise() { |
95 return asyncFn().then(x => (log.push("Then: " + x), x)); | 95 return asyncFn().then(x => (log.push("Then: " + x), x)); |
96 }), | 96 }), |
97 "should call Promise[@@Species] after non-internal Then"); | 97 "should call Promise[@@Species] after non-internal Then"); |
98 assertEquals([ | 98 assertEquals([ |
99 "@@Species: [@testThenOnReturnedPromise > FakePromise]", | 99 "@@Species: [@testThenOnReturnedPromise > Promise.then > FakePromise]", |
100 "Then: foo" | 100 "Then: foo" |
101 ], log); | 101 ], log); |
OLD | NEW |