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

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

Issue 359723005: Add mechanism to postpone interrupts selectively. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | « src/isolate.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 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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun)); 396 isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun));
397 isolate->RunMicrotasks(); 397 isolate->RunMicrotasks();
398 398
399 v8::V8::CancelTerminateExecution(isolate); 399 v8::V8::CancelTerminateExecution(isolate);
400 isolate->RunMicrotasks(); // should not run MicrotaskShouldNotRun 400 isolate->RunMicrotasks(); // should not run MicrotaskShouldNotRun
401 401
402 thread.Join(); 402 thread.Join();
403 delete semaphore; 403 delete semaphore;
404 semaphore = NULL; 404 semaphore = NULL;
405 } 405 }
406
407
408 static int callback_counter = 0;
409
410
411 static void CounterCallback(v8::Isolate* isolate, void* data) {
412 callback_counter++;
413 }
414
415
416 TEST(PostponeTerminateException) {
417 v8::Isolate* isolate = CcTest::isolate();
418 v8::HandleScope scope(isolate);
419 v8::Handle<v8::ObjectTemplate> global =
420 CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop);
421 v8::Handle<v8::Context> context =
422 v8::Context::New(CcTest::isolate(), NULL, global);
423 v8::Context::Scope context_scope(context);
424
425 v8::TryCatch try_catch;
426 static const char* terminate_and_loop =
427 "terminate(); for (var i = 0; i < 10000; i++);";
428
429 { // Postpone terminate execution interrupts.
430 i::PostponeInterruptsScope p1(CcTest::i_isolate(),
431 i::StackGuard::TERMINATE_EXECUTION) ;
432
433 // API interrupts should still be triggered.
434 CcTest::isolate()->RequestInterrupt(&CounterCallback, NULL);
435 CHECK_EQ(0, callback_counter);
436 CompileRun(terminate_and_loop);
437 CHECK(!try_catch.HasTerminated());
438 CHECK_EQ(1, callback_counter);
439
440 { // Postpone API interrupts as well.
441 i::PostponeInterruptsScope p2(CcTest::i_isolate(),
442 i::StackGuard::API_INTERRUPT);
443
444 // None of the two interrupts should trigger.
445 CcTest::isolate()->RequestInterrupt(&CounterCallback, NULL);
446 CompileRun(terminate_and_loop);
447 CHECK(!try_catch.HasTerminated());
448 CHECK_EQ(1, callback_counter);
449 }
450
451 // Now the previously requested API interrupt should trigger.
452 CompileRun(terminate_and_loop);
453 CHECK(!try_catch.HasTerminated());
454 CHECK_EQ(2, callback_counter);
455 }
456
457 // Now the previously requested terminate execution interrupt should trigger.
458 CompileRun("for (var i = 0; i < 10000; i++);");
459 CHECK(try_catch.HasTerminated());
460 CHECK_EQ(2, callback_counter);
461 }
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698