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

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

Issue 11014017: Pass pending exception to the message listener. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 8 years, 2 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 | « src/messages.cc ('k') | 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 2396 matching lines...) Expand 10 before | Expand all | Expand 10 after
2407 CHECK(result.IsEmpty()); 2407 CHECK(result.IsEmpty());
2408 CHECK(try_catch.HasCaught()); 2408 CHECK(try_catch.HasCaught());
2409 String::AsciiValue exception_value(try_catch.Exception()); 2409 String::AsciiValue exception_value(try_catch.Exception());
2410 CHECK_EQ(*exception_value, "panama!"); 2410 CHECK_EQ(*exception_value, "panama!");
2411 } 2411 }
2412 2412
2413 2413
2414 bool message_received; 2414 bool message_received;
2415 2415
2416 2416
2417 static void check_message(v8::Handle<v8::Message> message, 2417 static void check_message_0(v8::Handle<v8::Message> message,
2418 v8::Handle<Value> data) { 2418 v8::Handle<Value> data) {
2419 CHECK_EQ(5.76, data->NumberValue());
2420 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); 2419 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
2421 CHECK_EQ(7.56, message->GetScriptData()->NumberValue()); 2420 CHECK_EQ(7.56, message->GetScriptData()->NumberValue());
2422 message_received = true; 2421 message_received = true;
2423 } 2422 }
2424 2423
2425 2424
2426 THREADED_TEST(MessageHandlerData) { 2425 THREADED_TEST(MessageHandler0) {
2427 message_received = false; 2426 message_received = false;
2428 v8::HandleScope scope; 2427 v8::HandleScope scope;
2429 CHECK(!message_received); 2428 CHECK(!message_received);
2430 v8::V8::AddMessageListener(check_message, v8_num(5.76)); 2429 v8::V8::AddMessageListener(check_message_0);
2431 LocalContext context; 2430 LocalContext context;
2432 v8::ScriptOrigin origin = 2431 v8::ScriptOrigin origin =
2433 v8::ScriptOrigin(v8_str("6.75")); 2432 v8::ScriptOrigin(v8_str("6.75"));
2434 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 2433 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
2435 &origin); 2434 &origin);
2436 script->SetData(v8_str("7.56")); 2435 script->SetData(v8_str("7.56"));
2437 script->Run(); 2436 script->Run();
2438 CHECK(message_received); 2437 CHECK(message_received);
2439 // clear out the message listener 2438 // clear out the message listener
2440 v8::V8::RemoveMessageListeners(check_message); 2439 v8::V8::RemoveMessageListeners(check_message_0);
2441 } 2440 }
2442 2441
2443 2442
2443 static void check_message_1(v8::Handle<v8::Message> message,
2444 v8::Handle<Value> data) {
2445 CHECK(data->IsNumber());
2446 CHECK_EQ(1337, data->Int32Value());
2447 message_received = true;
2448 }
2449
2450
2451 TEST(MessageHandler1) {
2452 message_received = false;
2453 v8::HandleScope scope;
2454 CHECK(!message_received);
2455 v8::V8::AddMessageListener(check_message_1);
2456 LocalContext context;
2457 CompileRun("throw 1337;");
2458 CHECK(message_received);
2459 // clear out the message listener
2460 v8::V8::RemoveMessageListeners(check_message_1);
2461 }
2462
2463
2464 static void check_message_2(v8::Handle<v8::Message> message,
2465 v8::Handle<Value> data) {
2466 LocalContext context;
2467 CHECK(data->IsObject());
2468 v8::Local<v8::Value> hidden_property =
2469 v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key"));
2470 CHECK(v8_str("hidden value")->Equals(hidden_property));
2471 message_received = true;
2472 }
2473
2474
2475 TEST(MessageHandler2) {
2476 message_received = false;
2477 v8::HandleScope scope;
2478 CHECK(!message_received);
2479 v8::V8::AddMessageListener(check_message_2);
2480 LocalContext context;
2481 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error"));
2482 v8::Object::Cast(*error)->SetHiddenValue(v8_str("hidden key"),
2483 v8_str("hidden value"));
2484 context->Global()->Set(v8_str("error"), error);
2485 CompileRun("throw error;");
2486 CHECK(message_received);
2487 // clear out the message listener
2488 v8::V8::RemoveMessageListeners(check_message_2);
2489 }
2490
2491
2444 THREADED_TEST(GetSetProperty) { 2492 THREADED_TEST(GetSetProperty) {
2445 v8::HandleScope scope; 2493 v8::HandleScope scope;
2446 LocalContext context; 2494 LocalContext context;
2447 context->Global()->Set(v8_str("foo"), v8_num(14)); 2495 context->Global()->Set(v8_str("foo"), v8_num(14));
2448 context->Global()->Set(v8_str("12"), v8_num(92)); 2496 context->Global()->Set(v8_str("12"), v8_num(92));
2449 context->Global()->Set(v8::Integer::New(16), v8_num(32)); 2497 context->Global()->Set(v8::Integer::New(16), v8_num(32));
2450 context->Global()->Set(v8_num(13), v8_num(56)); 2498 context->Global()->Set(v8_num(13), v8_num(56));
2451 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run(); 2499 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run();
2452 CHECK_EQ(14, foo->Int32Value()); 2500 CHECK_EQ(14, foo->Int32Value());
2453 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run(); 2501 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run();
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
3071 CompileRun("asdf;"); 3119 CompileRun("asdf;");
3072 CompileRun("ReferenceError.prototype = new Object();"); 3120 CompileRun("ReferenceError.prototype = new Object();");
3073 CompileRun("asdf;"); 3121 CompileRun("asdf;");
3074 v8::Handle<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }"); 3122 v8::Handle<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }");
3075 CHECK(string->Equals(v8_str("Whoops"))); 3123 CHECK(string->Equals(v8_str("Whoops")));
3076 CompileRun("ReferenceError.prototype.constructor = new Object();" 3124 CompileRun("ReferenceError.prototype.constructor = new Object();"
3077 "ReferenceError.prototype.constructor.name = 1;" 3125 "ReferenceError.prototype.constructor.name = 1;"
3078 "Number.prototype.toString = function() { return 'Whoops'; };" 3126 "Number.prototype.toString = function() { return 'Whoops'; };"
3079 "ReferenceError.prototype.toString = Object.prototype.toString;"); 3127 "ReferenceError.prototype.toString = Object.prototype.toString;");
3080 CompileRun("asdf;"); 3128 CompileRun("asdf;");
3081 v8::V8::RemoveMessageListeners(check_message); 3129 v8::V8::RemoveMessageListeners(check_reference_error_message);
3082 } 3130 }
3083 3131
3084 3132
3085 static void check_custom_error_message( 3133 static void check_custom_error_message(
3086 v8::Handle<v8::Message> message, 3134 v8::Handle<v8::Message> message,
3087 v8::Handle<v8::Value> data) { 3135 v8::Handle<v8::Value> data) {
3088 const char* uncaught_error = "Uncaught MyError toString"; 3136 const char* uncaught_error = "Uncaught MyError toString";
3089 CHECK(message->Get()->Equals(v8_str(uncaught_error))); 3137 CHECK(message->Get()->Equals(v8_str(uncaught_error)));
3090 } 3138 }
3091 3139
(...skipping 26 matching lines...) Expand all
3118 TEST(APIThrowMessage) { 3166 TEST(APIThrowMessage) {
3119 message_received = false; 3167 message_received = false;
3120 v8::HandleScope scope; 3168 v8::HandleScope scope;
3121 v8::V8::AddMessageListener(receive_message); 3169 v8::V8::AddMessageListener(receive_message);
3122 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3170 Local<ObjectTemplate> templ = ObjectTemplate::New();
3123 templ->Set(v8_str("ThrowFromC"), 3171 templ->Set(v8_str("ThrowFromC"),
3124 v8::FunctionTemplate::New(ThrowFromC)); 3172 v8::FunctionTemplate::New(ThrowFromC));
3125 LocalContext context(0, templ); 3173 LocalContext context(0, templ);
3126 CompileRun("ThrowFromC();"); 3174 CompileRun("ThrowFromC();");
3127 CHECK(message_received); 3175 CHECK(message_received);
3128 v8::V8::RemoveMessageListeners(check_message); 3176 v8::V8::RemoveMessageListeners(receive_message);
3129 } 3177 }
3130 3178
3131 3179
3132 TEST(APIThrowMessageAndVerboseTryCatch) { 3180 TEST(APIThrowMessageAndVerboseTryCatch) {
3133 message_received = false; 3181 message_received = false;
3134 v8::HandleScope scope; 3182 v8::HandleScope scope;
3135 v8::V8::AddMessageListener(receive_message); 3183 v8::V8::AddMessageListener(receive_message);
3136 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3184 Local<ObjectTemplate> templ = ObjectTemplate::New();
3137 templ->Set(v8_str("ThrowFromC"), 3185 templ->Set(v8_str("ThrowFromC"),
3138 v8::FunctionTemplate::New(ThrowFromC)); 3186 v8::FunctionTemplate::New(ThrowFromC));
3139 LocalContext context(0, templ); 3187 LocalContext context(0, templ);
3140 v8::TryCatch try_catch; 3188 v8::TryCatch try_catch;
3141 try_catch.SetVerbose(true); 3189 try_catch.SetVerbose(true);
3142 Local<Value> result = CompileRun("ThrowFromC();"); 3190 Local<Value> result = CompileRun("ThrowFromC();");
3143 CHECK(try_catch.HasCaught()); 3191 CHECK(try_catch.HasCaught());
3144 CHECK(result.IsEmpty()); 3192 CHECK(result.IsEmpty());
3145 CHECK(message_received); 3193 CHECK(message_received);
3146 v8::V8::RemoveMessageListeners(check_message); 3194 v8::V8::RemoveMessageListeners(receive_message);
3147 } 3195 }
3148 3196
3149 3197
3150 TEST(APIStackOverflowAndVerboseTryCatch) { 3198 TEST(APIStackOverflowAndVerboseTryCatch) {
3151 message_received = false; 3199 message_received = false;
3152 v8::HandleScope scope; 3200 v8::HandleScope scope;
3153 v8::V8::AddMessageListener(receive_message); 3201 v8::V8::AddMessageListener(receive_message);
3154 LocalContext context; 3202 LocalContext context;
3155 v8::TryCatch try_catch; 3203 v8::TryCatch try_catch;
3156 try_catch.SetVerbose(true); 3204 try_catch.SetVerbose(true);
(...skipping 1944 matching lines...) Expand 10 before | Expand all | Expand 10 after
5101 Script::Compile(String::New(js_code_causing_huge_string_flattening)); 5149 Script::Compile(String::New(js_code_causing_huge_string_flattening));
5102 last_location = NULL; 5150 last_location = NULL;
5103 script->Run(); 5151 script->Run();
5104 5152
5105 CHECK(false); // Should not return. 5153 CHECK(false); // Should not return.
5106 } 5154 }
5107 5155
5108 5156
5109 static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message, 5157 static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message,
5110 v8::Handle<Value> data) { 5158 v8::Handle<Value> data) {
5111 CHECK_EQ(v8::Undefined(), data);
5112 CHECK(message->GetScriptResourceName()->IsUndefined()); 5159 CHECK(message->GetScriptResourceName()->IsUndefined());
5113 CHECK_EQ(v8::Undefined(), message->GetScriptResourceName()); 5160 CHECK_EQ(v8::Undefined(), message->GetScriptResourceName());
5114 message->GetLineNumber(); 5161 message->GetLineNumber();
5115 message->GetSourceLine(); 5162 message->GetSourceLine();
5116 } 5163 }
5117 5164
5118 5165
5119 THREADED_TEST(ErrorWithMissingScriptInfo) { 5166 THREADED_TEST(ErrorWithMissingScriptInfo) {
5120 v8::HandleScope scope; 5167 v8::HandleScope scope;
5121 LocalContext context; 5168 LocalContext context;
(...skipping 12501 matching lines...) Expand 10 before | Expand all | Expand 10 after
17623 17670
17624 i::Semaphore* sem_; 17671 i::Semaphore* sem_;
17625 volatile int sem_value_; 17672 volatile int sem_value_;
17626 }; 17673 };
17627 17674
17628 17675
17629 THREADED_TEST(SemaphoreInterruption) { 17676 THREADED_TEST(SemaphoreInterruption) {
17630 ThreadInterruptTest().RunTest(); 17677 ThreadInterruptTest().RunTest();
17631 } 17678 }
17632 #endif // WIN32 17679 #endif // WIN32
OLDNEW
« no previous file with comments | « src/messages.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698