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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 v8::HandleScope scope(CcTest::isolate()); | 145 v8::HandleScope scope(CcTest::isolate()); |
146 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( | 146 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( |
147 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); | 147 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); |
148 v8::Handle<v8::Context> context = | 148 v8::Handle<v8::Context> context = |
149 v8::Context::New(CcTest::isolate(), NULL, global); | 149 v8::Context::New(CcTest::isolate(), NULL, global); |
150 v8::Context::Scope context_scope(context); | 150 v8::Context::Scope context_scope(context); |
151 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 151 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
152 // Run a loop that will be infinite if thread termination does not work. | 152 // Run a loop that will be infinite if thread termination does not work. |
153 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 153 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
154 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); | 154 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); |
155 i::FLAG_turbo_osr = false; // TODO(titzer): interrupts in TF loops. | |
156 v8::Script::Compile(source)->Run(); | 155 v8::Script::Compile(source)->Run(); |
157 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 156 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
158 // Test that we can run the code again after thread termination. | 157 // Test that we can run the code again after thread termination. |
159 v8::Script::Compile(source)->Run(); | 158 v8::Script::Compile(source)->Run(); |
160 } | 159 } |
161 | 160 |
162 | 161 |
163 class TerminatorThread : public v8::base::Thread { | 162 class TerminatorThread : public v8::base::Thread { |
164 public: | 163 public: |
165 explicit TerminatorThread(i::Isolate* isolate) | 164 explicit TerminatorThread(i::Isolate* isolate) |
(...skipping 20 matching lines...) Expand all Loading... |
186 v8::HandleScope scope(CcTest::isolate()); | 185 v8::HandleScope scope(CcTest::isolate()); |
187 v8::Handle<v8::ObjectTemplate> global = | 186 v8::Handle<v8::ObjectTemplate> global = |
188 CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop); | 187 CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop); |
189 v8::Handle<v8::Context> context = | 188 v8::Handle<v8::Context> context = |
190 v8::Context::New(CcTest::isolate(), NULL, global); | 189 v8::Context::New(CcTest::isolate(), NULL, global); |
191 v8::Context::Scope context_scope(context); | 190 v8::Context::Scope context_scope(context); |
192 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 191 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
193 // Run a loop that will be infinite if thread termination does not work. | 192 // Run a loop that will be infinite if thread termination does not work. |
194 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 193 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
195 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); | 194 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); |
196 i::FLAG_turbo_osr = false; // TODO(titzer): interrupts in TF loops. | |
197 v8::Script::Compile(source)->Run(); | 195 v8::Script::Compile(source)->Run(); |
198 | 196 |
199 thread.Join(); | 197 thread.Join(); |
200 delete semaphore; | 198 delete semaphore; |
201 semaphore = NULL; | 199 semaphore = NULL; |
202 } | 200 } |
203 | 201 |
204 | 202 |
205 int call_count = 0; | 203 int call_count = 0; |
206 | 204 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 TEST(TerminateCancelTerminateFromThreadItself) { | 353 TEST(TerminateCancelTerminateFromThreadItself) { |
356 v8::Isolate* isolate = CcTest::isolate(); | 354 v8::Isolate* isolate = CcTest::isolate(); |
357 v8::HandleScope scope(isolate); | 355 v8::HandleScope scope(isolate); |
358 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( | 356 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( |
359 isolate, TerminateCurrentThread, DoLoopCancelTerminate); | 357 isolate, TerminateCurrentThread, DoLoopCancelTerminate); |
360 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); | 358 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); |
361 v8::Context::Scope context_scope(context); | 359 v8::Context::Scope context_scope(context); |
362 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 360 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
363 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 361 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
364 isolate, "try { doloop(); } catch(e) { fail(); } 'completed';"); | 362 isolate, "try { doloop(); } catch(e) { fail(); } 'completed';"); |
365 i::FLAG_turbo_osr = false; // TODO(titzer): interrupts in TF loops. | |
366 // Check that execution completed with correct return value. | 363 // Check that execution completed with correct return value. |
367 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); | 364 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); |
368 } | 365 } |
369 | 366 |
370 | 367 |
371 void MicrotaskShouldNotRun(const v8::FunctionCallbackInfo<v8::Value>& info) { | 368 void MicrotaskShouldNotRun(const v8::FunctionCallbackInfo<v8::Value>& info) { |
372 CHECK(false); | 369 CHECK(false); |
373 } | 370 } |
374 | 371 |
375 | 372 |
376 void MicrotaskLoopForever(const v8::FunctionCallbackInfo<v8::Value>& info) { | 373 void MicrotaskLoopForever(const v8::FunctionCallbackInfo<v8::Value>& info) { |
377 v8::Isolate* isolate = info.GetIsolate(); | 374 v8::Isolate* isolate = info.GetIsolate(); |
378 v8::HandleScope scope(isolate); | 375 v8::HandleScope scope(isolate); |
379 // Enqueue another should-not-run task to ensure we clean out the queue | 376 // Enqueue another should-not-run task to ensure we clean out the queue |
380 // when we terminate. | 377 // when we terminate. |
381 isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun)); | 378 isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun)); |
382 i::FLAG_turbo_osr = false; // TODO(titzer): interrupts in TF loops. | |
383 CompileRun("terminate(); while (true) { }"); | 379 CompileRun("terminate(); while (true) { }"); |
384 CHECK(v8::V8::IsExecutionTerminating()); | 380 CHECK(v8::V8::IsExecutionTerminating()); |
385 } | 381 } |
386 | 382 |
387 | 383 |
388 TEST(TerminateFromOtherThreadWhileMicrotaskRunning) { | 384 TEST(TerminateFromOtherThreadWhileMicrotaskRunning) { |
389 semaphore = new v8::base::Semaphore(0); | 385 semaphore = new v8::base::Semaphore(0); |
390 TerminatorThread thread(CcTest::i_isolate()); | 386 TerminatorThread thread(CcTest::i_isolate()); |
391 thread.Start(); | 387 thread.Start(); |
392 | 388 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 v8::Handle<v8::ObjectTemplate> global_template = CreateGlobalTemplate( | 498 v8::Handle<v8::ObjectTemplate> global_template = CreateGlobalTemplate( |
503 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); | 499 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); |
504 global_template->Set( | 500 global_template->Set( |
505 v8_str("inner_try_call_terminate"), | 501 v8_str("inner_try_call_terminate"), |
506 v8::FunctionTemplate::New(isolate, InnerTryCallTerminate)); | 502 v8::FunctionTemplate::New(isolate, InnerTryCallTerminate)); |
507 v8::Handle<v8::Context> context = | 503 v8::Handle<v8::Context> context = |
508 v8::Context::New(CcTest::isolate(), NULL, global_template); | 504 v8::Context::New(CcTest::isolate(), NULL, global_template); |
509 v8::Context::Scope context_scope(context); | 505 v8::Context::Scope context_scope(context); |
510 { | 506 { |
511 v8::TryCatch try_catch; | 507 v8::TryCatch try_catch; |
512 i::FLAG_turbo_osr = false; // TODO(titzer): interrupts in TF loops. | |
513 CompileRun("inner_try_call_terminate()"); | 508 CompileRun("inner_try_call_terminate()"); |
514 CHECK(try_catch.HasTerminated()); | 509 CHECK(try_catch.HasTerminated()); |
515 } | 510 } |
516 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value()); | 511 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value()); |
517 CHECK(!v8::V8::IsExecutionTerminating()); | 512 CHECK(!v8::V8::IsExecutionTerminating()); |
518 } | 513 } |
519 | 514 |
520 | 515 |
521 TEST(TerminateAndTryCall) { | 516 TEST(TerminateAndTryCall) { |
522 i::FLAG_allow_natives_syntax = true; | 517 i::FLAG_allow_natives_syntax = true; |
(...skipping 12 matching lines...) Expand all Loading... |
535 CHECK(try_catch.HasCaught()); | 530 CHECK(try_catch.HasCaught()); |
536 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 531 CHECK(!v8::V8::IsExecutionTerminating(isolate)); |
537 CHECK(CcTest::global()->Get(v8_str("terminate"))->IsFunction()); | 532 CHECK(CcTest::global()->Get(v8_str("terminate"))->IsFunction()); |
538 // The first stack check after terminate has been re-requested fails. | 533 // The first stack check after terminate has been re-requested fails. |
539 CHECK(CompileRun("1 + 1").IsEmpty()); | 534 CHECK(CompileRun("1 + 1").IsEmpty()); |
540 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 535 CHECK(!v8::V8::IsExecutionTerminating(isolate)); |
541 // V8 then recovers. | 536 // V8 then recovers. |
542 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value()); | 537 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value()); |
543 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 538 CHECK(!v8::V8::IsExecutionTerminating(isolate)); |
544 } | 539 } |
OLD | NEW |