test-is-error.js (1042B)
1 // |jit-test| --enable-error-iserror 2 3 // Check if Error.isError is available 4 if (typeof Error.isError !== "function") { 5 quit(); 6 } 7 8 // Test non-object input should return false 9 assertEq(Error.isError(null), false); 10 assertEq(Error.isError(undefined), false); 11 assertEq(Error.isError(123), false); 12 assertEq(Error.isError("string"), false); 13 14 // Test plain objects should return false 15 assertEq(Error.isError({}), false); 16 assertEq(Error.isError(new Object()), false); 17 18 // Test various error objects should return true 19 assertEq(Error.isError(new Error()), true); 20 assertEq(Error.isError(new TypeError()), true); 21 assertEq(Error.isError(new RangeError()), true); 22 23 // Test cross-compartment wrapper (CCW) objects 24 const g = newGlobal({ newCompartment: true }); 25 const e = g.eval(`new Error()`); 26 assertEq(Error.isError(e), true); 27 28 nukeCCW(e); 29 30 // Test Error.isError for the nuked CCW object 31 let caught = false; 32 try { 33 Error.isError(e); 34 } catch (ex) { 35 caught = true; 36 assertEq(ex.message, "can't access dead object"); 37 } 38 assertEq(caught, true);