disposal-errors-dont-get-caught-by-non-encl-try-catches.js (1220B)
1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management 2 3 load(libdir + "asserts.js"); 4 5 class CustomError extends Error {} 6 7 { 8 const disposed = []; 9 let catchCalled = false; 10 function testDisposalErrorIsNotCaughtByNonEnclosingTry() { 11 using x = { 12 [Symbol.dispose]() { 13 disposed.push('a'); 14 throw new CustomError("dispose error"); 15 } 16 } 17 18 try { 19 return; 20 } catch { 21 catchCalled = true; 22 } 23 } 24 assertThrowsInstanceOf(testDisposalErrorIsNotCaughtByNonEnclosingTry, CustomError); 25 assertArrayEq(disposed, ['a']); 26 assertEq(catchCalled, false); 27 } 28 29 { 30 const disposed = []; 31 let catchCalled = false; 32 function testDisposalErrorIsNotCaughtByNonEnclosingTryWhenLabelledBlocks() { 33 outer: { 34 using x = { 35 [Symbol.dispose]() { 36 disposed.push('a'); 37 throw new CustomError("dispose error"); 38 } 39 } 40 41 try { 42 break outer; 43 } catch { 44 catchCalled = true; 45 } 46 } 47 } 48 49 assertThrowsInstanceOf(testDisposalErrorIsNotCaughtByNonEnclosingTryWhenLabelledBlocks, CustomError); 50 assertArrayEq(disposed, ['a']); 51 assertEq(catchCalled, false); 52 }