Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Unified Diff: test/mjsunit/error-constructors.js

Issue 1281833002: Rewrite Error.prototype.toString in C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix test case Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | test/mjsunit/regress/regress-crbug-513472.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/error-constructors.js
diff --git a/test/mjsunit/error-constructors.js b/test/mjsunit/error-constructors.js
index 84c6bbfd0cf663b853c8c48d4c220cfd462b7dea..b18a3fed998c14b5764ab7d30f0e95f95c73903e 100644
--- a/test/mjsunit/error-constructors.js
+++ b/test/mjsunit/error-constructors.js
@@ -69,26 +69,53 @@ assertTrue(e.hasOwnProperty('stack'));
// 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.
-var errors = [SyntaxError, ReferenceError, TypeError];
+var errors = [SyntaxError, ReferenceError, TypeError, RangeError, URIError];
+var error_triggers = ["syntax error",
+ "var error = reference",
+ "undefined()",
+ "String.fromCodePoint(0xFFFFFF)",
+ "decodeURI('%F')"];
for (var i in errors) {
- var name = errors[i].prototype.toString();
+ 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);
}
// String conversion should not invoke monkey-patched getters on prototype.
- var e = new errors[i];
- assertEquals(name, e.toString());
+ 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.
- e.__defineGetter__("name", function() { return "mine"; });
- assertEquals("mine", e.toString());
+ 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());
}
-// Monkey-patching non-static errors should still be observable.
+// Monkey-patching non-internal errors should still be observable.
function MyError() {}
MyError.prototype = new Error;
-var errors = [Error, RangeError, EvalError, URIError, MyError];
+var errors = [Error, RangeError, EvalError, URIError,
+ SyntaxError, ReferenceError, TypeError, MyError];
for (var i in errors) {
errors[i].prototype.__defineGetter__("name", function() { return "my"; });
errors[i].prototype.__defineGetter__("message", function() { return "moo"; });
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | test/mjsunit/regress/regress-crbug-513472.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698