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

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

Issue 294943009: Allow microtasks to throw exceptions and handle them gracefully (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use existing Suppression scope Created 6 years, 7 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-api.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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( 351 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
352 isolate, TerminateCurrentThread, DoLoopCancelTerminate); 352 isolate, TerminateCurrentThread, DoLoopCancelTerminate);
353 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); 353 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global);
354 v8::Context::Scope context_scope(context); 354 v8::Context::Scope context_scope(context);
355 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); 355 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
356 v8::Handle<v8::String> source = v8::String::NewFromUtf8( 356 v8::Handle<v8::String> source = v8::String::NewFromUtf8(
357 isolate, "try { doloop(); } catch(e) { fail(); } 'completed';"); 357 isolate, "try { doloop(); } catch(e) { fail(); } 'completed';");
358 // Check that execution completed with correct return value. 358 // Check that execution completed with correct return value.
359 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); 359 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed")));
360 } 360 }
361
362
363 void MicrotaskShouldNotRun(const v8::FunctionCallbackInfo<v8::Value>& info) {
364 CHECK(false);
365 }
366
367
368 void MicrotaskLoopForever(const v8::FunctionCallbackInfo<v8::Value>& info) {
369 v8::Isolate* isolate = info.GetIsolate();
370 v8::HandleScope scope(isolate);
371 // Enqueue another should-not-run task to ensure we clean out the queue
372 // when we terminate.
373 isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun));
374 CompileRun("terminate(); while (true) { }");
375 CHECK(v8::V8::IsExecutionTerminating());
376 }
377
378
379 TEST(TerminateFromOtherThreadWhileMicrotaskRunning) {
380 semaphore = new v8::internal::Semaphore(0);
381 TerminatorThread thread(CcTest::i_isolate());
382 thread.Start();
383
384 v8::Isolate* isolate = CcTest::isolate();
385 isolate->SetAutorunMicrotasks(false);
386 v8::HandleScope scope(isolate);
387 v8::Handle<v8::ObjectTemplate> global =
388 CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop);
389 v8::Handle<v8::Context> context =
390 v8::Context::New(CcTest::isolate(), NULL, global);
391 v8::Context::Scope context_scope(context);
392 isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskLoopForever));
393 // The second task should never be run because we bail out if we're
394 // terminating.
395 isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun));
396 isolate->RunMicrotasks();
397
398 v8::V8::CancelTerminateExecution(isolate);
399 isolate->RunMicrotasks(); // should not run MicrotaskShouldNotRun
400
401 thread.Join();
402 delete semaphore;
403 semaphore = NULL;
404 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698