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

Side by Side Diff: test/cctest/test-api.cc

Issue 10388208: Add test case for custom error's toString. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 3038 matching lines...) Expand 10 before | Expand all | Expand 10 after
3049 CHECK(string->Equals(v8_str("Whoops"))); 3049 CHECK(string->Equals(v8_str("Whoops")));
3050 CompileRun("ReferenceError.prototype.constructor = new Object();" 3050 CompileRun("ReferenceError.prototype.constructor = new Object();"
3051 "ReferenceError.prototype.constructor.name = 1;" 3051 "ReferenceError.prototype.constructor.name = 1;"
3052 "Number.prototype.toString = function() { return 'Whoops'; };" 3052 "Number.prototype.toString = function() { return 'Whoops'; };"
3053 "ReferenceError.prototype.toString = Object.prototype.toString;"); 3053 "ReferenceError.prototype.toString = Object.prototype.toString;");
3054 CompileRun("asdf;"); 3054 CompileRun("asdf;");
3055 v8::V8::RemoveMessageListeners(check_message); 3055 v8::V8::RemoveMessageListeners(check_message);
3056 } 3056 }
3057 3057
3058 3058
3059 static void check_custom_error_message(
3060 v8::Handle<v8::Message> message,
3061 v8::Handle<v8::Value> data) {
3062 const char* uncaught_error = "Uncaught MyError toString";
3063 CHECK(message->Get()->Equals(v8_str(uncaught_error)));
3064 }
3065
3066
3067 TEST(CustomErrorToString) {
3068 v8::HandleScope scope;
3069 v8::V8::AddMessageListener(check_custom_error_message);
3070 LocalContext context;
3071 CompileRun(
3072 "function MyError(name, message) { "
3073 " this.name = name; "
3074 " this.message = message; "
3075 "} "
3076 "MyError.prototype = Object.create(Error.prototype); "
3077 "MyError.prototype.toString = function() { "
3078 " return 'MyError toString'; "
3079 "}; "
3080 "throw new MyError('my name', 'my message'); ");
3081 v8::V8::RemoveMessageListeners(check_custom_error_message);
3082 }
3083
3084
3059 static void receive_message(v8::Handle<v8::Message> message, 3085 static void receive_message(v8::Handle<v8::Message> message,
3060 v8::Handle<v8::Value> data) { 3086 v8::Handle<v8::Value> data) {
3061 message->Get(); 3087 message->Get();
3062 message_received = true; 3088 message_received = true;
3063 } 3089 }
3064 3090
3065 3091
3066 TEST(APIThrowMessage) { 3092 TEST(APIThrowMessage) {
3067 message_received = false; 3093 message_received = false;
3068 v8::HandleScope scope; 3094 v8::HandleScope scope;
(...skipping 13759 matching lines...) Expand 10 before | Expand all | Expand 10 after
16828 " x++; \n" 16854 " x++; \n"
16829 " throw new Error('again'); \n" // This is the new uncaught error. 16855 " throw new Error('again'); \n" // This is the new uncaught error.
16830 "} \n"; 16856 "} \n";
16831 CompileRun(throw_again); 16857 CompileRun(throw_again);
16832 CHECK(try_catch.HasCaught()); 16858 CHECK(try_catch.HasCaught());
16833 Local<Message> message = try_catch.Message(); 16859 Local<Message> message = try_catch.Message();
16834 CHECK(!message.IsEmpty()); 16860 CHECK(!message.IsEmpty());
16835 CHECK_EQ(6, message->GetLineNumber()); 16861 CHECK_EQ(6, message->GetLineNumber());
16836 } 16862 }
16837 } 16863 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698