| 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 isolate, "try { loop(); fail(); } catch(e) { fail(); }"); | 263 isolate, "try { loop(); fail(); } catch(e) { fail(); }"); |
| 264 call_count = 0; | 264 call_count = 0; |
| 265 v8::Script::Compile(source)->Run(); | 265 v8::Script::Compile(source)->Run(); |
| 266 // Test that we can run the code again after thread termination. | 266 // Test that we can run the code again after thread termination. |
| 267 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 267 CHECK(!v8::V8::IsExecutionTerminating(isolate)); |
| 268 call_count = 0; | 268 call_count = 0; |
| 269 v8::Script::Compile(source)->Run(); | 269 v8::Script::Compile(source)->Run(); |
| 270 } | 270 } |
| 271 | 271 |
| 272 | 272 |
| 273 v8::Persistent<v8::String> reenter_script_1; |
| 274 v8::Persistent<v8::String> reenter_script_2; |
| 275 |
| 273 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { | 276 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 274 v8::TryCatch try_catch; | 277 v8::TryCatch try_catch; |
| 275 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 278 v8::Isolate* isolate = args.GetIsolate(); |
| 276 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), | 279 CHECK(!v8::V8::IsExecutionTerminating(isolate)); |
| 277 "function f() {" | 280 v8::Local<v8::String> script = |
| 278 " var term = true;" | 281 v8::Local<v8::String>::New(isolate, reenter_script_1); |
| 279 " try {" | 282 v8::Script::Compile(script)->Run(); |
| 280 " while(true) {" | |
| 281 " if (term) terminate();" | |
| 282 " term = false;" | |
| 283 " }" | |
| 284 " fail();" | |
| 285 " } catch(e) {" | |
| 286 " fail();" | |
| 287 " }" | |
| 288 "}" | |
| 289 "f()"))->Run(); | |
| 290 CHECK(try_catch.HasCaught()); | 283 CHECK(try_catch.HasCaught()); |
| 291 CHECK(try_catch.Exception()->IsNull()); | 284 CHECK(try_catch.Exception()->IsNull()); |
| 292 CHECK(try_catch.Message().IsEmpty()); | 285 CHECK(try_catch.Message().IsEmpty()); |
| 293 CHECK(!try_catch.CanContinue()); | 286 CHECK(!try_catch.CanContinue()); |
| 294 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 287 CHECK(v8::V8::IsExecutionTerminating(isolate)); |
| 295 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), | 288 script = v8::Local<v8::String>::New(isolate, reenter_script_2); |
| 296 "function f() { fail(); } f()")) | 289 v8::Script::Compile(script)->Run(); |
| 297 ->Run(); | |
| 298 } | 290 } |
| 299 | 291 |
| 300 | 292 |
| 301 // Test that reentry into V8 while the termination exception is still pending | 293 // Test that reentry into V8 while the termination exception is still pending |
| 302 // (has not yet unwound the 0-level JS frame) does not crash. | 294 // (has not yet unwound the 0-level JS frame) does not crash. |
| 303 TEST(TerminateAndReenterFromThreadItself) { | 295 TEST(TerminateAndReenterFromThreadItself) { |
| 304 v8::Isolate* isolate = CcTest::isolate(); | 296 v8::Isolate* isolate = CcTest::isolate(); |
| 305 v8::HandleScope scope(isolate); | 297 v8::HandleScope scope(isolate); |
| 306 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( | 298 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( |
| 307 isolate, TerminateCurrentThread, ReenterAfterTermination); | 299 isolate, TerminateCurrentThread, ReenterAfterTermination); |
| 308 v8::Handle<v8::Context> context = | 300 v8::Handle<v8::Context> context = |
| 309 v8::Context::New(isolate, NULL, global); | 301 v8::Context::New(isolate, NULL, global); |
| 310 v8::Context::Scope context_scope(context); | 302 v8::Context::Scope context_scope(context); |
| 311 CHECK(!v8::V8::IsExecutionTerminating()); | 303 CHECK(!v8::V8::IsExecutionTerminating()); |
| 312 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 304 // Create script strings upfront as it won't work when terminating. |
| 313 isolate, "try { loop(); fail(); } catch(e) { fail(); }"); | 305 reenter_script_1.Reset(isolate, v8_str( |
| 314 v8::Script::Compile(source)->Run(); | 306 "function f() {" |
| 307 " var term = true;" |
| 308 " try {" |
| 309 " while(true) {" |
| 310 " if (term) terminate();" |
| 311 " term = false;" |
| 312 " }" |
| 313 " fail();" |
| 314 " } catch(e) {" |
| 315 " fail();" |
| 316 " }" |
| 317 "}" |
| 318 "f()")); |
| 319 reenter_script_2.Reset(isolate, v8_str("function f() { fail(); } f()")); |
| 320 CompileRun("try { loop(); fail(); } catch(e) { fail(); }"); |
| 315 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 321 CHECK(!v8::V8::IsExecutionTerminating(isolate)); |
| 316 // Check we can run JS again after termination. | 322 // Check we can run JS again after termination. |
| 317 CHECK(v8::Script::Compile( | 323 CHECK(CompileRun("function f() { return true; } f()")->IsTrue()); |
| 318 v8::String::NewFromUtf8(isolate, | 324 reenter_script_1.Reset(); |
| 319 "function f() { return true; }" | 325 reenter_script_2.Reset(); |
| 320 "f()")) | |
| 321 ->Run() | |
| 322 ->IsTrue()); | |
| 323 } | 326 } |
| 324 | 327 |
| 325 | 328 |
| 326 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 329 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 327 v8::TryCatch try_catch; | 330 v8::TryCatch try_catch; |
| 328 CHECK(!v8::V8::IsExecutionTerminating()); | 331 CHECK(!v8::V8::IsExecutionTerminating()); |
| 329 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), | 332 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), |
| 330 "var term = true;" | 333 "var term = true;" |
| 331 "while(true) {" | 334 "while(true) {" |
| 332 " if (term) terminate();" | 335 " if (term) terminate();" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 TEST(ErrorObjectAfterTermination) { | 467 TEST(ErrorObjectAfterTermination) { |
| 465 v8::Isolate* isolate = CcTest::isolate(); | 468 v8::Isolate* isolate = CcTest::isolate(); |
| 466 v8::HandleScope scope(isolate); | 469 v8::HandleScope scope(isolate); |
| 467 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 470 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
| 468 v8::Context::Scope context_scope(context); | 471 v8::Context::Scope context_scope(context); |
| 469 v8::V8::TerminateExecution(isolate); | 472 v8::V8::TerminateExecution(isolate); |
| 470 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("error")); | 473 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("error")); |
| 471 // TODO(yangguo): crbug/403509. Check for empty handle instead. | 474 // TODO(yangguo): crbug/403509. Check for empty handle instead. |
| 472 CHECK(error->IsUndefined()); | 475 CHECK(error->IsUndefined()); |
| 473 } | 476 } |
| OLD | NEW |