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

Unified Diff: test/cctest/test-api.cc

Issue 21761002: Improve internal stringifcation for custom Error objects. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: GetDataProperty. Created 7 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/messages.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 511a9440b2c83172b61516ed6fb5121667dbdc6f..664f905105e7ca0a1f708c58d68eef22e5265bec 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -4388,7 +4388,7 @@ TEST(APIThrowMessageOverwrittenToString) {
}
-static void check_custom_error_message(
+static void check_custom_error_tostring(
v8::Handle<v8::Message> message,
v8::Handle<v8::Value> data) {
const char* uncaught_error = "Uncaught MyError toString";
@@ -4399,7 +4399,7 @@ static void check_custom_error_message(
TEST(CustomErrorToString) {
LocalContext context;
v8::HandleScope scope(context->GetIsolate());
- v8::V8::AddMessageListener(check_custom_error_message);
+ v8::V8::AddMessageListener(check_custom_error_tostring);
CompileRun(
"function MyError(name, message) { "
" this.name = name; "
@@ -4410,6 +4410,58 @@ TEST(CustomErrorToString) {
" return 'MyError toString'; "
"}; "
"throw new MyError('my name', 'my message'); ");
+ v8::V8::RemoveMessageListeners(check_custom_error_tostring);
+}
+
+
+static void check_custom_error_message(
+ v8::Handle<v8::Message> message,
+ v8::Handle<v8::Value> data) {
+ const char* uncaught_error = "Uncaught MyError: my message";
+ printf("%s\n", *v8::String::Utf8Value(message->Get()));
+ CHECK(message->Get()->Equals(v8_str(uncaught_error)));
+}
+
+
+TEST(CustomErrorMessage) {
+ LocalContext context;
+ v8::HandleScope scope(context->GetIsolate());
+ v8::V8::AddMessageListener(check_custom_error_message);
+
+ // Handlebars.
+ CompileRun(
+ "function MyError(msg) { "
+ " this.name = 'MyError'; "
+ " this.message = msg; "
+ "} "
+ "MyError.prototype = new Error(); "
+ "throw new MyError('my message'); ");
+
+ // Closure.
+ CompileRun(
+ "function MyError(msg) { "
+ " this.name = 'MyError'; "
+ " this.message = msg; "
+ "} "
+ "inherits = function(childCtor, parentCtor) { "
+ " function tempCtor() {}; "
+ " tempCtor.prototype = parentCtor.prototype; "
+ " childCtor.superClass_ = parentCtor.prototype; "
+ " childCtor.prototype = new tempCtor(); "
+ " childCtor.prototype.constructor = childCtor; "
+ "}; "
+ "inherits(MyError, Error); "
+ "throw new MyError('my message'); ");
+
+ // Object.create.
+ CompileRun(
+ "function MyError(msg) { "
+ " this.name = 'MyError'; "
+ " this.message = msg; "
+ "} "
+ "MyError.prototype = Object.create(Error.prototype); "
+ "throw new MyError('my message'); ");
+
v8::V8::RemoveMessageListeners(check_custom_error_message);
}
« no previous file with comments | « src/messages.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698