| 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 |  | 
| 6 |  | 
| 7 async function test(func, funcs) { |  | 
| 8   try { |  | 
| 9     await func(); |  | 
| 10     throw new Error("Expected " + func.toString() + " to throw"); |  | 
| 11   } catch (e) { |  | 
| 12     var stack = e.stack.split('\n'). |  | 
| 13         slice(1). |  | 
| 14         map(line => line.trim()). |  | 
| 15         map(line => line.match(/at (?:(.*) )?.*$/)[1]). |  | 
| 16         filter(x => typeof x === 'string' && x.length); |  | 
| 17 |  | 
| 18     assertEquals(funcs, stack, `Unexpected stack trace ${e.stack}`); |  | 
| 19   } |  | 
| 20 } |  | 
| 21 |  | 
| 22 function thrower() { throw new Error("NOPE"); } |  | 
| 23 function reject() { return Promise.reject(new Error("NOPE")); } |  | 
| 24 |  | 
| 25 async function runTests() { |  | 
| 26   await test(async function a() { |  | 
| 27     throw new Error("FAIL"); |  | 
| 28   }, |  | 
| 29   ["a", "test", "runTests"]); |  | 
| 30 |  | 
| 31   await test(async function a2() { |  | 
| 32     await 1; |  | 
| 33     throw new Error("FAIL"); |  | 
| 34   }, ["a2"]); |  | 
| 35 |  | 
| 36   await test(async function a3() { |  | 
| 37     await 1; |  | 
| 38     try { await thrower(); } catch (e) { throw new Error("FAIL"); } |  | 
| 39   }, ["a3"]); |  | 
| 40 |  | 
| 41   await test(async function a4() { |  | 
| 42     await 1; |  | 
| 43     try { await reject(); } catch (e) { throw new Error("FAIL"); } |  | 
| 44   }, ["a4"]); |  | 
| 45 |  | 
| 46   await test({ async b() { |  | 
| 47     throw new Error("FAIL"); |  | 
| 48   }}.b, |  | 
| 49   ["b", "test", "runTests"]); |  | 
| 50 |  | 
| 51   await test({ async b2() { |  | 
| 52     await 1; |  | 
| 53     throw new Error("FAIL"); |  | 
| 54   }}.b2, ["b2"]); |  | 
| 55 |  | 
| 56   await test({ async b3() { |  | 
| 57     await 1; |  | 
| 58     try { await thrower(); } catch (e) { throw new Error("FAIL"); } |  | 
| 59   } }.b3, ["b3"]); |  | 
| 60 |  | 
| 61   await test({ async b4() { |  | 
| 62     await 1; |  | 
| 63     try { await reject(); } catch (e) { throw new Error("FAIL"); } |  | 
| 64   } }.b4, ["b4"]); |  | 
| 65 |  | 
| 66   await test((new class { async c() { |  | 
| 67     throw new Error("FAIL"); |  | 
| 68   } }).c, |  | 
| 69   ["c", "test", "runTests"]); |  | 
| 70 |  | 
| 71   await test((new class { async c2() { |  | 
| 72     await 1; |  | 
| 73     throw new Error("FAIL"); |  | 
| 74   } }).c2, ["c2"]); |  | 
| 75 |  | 
| 76   await test((new class { async c3() { |  | 
| 77     await 1; |  | 
| 78     try { await thrower(); } catch (e) { throw new Error("FAIL"); } |  | 
| 79   } }).c3, ["c3"]); |  | 
| 80 |  | 
| 81   await test((new class { async c4() { |  | 
| 82     await 1; |  | 
| 83     try { await reject(); } catch (e) { throw new Error("FAIL"); } |  | 
| 84   } }).c4, ["c4"]); |  | 
| 85 |  | 
| 86   // TODO(caitp): We should infer anonymous async functions as the empty |  | 
| 87   // string, not as the name of a function they're passed as a parameter to. |  | 
| 88   await test(async x => { throw new Error("FAIL") }, |  | 
| 89              ["test", "test", "runTests"]); |  | 
| 90   await test(async() => { throw new Error("FAIL") }, |  | 
| 91              ["test", "test", "runTests"]); |  | 
| 92   await test(async(a) => { throw new Error("FAIL") }, |  | 
| 93              ["test", "test", "runTests"]); |  | 
| 94   await test(async(a, b) => { throw new Error("FAIL") }, |  | 
| 95              ["test", "test", "runTests"]); |  | 
| 96 |  | 
| 97   await test(async x => { await 1; throw new Error("FAIL") }, ["test"]); |  | 
| 98   await test(async() => { await 1; throw new Error("FAIL") }, ["test"]); |  | 
| 99   await test(async(a) => { await 1; throw new Error("FAIL") }, ["test"]); |  | 
| 100   await test(async(a, b) => { await 1; throw new Error("FAIL") }, ["test"]); |  | 
| 101 |  | 
| 102   await test(async x => { |  | 
| 103     await 1; |  | 
| 104     try { |  | 
| 105       await thrower(); |  | 
| 106     } catch (e) { |  | 
| 107       throw new Error("FAIL"); |  | 
| 108     } |  | 
| 109   }, ["test"]); |  | 
| 110 |  | 
| 111   await test(async() => { |  | 
| 112     await 1; |  | 
| 113     try { |  | 
| 114       await thrower(); |  | 
| 115     } catch (e) { |  | 
| 116       throw new Error("FAIL"); |  | 
| 117     } |  | 
| 118   }, ["test"]); |  | 
| 119 |  | 
| 120   await test(async(a) => { |  | 
| 121     await 1; |  | 
| 122     try { |  | 
| 123       await thrower(); |  | 
| 124     } catch (e) { |  | 
| 125       throw new Error("FAIL"); |  | 
| 126     } |  | 
| 127   }, ["test"]); |  | 
| 128 |  | 
| 129   await test(async(a, b) => { |  | 
| 130     await 1; |  | 
| 131     try { |  | 
| 132       await thrower(); |  | 
| 133     } catch (e) { |  | 
| 134       throw new Error("FAIL"); |  | 
| 135     } |  | 
| 136   }, ["test"]); |  | 
| 137 |  | 
| 138   await test(async x => { |  | 
| 139     await 1; |  | 
| 140     try { |  | 
| 141       await reject(); |  | 
| 142     } catch (e) { |  | 
| 143       throw new Error("FAIL"); |  | 
| 144     } |  | 
| 145   }, ["test"]); |  | 
| 146 |  | 
| 147   await test(async() => { |  | 
| 148     await 1; |  | 
| 149     try { |  | 
| 150       await reject(); |  | 
| 151     } catch (e) { |  | 
| 152       throw new Error("FAIL"); |  | 
| 153     } |  | 
| 154   }, ["test"]); |  | 
| 155 |  | 
| 156   await test(async(a) => { |  | 
| 157     await 1; |  | 
| 158     try { |  | 
| 159       await reject(); |  | 
| 160     } catch (e) { |  | 
| 161       throw new Error("FAIL"); |  | 
| 162     } |  | 
| 163   }, ["test"]); |  | 
| 164 |  | 
| 165   await test(async(a, b) => { |  | 
| 166     await 1; |  | 
| 167     try { |  | 
| 168       await reject(); |  | 
| 169     } catch (e) { |  | 
| 170       throw new Error("FAIL"); |  | 
| 171     } |  | 
| 172   }, ["test"]); |  | 
| 173 } |  | 
| 174 |  | 
| 175 runTests().catch(e => { |  | 
| 176   print(e); |  | 
| 177   quit(1); |  | 
| 178 }); |  | 
| OLD | NEW | 
|---|