ccw-errors.js (894B)
1 function test() { 2 "use strict"; 3 4 const g = newGlobal({newCompartment: true}); 5 Error.prototype.whence = "main global"; 6 g.eval("Error.prototype.whence = 'other global'"); 7 8 const obj = g.eval("[]"); 9 Object.freeze(obj); 10 try { 11 obj.foo = 7; 12 assertEq("reached", "no", "This line should not be reached; the previous line should have thrown"); 13 } catch(e) { 14 assertEq("" + e, `TypeError: can't define property "foo": Array is not extensible`); 15 assertEq(e.whence, "main global"); // setting operation happens in this global 16 } 17 18 const obj2 = g.eval(`obj2 = { get x() { throw new Error("go away"); } };`); 19 try { 20 obj2.x; 21 assertEq("reached", "no", "This line should not be reached; the previous line should have thrown"); 22 } catch(e) { 23 assertEq("" + e, `Error: go away`); 24 assertEq(e.whence, "other global"); // Error created in other global 25 } 26 } 27 28 test();