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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); | 373 context.Dispose(); |
374 } | 374 } |
375 | 375 |
376 | |
377 v8::Handle<v8::Value> DoLoopResume(const v8::Arguments& args) { | |
378 v8::TryCatch try_catch; | |
379 CHECK(!v8::V8::IsExecutionTerminating()); | |
380 v8::Script::Compile(v8::String::New("var term = true;" | |
381 "while(true) {" | |
382 " if (term) terminate();" | |
383 " term = false;" | |
384 "}"))->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::ResumeExecution(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(TerminateResumeFromThreadItself) { | |
399 v8::HandleScope scope; | |
400 v8::Handle<v8::ObjectTemplate> global = | |
401 CreateGlobalTemplate(TerminateCurrentThread, DoLoopResume); | |
402 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global); | |
403 v8::Context::Scope context_scope(context); | |
404 CHECK(!v8::V8::IsExecutionTerminating()); | |
405 // Run a loop that will be infinite if thread termination does not work. | |
406 v8::Handle<v8::String> source = | |
407 v8::String::New("try { doloop(); } catch(e) { fail(); }"); | |
408 v8::Script::Compile(source)->Run(); | |
409 // Test that we can run the code again after thread termination. | |
410 CHECK(!v8::V8::IsExecutionTerminating()); | |
411 v8::Script::Compile(source)->Run(); | |
412 context.Dispose(); | |
413 } | |
OLD | NEW |