error-cause-copied.js (1066B)
1 // Test that the ErrorCopier copies the optional "cause" property of error objects. 2 3 let g = newGlobal({newCompartment: true}); 4 let dbg = new Debugger(g); 5 let hits = 0; 6 dbg.onDebuggerStatement = function (frame) { 7 hits++; 8 9 // Use |getVariable()| so we can easily throw our custom error from the 10 // with-statement scope. 11 let caught; 12 try { 13 frame.environment.getVariable("x"); 14 } catch (e) { 15 caught = e; 16 } 17 18 // The ErrorCopier copied error, so |caught| isn't equal to |g.error|. 19 assertEq(caught !== g.error, true); 20 21 // Ensure the "cause" property is correctly copied. 22 assertEq(caught.cause, g.cause); 23 }; 24 25 // The error must be same-compartment with the debugger compartment for the 26 // ErrorCopier. 27 g.eval(` 28 var cause = new Object(); 29 var error = new Error("", {cause}); 30 `); 31 32 // Scope must be outside of debugger compartment to avoid triggering a 33 // DebuggeeWouldRun error. 34 let scope = { 35 get x() { 36 throw g.error; 37 } 38 }; 39 40 g.eval(` 41 function f(scope) { 42 with (scope) { 43 debugger; 44 } 45 } 46 `); 47 48 g.f(scope); 49 50 assertEq(hits, 1);