| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // Run a loop that will be infinite if thread termination does not work. | 197 // Run a loop that will be infinite if thread termination does not work. |
| 198 v8::MaybeLocal<v8::Value> result = | 198 v8::MaybeLocal<v8::Value> result = |
| 199 CompileRun(CcTest::isolate()->GetCurrentContext(), | 199 CompileRun(CcTest::isolate()->GetCurrentContext(), |
| 200 "try { loop(); fail(); } catch(e) { fail(); }"); | 200 "try { loop(); fail(); } catch(e) { fail(); }"); |
| 201 CHECK(result.IsEmpty()); | 201 CHECK(result.IsEmpty()); |
| 202 thread.Join(); | 202 thread.Join(); |
| 203 delete semaphore; | 203 delete semaphore; |
| 204 semaphore = NULL; | 204 semaphore = NULL; |
| 205 } | 205 } |
| 206 | 206 |
| 207 // Test that execution can be terminated from within JSON.stringify. |
| 208 TEST(TerminateJsonStringify) { |
| 209 semaphore = new v8::base::Semaphore(0); |
| 210 TerminatorThread thread(CcTest::i_isolate()); |
| 211 thread.Start(); |
| 212 |
| 213 v8::HandleScope scope(CcTest::isolate()); |
| 214 v8::Local<v8::ObjectTemplate> global = |
| 215 CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop); |
| 216 v8::Local<v8::Context> context = |
| 217 v8::Context::New(CcTest::isolate(), NULL, global); |
| 218 v8::Context::Scope context_scope(context); |
| 219 CHECK(!CcTest::isolate()->IsExecutionTerminating()); |
| 220 v8::MaybeLocal<v8::Value> result = |
| 221 CompileRun(CcTest::isolate()->GetCurrentContext(), |
| 222 "var x = [];" |
| 223 "x[2**31]=1;" |
| 224 "terminate();" |
| 225 "JSON.stringify(x);" |
| 226 "fail();"); |
| 227 CHECK(result.IsEmpty()); |
| 228 thread.Join(); |
| 229 delete semaphore; |
| 230 semaphore = NULL; |
| 231 } |
| 207 | 232 |
| 208 int call_count = 0; | 233 int call_count = 0; |
| 209 | 234 |
| 210 | 235 |
| 211 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | 236 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 212 if (++call_count == 10) { | 237 if (++call_count == 10) { |
| 213 CHECK(!args.GetIsolate()->IsExecutionTerminating()); | 238 CHECK(!args.GetIsolate()->IsExecutionTerminating()); |
| 214 args.GetIsolate()->TerminateExecution(); | 239 args.GetIsolate()->TerminateExecution(); |
| 215 return; | 240 return; |
| 216 } | 241 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 CHECK(value->IsFunction()); | 584 CHECK(value->IsFunction()); |
| 560 // The first stack check after terminate has been re-requested fails. | 585 // The first stack check after terminate has been re-requested fails. |
| 561 CHECK(CompileRun("1 + 1").IsEmpty()); | 586 CHECK(CompileRun("1 + 1").IsEmpty()); |
| 562 CHECK(!isolate->IsExecutionTerminating()); | 587 CHECK(!isolate->IsExecutionTerminating()); |
| 563 // V8 then recovers. | 588 // V8 then recovers. |
| 564 v8::Maybe<int32_t> result = CompileRun("2 + 2")->Int32Value( | 589 v8::Maybe<int32_t> result = CompileRun("2 + 2")->Int32Value( |
| 565 v8::Isolate::GetCurrent()->GetCurrentContext()); | 590 v8::Isolate::GetCurrent()->GetCurrentContext()); |
| 566 CHECK_EQ(4, result.FromJust()); | 591 CHECK_EQ(4, result.FromJust()); |
| 567 CHECK(!isolate->IsExecutionTerminating()); | 592 CHECK(!isolate->IsExecutionTerminating()); |
| 568 } | 593 } |
| OLD | NEW |