Chromium Code Reviews| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) {" |
| 231 " (function() {})();" // trigger stack check. | |
| 231 " fail();" | 232 " fail();" |
| 232 " }" | 233 " }" |
| 233 "}" | 234 "}" |
| 234 "f()"))->Run(); | 235 "f()"))->Run(); |
| 235 CHECK(try_catch.HasCaught()); | 236 CHECK(try_catch.HasCaught()); |
| 236 CHECK(try_catch.Exception()->IsNull()); | 237 CHECK(try_catch.Exception()->IsNull()); |
| 237 CHECK(try_catch.Message().IsEmpty()); | 238 CHECK(try_catch.Message().IsEmpty()); |
| 238 CHECK(!try_catch.CanContinue()); | 239 CHECK(!try_catch.CanContinue()); |
| 239 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 240 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); |
| 240 } | 241 } |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 TEST(ErrorObjectAfterTermination) { | 468 TEST(ErrorObjectAfterTermination) { |
| 468 v8::Isolate* isolate = CcTest::isolate(); | 469 v8::Isolate* isolate = CcTest::isolate(); |
| 469 v8::HandleScope scope(isolate); | 470 v8::HandleScope scope(isolate); |
| 470 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 471 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 471 v8::Context::Scope context_scope(context); | 472 v8::Context::Scope context_scope(context); |
| 472 v8::V8::TerminateExecution(isolate); | 473 v8::V8::TerminateExecution(isolate); |
| 473 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("error")); | 474 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("error")); |
| 474 // TODO(yangguo): crbug/403509. Check for empty handle instead. | 475 // TODO(yangguo): crbug/403509. Check for empty handle instead. |
| 475 CHECK(error->IsUndefined()); | 476 CHECK(error->IsUndefined()); |
| 476 } | 477 } |
| 478 | |
| 479 | |
| 480 void InnerTryCallTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 481 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | |
| 482 v8::Handle<v8::Object> global = CcTest::global(); | |
| 483 v8::Handle<v8::Function> loop = | |
| 484 v8::Handle<v8::Function>::Cast(global->Get(v8_str("loop"))); | |
| 485 i::MaybeHandle<i::Object> result = | |
| 486 i::Execution::TryCall(v8::Utils::OpenHandle((*loop)), | |
| 487 v8::Utils::OpenHandle((*global)), 0, NULL, NULL); | |
| 488 CHECK(result.is_null()); | |
| 489 // TryCall ignores terminate execution, but rerequests the interrupt. | |
| 490 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | |
| 491 CHECK(CompileRun("1+1;").IsEmpty()); | |
|
Jakob Kummerow
2015/02/23 15:24:45
nit: spaces around '+'
(I guess strictly speaking
| |
| 492 } | |
| 493 | |
| 494 | |
| 495 TEST(TerminationInInnerTryCall) { | |
| 496 v8::Isolate* isolate = CcTest::isolate(); | |
| 497 v8::HandleScope scope(isolate); | |
| 498 v8::Handle<v8::ObjectTemplate> global_template = CreateGlobalTemplate( | |
| 499 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); | |
| 500 global_template->Set( | |
| 501 v8_str("inner_try_call_terminate"), | |
| 502 v8::FunctionTemplate::New(isolate, InnerTryCallTerminate)); | |
| 503 v8::Handle<v8::Context> context = | |
| 504 v8::Context::New(CcTest::isolate(), NULL, global_template); | |
| 505 v8::Context::Scope context_scope(context); | |
| 506 { | |
| 507 v8::TryCatch try_catch; | |
| 508 CompileRun("inner_try_call_terminate()"); | |
| 509 CHECK(try_catch.HasTerminated()); | |
| 510 } | |
| 511 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value()); | |
| 512 CHECK(!v8::V8::IsExecutionTerminating()); | |
| 513 } | |
| 514 | |
| 515 | |
| 516 TEST(TerminateAndTryCall) { | |
| 517 i::FLAG_allow_natives_syntax = true; | |
| 518 v8::Isolate* isolate = CcTest::isolate(); | |
| 519 v8::HandleScope scope(isolate); | |
| 520 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( | |
| 521 isolate, TerminateCurrentThread, DoLoopCancelTerminate); | |
| 522 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); | |
| 523 v8::Context::Scope context_scope(context); | |
| 524 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | |
|
Jakob Kummerow
2015/02/23 15:24:45
nit: s/CcTest::isolate()/isolate/, it's cleaner
| |
| 525 v8::TryCatch try_catch; | |
| 526 CHECK(!v8::V8::IsExecutionTerminating()); | |
|
Jakob Kummerow
2015/02/23 15:24:45
nit: pass in the isolate, here and below (I'm kind
| |
| 527 // Terminate execution has been triggered inside TryCall, but re-requested | |
| 528 // to trigger later. | |
| 529 CHECK(CompileRun("terminate(); reference_error();").IsEmpty()); | |
| 530 CHECK(try_catch.HasCaught()); | |
| 531 CHECK(!v8::V8::IsExecutionTerminating()); | |
| 532 CHECK(CcTest::global()->Get(v8_str("terminate"))->IsFunction()); | |
| 533 // The first stack check after terminate has been re-requested fails. | |
| 534 CHECK(CompileRun("1 + 1").IsEmpty()); | |
| 535 CHECK(!v8::V8::IsExecutionTerminating()); | |
| 536 // V8 then recovers. | |
| 537 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value()); | |
| 538 CHECK(!v8::V8::IsExecutionTerminating()); | |
| 539 } | |
| OLD | NEW |