throw-during-disposal-with-generators-doesnt-expose-magic-value.js (1010B)
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 values = []; 9 let caught = false; 10 function* gen() { 11 yield 1; 12 using a = { 13 [Symbol.dispose]() { 14 values.push("a"); 15 throw new CustomError(); 16 } 17 } 18 yield 2; 19 yield 3; 20 } 21 function testGeneratorDoesntExposeMagicValue() { 22 let it = gen(); 23 values.push(it.next().value); 24 values.push(it.next().value); 25 try { 26 values.push(it.return(40).value); 27 } catch (e) { 28 caught = true; 29 // The "generator closing" is represented as a throw completion with a magic value. 30 // The magic value shouldn't be captured as a suppressed error and exposed via the 31 // suppressed property. 32 assertEq(e instanceof CustomError, true); 33 } 34 } 35 testGeneratorDoesntExposeMagicValue(); 36 assertArrayEq(values, [1, 2, "a"]); 37 assertEq(caught, true); 38 }