suppressed-error-handling-non-Error.js (1360B)
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 throwObject = { message: 'Hello world' }; 8 function testNonErrorObjectThrowsDuringDispose() { 9 using x = { 10 [Symbol.dispose]() { 11 disposed.push(1); 12 throw 1; 13 } 14 } 15 using y = { 16 [Symbol.dispose]() { 17 disposed.push(2); 18 throw "test"; 19 } 20 } 21 using z = { 22 [Symbol.dispose]() { 23 throw null; 24 } 25 } 26 27 throw throwObject; 28 } 29 30 assertSuppressionChain(testNonErrorObjectThrowsDuringDispose, [ 31 1, "test", null, throwObject 32 ]); 33 assertArrayEq(disposed, [2, 1]); 34 } 35 36 { 37 const disposed = []; 38 class SubError extends Error { 39 constructor(num) { 40 super(); 41 this.name = 'SubError'; 42 this.ident = num; 43 } 44 } 45 const errorsToThrow = [new SubError(1), new SubError(2)]; 46 function testCustomErrorObjectThrowsDuringDispose() { 47 using x = { 48 [Symbol.dispose]() { 49 disposed.push(1); 50 throw errorsToThrow[0]; 51 } 52 } 53 using y = { 54 [Symbol.dispose]() { 55 disposed.push(2); 56 throw errorsToThrow[1]; 57 } 58 } 59 } 60 assertSuppressionChain(testCustomErrorObjectThrowsDuringDispose, errorsToThrow); 61 assertArrayEq(disposed, [2, 1]); 62 }