OLD | NEW |
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 Loading... |
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 "}" |
| 384 "fail();"))->Run(); |
| 385 CHECK(try_catch.HasCaught()); |
| 386 CHECK(try_catch.Exception()->IsNull()); |
| 387 CHECK(try_catch.Message().IsEmpty()); |
| 388 CHECK(!try_catch.CanContinue()); |
| 389 CHECK(v8::V8::IsExecutionTerminating()); |
| 390 CHECK(try_catch.HasTerminated()); |
| 391 v8::V8::CancelTerminateExecution(v8::Isolate::GetCurrent()); |
| 392 CHECK(!v8::V8::IsExecutionTerminating()); |
| 393 return v8::Undefined(); |
| 394 } |
| 395 |
| 396 // Test that a single thread of JavaScript execution can terminate |
| 397 // itself and then resume execution. |
| 398 TEST(TerminateCancelTerminateFromThreadItself) { |
| 399 v8::HandleScope scope; |
| 400 v8::Handle<v8::ObjectTemplate> global = |
| 401 CreateGlobalTemplate(TerminateCurrentThread, DoLoopCancelTerminate); |
| 402 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global); |
| 403 v8::Context::Scope context_scope(context); |
| 404 CHECK(!v8::V8::IsExecutionTerminating()); |
| 405 v8::Handle<v8::String> source = |
| 406 v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';"); |
| 407 // Check that execution completed with correct return value. |
| 408 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); |
| 409 context.Dispose(context->GetIsolate()); |
| 410 } |
| 411 |
OLD | NEW |