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

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

Issue 11142013: Add methods to allow resuming execution after calling TerminateExecution(). (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 9 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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 CHECK(!v8::V8::IsExecutionTerminating()); 365 CHECK(!v8::V8::IsExecutionTerminating());
366 v8::Handle<v8::String> source = 366 v8::Handle<v8::String> source =
367 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 367 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
368 v8::Script::Compile(source)->Run(); 368 v8::Script::Compile(source)->Run();
369 CHECK(!v8::V8::IsExecutionTerminating()); 369 CHECK(!v8::V8::IsExecutionTerminating());
370 // Check we can run JS again after termination. 370 // Check we can run JS again after termination.
371 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }" 371 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }"
372 "f()"))->Run()->IsTrue()); 372 "f()"))->Run()->IsTrue());
373 context.Dispose(context->GetIsolate()); 373 context.Dispose(context->GetIsolate());
374 } 374 }
375
376 v8::Handle<v8::Value> DoLoopCancelTerminate(const v8::Arguments& args) {
377 v8::TryCatch try_catch;
378 CHECK(!v8::V8::IsExecutionTerminating());
379 v8::Script::Compile(v8::String::New("var term = true;"
380 "while(true) {"
381 " if (term) terminate();"
382 " term = false;"
383 "}"))->Run();
384 CHECK(try_catch.HasCaught());
385 CHECK(try_catch.Exception()->IsNull());
386 CHECK(try_catch.Message().IsEmpty());
387 CHECK(!try_catch.CanContinue());
388 CHECK(v8::V8::IsExecutionTerminating());
389 CHECK(try_catch.HasTerminated());
390 v8::V8::CancelTerminateExecution(v8::Isolate::GetCurrent());
391 CHECK(!v8::V8::IsExecutionTerminating());
Yang 2013/03/21 10:47:42 If you remove the two lines above, the test would
392 return v8::Undefined();
393 }
394
395 // Test that a single thread of JavaScript execution can terminate
396 // itself and then resume execution.
397 TEST(TerminateCancelTerminateFromThreadItself) {
398 v8::HandleScope scope;
399 v8::Handle<v8::ObjectTemplate> global =
400 CreateGlobalTemplate(TerminateCurrentThread, DoLoopCancelTerminate);
401 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
402 v8::Context::Scope context_scope(context);
403 CHECK(!v8::V8::IsExecutionTerminating());
404 // Run a loop that will be infinite if thread termination does not work.
405 v8::Handle<v8::String> source =
406 v8::String::New("try { doloop(); } catch(e) { fail(); }");
407 v8::Script::Compile(source)->Run();
408 // Test that we can run the code again after thread termination.
409 CHECK(!v8::V8::IsExecutionTerminating());
410 v8::Script::Compile(source)->Run();
Yang 2013/03/21 10:47:42 See above. What you want to test is that the scrip
411 context.Dispose(context->GetIsolate());
412 }
413
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