disposal-during-throw-function.js (894B)
1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management 2 3 load(libdir + "asserts.js"); 4 5 const duringThrow = []; 6 function testDisposalDuringThrow() { 7 using a = { 8 value: "a", 9 [Symbol.dispose]() { 10 duringThrow.push(this.value); 11 } 12 }; 13 throw new Error("err 1"); 14 } 15 assertThrowsInstanceOf(testDisposalDuringThrow, Error); 16 assertArrayEq(duringThrow, ["a"]); 17 18 const duringBlockAndThrow = []; 19 function testDisposalDuringBlockAndThrow() { 20 using a = { 21 value: "a", 22 [Symbol.dispose]() { 23 duringBlockAndThrow.push(this.value); 24 } 25 }; 26 { 27 using b = { 28 value: "b", 29 [Symbol.dispose]() { 30 duringBlockAndThrow.push(this.value); 31 } 32 }; 33 throw new Error("err 2"); 34 } 35 } 36 assertThrowsInstanceOf(testDisposalDuringBlockAndThrow, Error); 37 assertArrayEq(duringBlockAndThrow, ["b", "a"]);