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

Side by Side Diff: test/cctest/test-thread-termination.cc

Issue 18509003: Keep two empty lines between declarations for cpp files (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 5 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 | « test/cctest/test-regexp.cc ('k') | test/cctest/test-threads.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 v8::Handle<v8::String> source = 315 v8::Handle<v8::String> source =
316 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 316 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
317 call_count = 0; 317 call_count = 0;
318 v8::Script::Compile(source)->Run(); 318 v8::Script::Compile(source)->Run();
319 // Test that we can run the code again after thread termination. 319 // Test that we can run the code again after thread termination.
320 CHECK(!v8::V8::IsExecutionTerminating()); 320 CHECK(!v8::V8::IsExecutionTerminating());
321 call_count = 0; 321 call_count = 0;
322 v8::Script::Compile(source)->Run(); 322 v8::Script::Compile(source)->Run();
323 } 323 }
324 324
325
325 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { 326 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) {
326 v8::TryCatch try_catch; 327 v8::TryCatch try_catch;
327 CHECK(!v8::V8::IsExecutionTerminating()); 328 CHECK(!v8::V8::IsExecutionTerminating());
328 v8::Script::Compile(v8::String::New("function f() {" 329 v8::Script::Compile(v8::String::New("function f() {"
329 " var term = true;" 330 " var term = true;"
330 " try {" 331 " try {"
331 " while(true) {" 332 " while(true) {"
332 " if (term) terminate();" 333 " if (term) terminate();"
333 " term = false;" 334 " term = false;"
334 " }" 335 " }"
335 " fail();" 336 " fail();"
336 " } catch(e) {" 337 " } catch(e) {"
337 " fail();" 338 " fail();"
338 " }" 339 " }"
339 "}" 340 "}"
340 "f()"))->Run(); 341 "f()"))->Run();
341 CHECK(try_catch.HasCaught()); 342 CHECK(try_catch.HasCaught());
342 CHECK(try_catch.Exception()->IsNull()); 343 CHECK(try_catch.Exception()->IsNull());
343 CHECK(try_catch.Message().IsEmpty()); 344 CHECK(try_catch.Message().IsEmpty());
344 CHECK(!try_catch.CanContinue()); 345 CHECK(!try_catch.CanContinue());
345 CHECK(v8::V8::IsExecutionTerminating()); 346 CHECK(v8::V8::IsExecutionTerminating());
346 v8::Script::Compile(v8::String::New("function f() { fail(); } f()"))->Run(); 347 v8::Script::Compile(v8::String::New("function f() { fail(); } f()"))->Run();
347 } 348 }
348 349
350
349 // Test that reentry into V8 while the termination exception is still pending 351 // Test that reentry into V8 while the termination exception is still pending
350 // (has not yet unwound the 0-level JS frame) does not crash. 352 // (has not yet unwound the 0-level JS frame) does not crash.
351 TEST(TerminateAndReenterFromThreadItself) { 353 TEST(TerminateAndReenterFromThreadItself) {
352 v8::HandleScope scope(v8::Isolate::GetCurrent()); 354 v8::HandleScope scope(v8::Isolate::GetCurrent());
353 v8::Handle<v8::ObjectTemplate> global = 355 v8::Handle<v8::ObjectTemplate> global =
354 CreateGlobalTemplate(TerminateCurrentThread, ReenterAfterTermination); 356 CreateGlobalTemplate(TerminateCurrentThread, ReenterAfterTermination);
355 v8::Handle<v8::Context> context = 357 v8::Handle<v8::Context> context =
356 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global); 358 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
357 v8::Context::Scope context_scope(context); 359 v8::Context::Scope context_scope(context);
358 CHECK(!v8::V8::IsExecutionTerminating()); 360 CHECK(!v8::V8::IsExecutionTerminating());
359 v8::Handle<v8::String> source = 361 v8::Handle<v8::String> source =
360 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 362 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
361 v8::Script::Compile(source)->Run(); 363 v8::Script::Compile(source)->Run();
362 CHECK(!v8::V8::IsExecutionTerminating()); 364 CHECK(!v8::V8::IsExecutionTerminating());
363 // Check we can run JS again after termination. 365 // Check we can run JS again after termination.
364 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }" 366 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }"
365 "f()"))->Run()->IsTrue()); 367 "f()"))->Run()->IsTrue());
366 } 368 }
367 369
370
368 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { 371 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
369 v8::TryCatch try_catch; 372 v8::TryCatch try_catch;
370 CHECK(!v8::V8::IsExecutionTerminating()); 373 CHECK(!v8::V8::IsExecutionTerminating());
371 v8::Script::Compile(v8::String::New("var term = true;" 374 v8::Script::Compile(v8::String::New("var term = true;"
372 "while(true) {" 375 "while(true) {"
373 " if (term) terminate();" 376 " if (term) terminate();"
374 " term = false;" 377 " term = false;"
375 "}" 378 "}"
376 "fail();"))->Run(); 379 "fail();"))->Run();
377 CHECK(try_catch.HasCaught()); 380 CHECK(try_catch.HasCaught());
378 CHECK(try_catch.Exception()->IsNull()); 381 CHECK(try_catch.Exception()->IsNull());
379 CHECK(try_catch.Message().IsEmpty()); 382 CHECK(try_catch.Message().IsEmpty());
380 CHECK(!try_catch.CanContinue()); 383 CHECK(!try_catch.CanContinue());
381 CHECK(v8::V8::IsExecutionTerminating()); 384 CHECK(v8::V8::IsExecutionTerminating());
382 CHECK(try_catch.HasTerminated()); 385 CHECK(try_catch.HasTerminated());
383 v8::V8::CancelTerminateExecution(v8::Isolate::GetCurrent()); 386 v8::V8::CancelTerminateExecution(v8::Isolate::GetCurrent());
384 CHECK(!v8::V8::IsExecutionTerminating()); 387 CHECK(!v8::V8::IsExecutionTerminating());
385 } 388 }
386 389
390
387 // Test that a single thread of JavaScript execution can terminate 391 // Test that a single thread of JavaScript execution can terminate
388 // itself and then resume execution. 392 // itself and then resume execution.
389 TEST(TerminateCancelTerminateFromThreadItself) { 393 TEST(TerminateCancelTerminateFromThreadItself) {
390 v8::HandleScope scope; 394 v8::HandleScope scope;
391 v8::Handle<v8::ObjectTemplate> global = 395 v8::Handle<v8::ObjectTemplate> global =
392 CreateGlobalTemplate(TerminateCurrentThread, DoLoopCancelTerminate); 396 CreateGlobalTemplate(TerminateCurrentThread, DoLoopCancelTerminate);
393 v8::Handle<v8::Context> context = 397 v8::Handle<v8::Context> context =
394 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global); 398 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
395 v8::Context::Scope context_scope(context); 399 v8::Context::Scope context_scope(context);
396 CHECK(!v8::V8::IsExecutionTerminating()); 400 CHECK(!v8::V8::IsExecutionTerminating());
397 v8::Handle<v8::String> source = 401 v8::Handle<v8::String> source =
398 v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';"); 402 v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';");
399 // Check that execution completed with correct return value. 403 // Check that execution completed with correct return value.
400 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); 404 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed")));
401 } 405 }
402 406
OLDNEW
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | test/cctest/test-threads.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698