asyncHelpers-throwsAsync-func-throws-sync.js (1253B)
1 // |reftest| async 2 // Copyright (C) 2022 Igalia, S.L. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 /*--- 5 description: | 6 assert.throwsAsync returns a promise that rejects if func or the inner thenable synchronously throws. 7 flags: [async] 8 includes: [asyncHelpers.js] 9 ---*/ 10 11 async function checkRejects(func) { 12 var caught = false; 13 const p = assert.throwsAsync(Test262Error, func); 14 assert(p instanceof Promise, "assert.throwsAsync should return a promise"); 15 try { 16 await p; 17 } catch (e) { 18 caught = true; 19 assert.sameValue( 20 e.constructor, 21 Test262Error, 22 "throwsAsync should reject improper function with a Test262Error" 23 ); 24 } finally { 25 assert( 26 caught, 27 "assert.throwsAsync did not reject improper function " + func 28 ); 29 } 30 } 31 32 asyncTest(async function () { 33 await checkRejects(function () { 34 throw new Error(); 35 }); 36 await checkRejects(function () { 37 throw new Test262Error(); 38 }); 39 await checkRejects(function () { 40 return { 41 then: function () { 42 throw new Error(); 43 }, 44 }; 45 }); 46 await checkRejects(function () { 47 return { 48 then: function () { 49 throw new Test262Error(); 50 }, 51 }; 52 }); 53 });