Revision: 12151 Author: [email protected] Date: Fri Jul 20 01:03:46 2012 Log: Add test case for custom error's toString.
[email protected] BUG= TEST=error-tostring.js Review URL: https://chromiumcodereview.appspot.com/10388208 http://code.google.com/p/v8/source/detail?r=12151 Modified: /branches/bleeding_edge/test/cctest/test-api.cc ======================================= --- /branches/bleeding_edge/test/cctest/test-api.cc Tue Jul 17 09:00:00 2012 +++ /branches/bleeding_edge/test/cctest/test-api.cc Fri Jul 20 01:03:46 2012 @@ -3055,6 +3055,32 @@ CompileRun("asdf;"); v8::V8::RemoveMessageListeners(check_message); } + + +static void check_custom_error_message( + v8::Handle<v8::Message> message, + v8::Handle<v8::Value> data) { + const char* uncaught_error = "Uncaught MyError toString"; + CHECK(message->Get()->Equals(v8_str(uncaught_error))); +} + + +TEST(CustomErrorToString) { + v8::HandleScope scope; + v8::V8::AddMessageListener(check_custom_error_message); + LocalContext context; + CompileRun( + "function MyError(name, message) { " + " this.name = name; " + " this.message = message; " + "} " + "MyError.prototype = Object.create(Error.prototype); " + "MyError.prototype.toString = function() { " + " return 'MyError toString'; " + "}; " + "throw new MyError('my name', 'my message'); "); + v8::V8::RemoveMessageListeners(check_custom_error_message); +} static void receive_message(v8::Handle<v8::Message> message, -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev
