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

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

Issue 1154423004: Update all callsites of the TryCatch ctor to pass an Isolate (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « test/cctest/test-strings.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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); 54 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
55 v8::Handle<v8::String> source = v8::String::NewFromUtf8( 55 v8::Handle<v8::String> source = v8::String::NewFromUtf8(
56 args.GetIsolate(), "try { doloop(); fail(); } catch(e) { fail(); }"); 56 args.GetIsolate(), "try { doloop(); fail(); } catch(e) { fail(); }");
57 v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run(); 57 v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run();
58 CHECK(result.IsEmpty()); 58 CHECK(result.IsEmpty());
59 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); 59 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
60 } 60 }
61 61
62 62
63 void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) { 63 void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) {
64 v8::TryCatch try_catch; 64 v8::TryCatch try_catch(args.GetIsolate());
65 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); 65 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
66 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), 66 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
67 "function f() {" 67 "function f() {"
68 " var term = true;" 68 " var term = true;"
69 " try {" 69 " try {"
70 " while(true) {" 70 " while(true) {"
71 " if (term) terminate();" 71 " if (term) terminate();"
72 " term = false;" 72 " term = false;"
73 " }" 73 " }"
74 " fail();" 74 " fail();"
75 " } catch(e) {" 75 " } catch(e) {"
76 " fail();" 76 " fail();"
77 " }" 77 " }"
78 "}" 78 "}"
79 "f()"))->Run(); 79 "f()"))->Run();
80 CHECK(try_catch.HasCaught()); 80 CHECK(try_catch.HasCaught());
81 CHECK(try_catch.Exception()->IsNull()); 81 CHECK(try_catch.Exception()->IsNull());
82 CHECK(try_catch.Message().IsEmpty()); 82 CHECK(try_catch.Message().IsEmpty());
83 CHECK(!try_catch.CanContinue()); 83 CHECK(!try_catch.CanContinue());
84 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); 84 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
85 } 85 }
86 86
87 87
88 void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) { 88 void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) {
89 v8::TryCatch try_catch; 89 v8::TryCatch try_catch(args.GetIsolate());
90 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); 90 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
91 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), 91 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
92 "var term = true;" 92 "var term = true;"
93 "while(true) {" 93 "while(true) {"
94 " if (term) terminate();" 94 " if (term) terminate();"
95 " term = false;" 95 " term = false;"
96 "}"))->Run(); 96 "}"))->Run();
97 CHECK(try_catch.HasCaught()); 97 CHECK(try_catch.HasCaught());
98 CHECK(try_catch.Exception()->IsNull()); 98 CHECK(try_catch.Exception()->IsNull());
99 CHECK(try_catch.Message().IsEmpty()); 99 CHECK(try_catch.Message().IsEmpty());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 return; 210 return;
211 } 211 }
212 v8::Local<v8::Object> result = v8::Object::New(args.GetIsolate()); 212 v8::Local<v8::Object> result = v8::Object::New(args.GetIsolate());
213 result->Set(v8::String::NewFromUtf8(args.GetIsolate(), "x"), 213 result->Set(v8::String::NewFromUtf8(args.GetIsolate(), "x"),
214 v8::Integer::New(args.GetIsolate(), 42)); 214 v8::Integer::New(args.GetIsolate(), 42));
215 args.GetReturnValue().Set(result); 215 args.GetReturnValue().Set(result);
216 } 216 }
217 217
218 218
219 void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) { 219 void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) {
220 v8::TryCatch try_catch; 220 v8::TryCatch try_catch(args.GetIsolate());
221 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); 221 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
222 v8::Script::Compile( 222 v8::Script::Compile(
223 v8::String::NewFromUtf8(args.GetIsolate(), 223 v8::String::NewFromUtf8(args.GetIsolate(),
224 "function f() {" 224 "function f() {"
225 " try {" 225 " try {"
226 " while(true) {" 226 " while(true) {"
227 " terminate_or_return_object().x;" 227 " terminate_or_return_object().x;"
228 " }" 228 " }"
229 " fail();" 229 " fail();"
230 " } catch(e) {" 230 " } catch(e) {"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 CHECK(!v8::V8::IsExecutionTerminating(isolate)); 268 CHECK(!v8::V8::IsExecutionTerminating(isolate));
269 call_count = 0; 269 call_count = 0;
270 v8::Script::Compile(source)->Run(); 270 v8::Script::Compile(source)->Run();
271 } 271 }
272 272
273 273
274 v8::Persistent<v8::String> reenter_script_1; 274 v8::Persistent<v8::String> reenter_script_1;
275 v8::Persistent<v8::String> reenter_script_2; 275 v8::Persistent<v8::String> reenter_script_2;
276 276
277 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { 277 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) {
278 v8::TryCatch try_catch; 278 v8::TryCatch try_catch(args.GetIsolate());
279 v8::Isolate* isolate = args.GetIsolate(); 279 v8::Isolate* isolate = args.GetIsolate();
280 CHECK(!v8::V8::IsExecutionTerminating(isolate)); 280 CHECK(!v8::V8::IsExecutionTerminating(isolate));
281 v8::Local<v8::String> script = 281 v8::Local<v8::String> script =
282 v8::Local<v8::String>::New(isolate, reenter_script_1); 282 v8::Local<v8::String>::New(isolate, reenter_script_1);
283 v8::Script::Compile(script)->Run(); 283 v8::Script::Compile(script)->Run();
284 CHECK(try_catch.HasCaught()); 284 CHECK(try_catch.HasCaught());
285 CHECK(try_catch.Exception()->IsNull()); 285 CHECK(try_catch.Exception()->IsNull());
286 CHECK(try_catch.Message().IsEmpty()); 286 CHECK(try_catch.Message().IsEmpty());
287 CHECK(!try_catch.CanContinue()); 287 CHECK(!try_catch.CanContinue());
288 CHECK(v8::V8::IsExecutionTerminating(isolate)); 288 CHECK(v8::V8::IsExecutionTerminating(isolate));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 CompileRun("try { loop(); fail(); } catch(e) { fail(); }"); 321 CompileRun("try { loop(); fail(); } catch(e) { fail(); }");
322 CHECK(!v8::V8::IsExecutionTerminating(isolate)); 322 CHECK(!v8::V8::IsExecutionTerminating(isolate));
323 // Check we can run JS again after termination. 323 // Check we can run JS again after termination.
324 CHECK(CompileRun("function f() { return true; } f()")->IsTrue()); 324 CHECK(CompileRun("function f() { return true; } f()")->IsTrue());
325 reenter_script_1.Reset(); 325 reenter_script_1.Reset();
326 reenter_script_2.Reset(); 326 reenter_script_2.Reset();
327 } 327 }
328 328
329 329
330 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { 330 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
331 v8::TryCatch try_catch; 331 v8::TryCatch try_catch(args.GetIsolate());
332 CHECK(!v8::V8::IsExecutionTerminating()); 332 CHECK(!v8::V8::IsExecutionTerminating());
333 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), 333 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
334 "var term = true;" 334 "var term = true;"
335 "while(true) {" 335 "while(true) {"
336 " if (term) terminate();" 336 " if (term) terminate();"
337 " term = false;" 337 " term = false;"
338 "}" 338 "}"
339 "fail();"))->Run(); 339 "fail();"))->Run();
340 CHECK(try_catch.HasCaught()); 340 CHECK(try_catch.HasCaught());
341 CHECK(try_catch.Exception()->IsNull()); 341 CHECK(try_catch.Exception()->IsNull());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 419
420 TEST(PostponeTerminateException) { 420 TEST(PostponeTerminateException) {
421 v8::Isolate* isolate = CcTest::isolate(); 421 v8::Isolate* isolate = CcTest::isolate();
422 v8::HandleScope scope(isolate); 422 v8::HandleScope scope(isolate);
423 v8::Handle<v8::ObjectTemplate> global = 423 v8::Handle<v8::ObjectTemplate> global =
424 CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop); 424 CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop);
425 v8::Handle<v8::Context> context = 425 v8::Handle<v8::Context> context =
426 v8::Context::New(CcTest::isolate(), NULL, global); 426 v8::Context::New(CcTest::isolate(), NULL, global);
427 v8::Context::Scope context_scope(context); 427 v8::Context::Scope context_scope(context);
428 428
429 v8::TryCatch try_catch; 429 v8::TryCatch try_catch(isolate);
430 static const char* terminate_and_loop = 430 static const char* terminate_and_loop =
431 "terminate(); for (var i = 0; i < 10000; i++);"; 431 "terminate(); for (var i = 0; i < 10000; i++);";
432 432
433 { // Postpone terminate execution interrupts. 433 { // Postpone terminate execution interrupts.
434 i::PostponeInterruptsScope p1(CcTest::i_isolate(), 434 i::PostponeInterruptsScope p1(CcTest::i_isolate(),
435 i::StackGuard::TERMINATE_EXECUTION) ; 435 i::StackGuard::TERMINATE_EXECUTION) ;
436 436
437 // API interrupts should still be triggered. 437 // API interrupts should still be triggered.
438 CcTest::isolate()->RequestInterrupt(&CounterCallback, NULL); 438 CcTest::isolate()->RequestInterrupt(&CounterCallback, NULL);
439 CHECK_EQ(0, callback_counter); 439 CHECK_EQ(0, callback_counter);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 v8::HandleScope scope(isolate); 497 v8::HandleScope scope(isolate);
498 v8::Handle<v8::ObjectTemplate> global_template = CreateGlobalTemplate( 498 v8::Handle<v8::ObjectTemplate> global_template = CreateGlobalTemplate(
499 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); 499 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall);
500 global_template->Set( 500 global_template->Set(
501 v8_str("inner_try_call_terminate"), 501 v8_str("inner_try_call_terminate"),
502 v8::FunctionTemplate::New(isolate, InnerTryCallTerminate)); 502 v8::FunctionTemplate::New(isolate, InnerTryCallTerminate));
503 v8::Handle<v8::Context> context = 503 v8::Handle<v8::Context> context =
504 v8::Context::New(CcTest::isolate(), NULL, global_template); 504 v8::Context::New(CcTest::isolate(), NULL, global_template);
505 v8::Context::Scope context_scope(context); 505 v8::Context::Scope context_scope(context);
506 { 506 {
507 v8::TryCatch try_catch; 507 v8::TryCatch try_catch(isolate);
508 CompileRun("inner_try_call_terminate()"); 508 CompileRun("inner_try_call_terminate()");
509 CHECK(try_catch.HasTerminated()); 509 CHECK(try_catch.HasTerminated());
510 } 510 }
511 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value()); 511 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value());
512 CHECK(!v8::V8::IsExecutionTerminating()); 512 CHECK(!v8::V8::IsExecutionTerminating());
513 } 513 }
514 514
515 515
516 TEST(TerminateAndTryCall) { 516 TEST(TerminateAndTryCall) {
517 i::FLAG_allow_natives_syntax = true; 517 i::FLAG_allow_natives_syntax = true;
518 v8::Isolate* isolate = CcTest::isolate(); 518 v8::Isolate* isolate = CcTest::isolate();
519 v8::HandleScope scope(isolate); 519 v8::HandleScope scope(isolate);
520 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( 520 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
521 isolate, TerminateCurrentThread, DoLoopCancelTerminate); 521 isolate, TerminateCurrentThread, DoLoopCancelTerminate);
522 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); 522 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global);
523 v8::Context::Scope context_scope(context); 523 v8::Context::Scope context_scope(context);
524 CHECK(!v8::V8::IsExecutionTerminating(isolate)); 524 CHECK(!v8::V8::IsExecutionTerminating(isolate));
525 v8::TryCatch try_catch; 525 v8::TryCatch try_catch(isolate);
526 CHECK(!v8::V8::IsExecutionTerminating(isolate)); 526 CHECK(!v8::V8::IsExecutionTerminating(isolate));
527 // Terminate execution has been triggered inside TryCall, but re-requested 527 // Terminate execution has been triggered inside TryCall, but re-requested
528 // to trigger later. 528 // to trigger later.
529 CHECK(CompileRun("terminate(); reference_error();").IsEmpty()); 529 CHECK(CompileRun("terminate(); reference_error();").IsEmpty());
530 CHECK(try_catch.HasCaught()); 530 CHECK(try_catch.HasCaught());
531 CHECK(!v8::V8::IsExecutionTerminating(isolate)); 531 CHECK(!v8::V8::IsExecutionTerminating(isolate));
532 CHECK(CcTest::global()->Get(v8_str("terminate"))->IsFunction()); 532 CHECK(CcTest::global()->Get(v8_str("terminate"))->IsFunction());
533 // The first stack check after terminate has been re-requested fails. 533 // The first stack check after terminate has been re-requested fails.
534 CHECK(CompileRun("1 + 1").IsEmpty()); 534 CHECK(CompileRun("1 + 1").IsEmpty());
535 CHECK(!v8::V8::IsExecutionTerminating(isolate)); 535 CHECK(!v8::V8::IsExecutionTerminating(isolate));
536 // V8 then recovers. 536 // V8 then recovers.
537 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value()); 537 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value());
538 CHECK(!v8::V8::IsExecutionTerminating(isolate)); 538 CHECK(!v8::V8::IsExecutionTerminating(isolate));
539 } 539 }
OLDNEW
« no previous file with comments | « test/cctest/test-strings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698