Index: test/mjsunit/error-constructors.js |
diff --git a/test/mjsunit/error-constructors.js b/test/mjsunit/error-constructors.js |
index 0f3d74c960cfb04ad84be7919e5dca9eeab8338e..5c2aac5b8703cb421a69066465d437c6aae9254f 100644 |
--- a/test/mjsunit/error-constructors.js |
+++ b/test/mjsunit/error-constructors.js |
@@ -69,9 +69,11 @@ try { |
assertTrue(e.hasOwnProperty('stack')); |
// Check that intercepting property access from toString is prevented for |
-// compiler errors. This is not specified, but allowing interception |
-// through a getter can leak error objects from different |
-// script tags in the same context in a browser setting. |
+// compiler errors. This is not specified, but allowing interception through a |
+// getter can leak error objects from different script tags in the same context |
+// in a browser setting. Use Realm.eval as a proxy for loading scripts. We |
+// ignore the exception thrown from it since that would not be catchable from |
+// user-land code. |
var errors = [SyntaxError, ReferenceError, TypeError, RangeError, URIError]; |
var error_triggers = ["syntax error", |
"var error = reference", |
@@ -79,39 +81,12 @@ var error_triggers = ["syntax error", |
"String.fromCodePoint(0xFFFFFF)", |
"decodeURI('%F')"]; |
for (var i in errors) { |
- var name = errors[i].name; |
- |
// Monkey-patch prototype. |
- var props = ["name", "message", "stack"]; |
- for (var j in props) { |
- errors[i].prototype.__defineGetter__(props[j], fail); |
+ for (var prop of ["name", "message", "stack"]) { |
+ errors[i].prototype.__defineGetter__(prop, fail); |
} |
// String conversion should not invoke monkey-patched getters on prototype. |
- var error; |
- try { |
- eval(error_triggers[i]); |
- } catch (e) { |
- error = e; |
- } |
- assertTrue(error.toString().startsWith(name)); |
- |
- // Deleting message on the error (exposing the getter) is fine. |
- delete error.message; |
- assertEquals(name, error.toString()); |
- |
- // Custom properties shadowing the name are fine. |
- var myerror = { name: "myerror", message: "mymessage"}; |
- myerror.__proto__ = error; |
- assertEquals("myerror: mymessage", myerror.toString()); |
- |
- // Custom getters in actual objects are welcome. |
- error.__defineGetter__("name", function() { return "mine"; }); |
- assertEquals("mine", error.toString()); |
- |
- // Custom properties shadowing the name are fine. |
- var myerror2 = { message: "mymessage"}; |
- myerror2.__proto__ = error; |
- assertEquals("mine: mymessage", myerror2.toString()); |
+ assertThrows(()=>Realm.eval(0, error_triggers[i])); |
} |
// Monkey-patching non-internal errors should still be observable. |