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 | 5 // Flags: --harmony-async-await |
6 | 6 |
7 async function test(func, funcs) { | 7 async function test(func, funcs) { |
8 try { | 8 try { |
9 await func(); | 9 await func(); |
10 throw new Error("Expected " + func.toString() + " to throw"); | 10 throw new Error("Expected " + func.toString() + " to throw"); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 await test((new class { async c3() { | 76 await test((new class { async c3() { |
77 await 1; | 77 await 1; |
78 try { await thrower(); } catch (e) { throw new Error("FAIL"); } | 78 try { await thrower(); } catch (e) { throw new Error("FAIL"); } |
79 } }).c3, ["c3"]); | 79 } }).c3, ["c3"]); |
80 | 80 |
81 await test((new class { async c4() { | 81 await test((new class { async c4() { |
82 await 1; | 82 await 1; |
83 try { await reject(); } catch (e) { throw new Error("FAIL"); } | 83 try { await reject(); } catch (e) { throw new Error("FAIL"); } |
84 } }).c4, ["c4"]); | 84 } }).c4, ["c4"]); |
85 | 85 |
86 // TODO(caitp): `async` probably shouldn't be the inferred name for async | 86 // TODO(caitp): We should infer anonymous async functions as the empty |
87 // arrow functions... | 87 // string, not as the name of a function they're passed as a parameter to. |
88 await test(async() => { throw new Error("FAIL") }, | 88 await test(async() => { throw new Error("FAIL") }, |
89 ["async", "test", "runTests"]); | 89 ["test", "test", "runTests"]); |
90 | 90 |
91 await test(async() => { await 1; throw new Error("FAIL") }, ["async"]); | 91 await test(async x => { await 1; throw new Error("FAIL") }, ["test"]); |
92 | 92 |
93 await test(async() => { | 93 await test(async() => { |
94 await 1; | 94 await 1; |
95 try { | 95 try { |
96 await thrower(); | 96 await thrower(); |
97 } catch (e) { | 97 } catch (e) { |
98 throw new Error("FAIL"); | 98 throw new Error("FAIL"); |
99 } | 99 } |
100 }, ["async"]); | 100 }, ["test"]); |
101 | 101 |
102 await test(async() => { | 102 await test(async() => { |
103 await 1; | 103 await 1; |
104 try { | 104 try { |
105 await reject(); | 105 await reject(); |
106 } catch (e) { | 106 } catch (e) { |
107 throw new Error("FAIL"); | 107 throw new Error("FAIL"); |
108 } | 108 } |
109 }, ["async"]); | 109 }, ["test"]); |
Dan Ehrenberg
2016/08/12 00:39:21
Maybe add a test to show that async functions with
| |
110 } | 110 } |
111 | 111 |
112 runTests().catch(e => { | 112 runTests().catch(e => { |
113 print(e); | 113 print(e); |
114 quit(1); | 114 quit(1); |
115 }); | 115 }); |
OLD | NEW |