disposal-handling-undefined-null-as-errors.js (1480B)
1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management 2 3 load(libdir + "asserts.js"); 4 5 { 6 const disposed = []; 7 const errorsToThrow = [undefined, null, 2]; 8 function testThrowsWithUndefinedAndNullValues() { 9 using a = { 10 [Symbol.dispose]() { 11 disposed.push(1); 12 throw errorsToThrow[0]; 13 } 14 } 15 16 using b = { 17 [Symbol.dispose]() { 18 disposed.push(2); 19 throw errorsToThrow[1]; 20 } 21 } 22 23 using c = { 24 [Symbol.dispose]() { 25 disposed.push(3); 26 throw errorsToThrow[2]; 27 } 28 } 29 } 30 assertSuppressionChain(testThrowsWithUndefinedAndNullValues, errorsToThrow); 31 assertArrayEq(disposed, [3, 2, 1]); 32 } 33 34 { 35 const disposed = []; 36 const errorsToThrow = [2, undefined]; 37 function testThrowsWithUndefinedAndRealValue() { 38 using a = { 39 [Symbol.dispose]() { 40 disposed.push(1); 41 throw errorsToThrow[0]; 42 } 43 } 44 45 throw errorsToThrow[1]; 46 } 47 assertSuppressionChain(testThrowsWithUndefinedAndRealValue, errorsToThrow); 48 assertArrayEq(disposed, [1]); 49 } 50 51 { 52 const disposed = []; 53 const errorsToThrow = [2, null]; 54 function testThrowsWithNullAndRealValue() { 55 using a = { 56 [Symbol.dispose]() { 57 disposed.push(1); 58 throw errorsToThrow[0]; 59 } 60 } 61 62 throw errorsToThrow[1]; 63 } 64 assertSuppressionChain(testThrowsWithNullAndRealValue, errorsToThrow); 65 assertArrayEq(disposed, [1]); 66 }