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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 100 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate( | 104 v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate( |
105 v8::Isolate* isolate, | 105 v8::Isolate* isolate, |
106 v8::FunctionCallback terminate, | 106 v8::FunctionCallback terminate, |
107 v8::FunctionCallback doloop) { | 107 v8::FunctionCallback doloop) { |
108 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); | 108 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); |
109 global->Set(v8::String::NewFromUtf8(isolate, "terminate"), | 109 global->Set(v8::String::NewFromUtf8(isolate, "terminate"), |
110 v8::FunctionTemplate::New(terminate)); | 110 v8::FunctionTemplate::New(isolate, terminate)); |
111 global->Set(v8::String::NewFromUtf8(isolate, "fail"), | 111 global->Set(v8::String::NewFromUtf8(isolate, "fail"), |
112 v8::FunctionTemplate::New(Fail)); | 112 v8::FunctionTemplate::New(isolate, Fail)); |
113 global->Set(v8::String::NewFromUtf8(isolate, "loop"), | 113 global->Set(v8::String::NewFromUtf8(isolate, "loop"), |
114 v8::FunctionTemplate::New(Loop)); | 114 v8::FunctionTemplate::New(isolate, Loop)); |
115 global->Set(v8::String::NewFromUtf8(isolate, "doloop"), | 115 global->Set(v8::String::NewFromUtf8(isolate, "doloop"), |
116 v8::FunctionTemplate::New(doloop)); | 116 v8::FunctionTemplate::New(isolate, doloop)); |
117 return global; | 117 return global; |
118 } | 118 } |
119 | 119 |
120 | 120 |
121 // Test that a single thread of JavaScript execution can terminate | 121 // Test that a single thread of JavaScript execution can terminate |
122 // itself. | 122 // itself. |
123 TEST(TerminateOnlyV8ThreadFromThreadItself) { | 123 TEST(TerminateOnlyV8ThreadFromThreadItself) { |
124 v8::HandleScope scope(CcTest::isolate()); | 124 v8::HandleScope scope(CcTest::isolate()); |
125 v8::Handle<v8::ObjectTemplate> global = | 125 v8::Handle<v8::ObjectTemplate> global = |
126 CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop); | 126 CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 CHECK(try_catch.Exception()->IsNull()); | 235 CHECK(try_catch.Exception()->IsNull()); |
236 CHECK(try_catch.Message().IsEmpty()); | 236 CHECK(try_catch.Message().IsEmpty()); |
237 CHECK(!try_catch.CanContinue()); | 237 CHECK(!try_catch.CanContinue()); |
238 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 238 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); |
239 } | 239 } |
240 | 240 |
241 | 241 |
242 // Test that we correctly handle termination exceptions if they are | 242 // Test that we correctly handle termination exceptions if they are |
243 // triggered by the creation of error objects in connection with ICs. | 243 // triggered by the creation of error objects in connection with ICs. |
244 TEST(TerminateLoadICException) { | 244 TEST(TerminateLoadICException) { |
245 v8::HandleScope scope(CcTest::isolate()); | 245 v8::Isolate* isolate = CcTest::isolate(); |
| 246 v8::HandleScope scope(isolate); |
246 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); | 247 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); |
247 global->Set( | 248 global->Set( |
248 v8::String::NewFromUtf8(CcTest::isolate(), "terminate_or_return_object"), | 249 v8::String::NewFromUtf8(isolate, "terminate_or_return_object"), |
249 v8::FunctionTemplate::New(TerminateOrReturnObject)); | 250 v8::FunctionTemplate::New(isolate, TerminateOrReturnObject)); |
250 global->Set(v8::String::NewFromUtf8(CcTest::isolate(), "fail"), | 251 global->Set(v8::String::NewFromUtf8(isolate, "fail"), |
251 v8::FunctionTemplate::New(Fail)); | 252 v8::FunctionTemplate::New(isolate, Fail)); |
252 global->Set(v8::String::NewFromUtf8(CcTest::isolate(), "loop"), | 253 global->Set(v8::String::NewFromUtf8(isolate, "loop"), |
253 v8::FunctionTemplate::New(LoopGetProperty)); | 254 v8::FunctionTemplate::New(isolate, LoopGetProperty)); |
254 | 255 |
255 v8::Handle<v8::Context> context = | 256 v8::Handle<v8::Context> context = |
256 v8::Context::New(CcTest::isolate(), NULL, global); | 257 v8::Context::New(isolate, NULL, global); |
257 v8::Context::Scope context_scope(context); | 258 v8::Context::Scope context_scope(context); |
258 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 259 CHECK(!v8::V8::IsExecutionTerminating(isolate)); |
259 // Run a loop that will be infinite if thread termination does not work. | 260 // Run a loop that will be infinite if thread termination does not work. |
260 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 261 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
261 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); | 262 isolate, "try { loop(); fail(); } catch(e) { fail(); }"); |
262 call_count = 0; | 263 call_count = 0; |
263 v8::Script::Compile(source)->Run(); | 264 v8::Script::Compile(source)->Run(); |
264 // Test that we can run the code again after thread termination. | 265 // Test that we can run the code again after thread termination. |
265 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 266 CHECK(!v8::V8::IsExecutionTerminating(isolate)); |
266 call_count = 0; | 267 call_count = 0; |
267 v8::Script::Compile(source)->Run(); | 268 v8::Script::Compile(source)->Run(); |
268 } | 269 } |
269 | 270 |
270 | 271 |
271 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { | 272 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { |
272 v8::TryCatch try_catch; | 273 v8::TryCatch try_catch; |
273 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 274 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); |
274 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), | 275 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), |
275 "function f() {" | 276 "function f() {" |
(...skipping 16 matching lines...) Expand all Loading... |
292 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 293 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); |
293 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), | 294 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), |
294 "function f() { fail(); } f()")) | 295 "function f() { fail(); } f()")) |
295 ->Run(); | 296 ->Run(); |
296 } | 297 } |
297 | 298 |
298 | 299 |
299 // Test that reentry into V8 while the termination exception is still pending | 300 // Test that reentry into V8 while the termination exception is still pending |
300 // (has not yet unwound the 0-level JS frame) does not crash. | 301 // (has not yet unwound the 0-level JS frame) does not crash. |
301 TEST(TerminateAndReenterFromThreadItself) { | 302 TEST(TerminateAndReenterFromThreadItself) { |
302 v8::HandleScope scope(CcTest::isolate()); | 303 v8::Isolate* isolate = CcTest::isolate(); |
| 304 v8::HandleScope scope(isolate); |
303 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( | 305 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( |
304 CcTest::isolate(), TerminateCurrentThread, ReenterAfterTermination); | 306 isolate, TerminateCurrentThread, ReenterAfterTermination); |
305 v8::Handle<v8::Context> context = | 307 v8::Handle<v8::Context> context = |
306 v8::Context::New(CcTest::isolate(), NULL, global); | 308 v8::Context::New(isolate, NULL, global); |
307 v8::Context::Scope context_scope(context); | 309 v8::Context::Scope context_scope(context); |
308 CHECK(!v8::V8::IsExecutionTerminating()); | 310 CHECK(!v8::V8::IsExecutionTerminating()); |
309 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 311 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
310 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); | 312 isolate, "try { loop(); fail(); } catch(e) { fail(); }"); |
311 v8::Script::Compile(source)->Run(); | 313 v8::Script::Compile(source)->Run(); |
312 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 314 CHECK(!v8::V8::IsExecutionTerminating(isolate)); |
313 // Check we can run JS again after termination. | 315 // Check we can run JS again after termination. |
314 CHECK(v8::Script::Compile( | 316 CHECK(v8::Script::Compile( |
315 v8::String::NewFromUtf8(CcTest::isolate(), | 317 v8::String::NewFromUtf8(isolate, |
316 "function f() { return true; }" | 318 "function f() { return true; }" |
317 "f()")) | 319 "f()")) |
318 ->Run() | 320 ->Run() |
319 ->IsTrue()); | 321 ->IsTrue()); |
320 } | 322 } |
321 | 323 |
322 | 324 |
323 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 325 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
324 v8::TryCatch try_catch; | 326 v8::TryCatch try_catch; |
325 CHECK(!v8::V8::IsExecutionTerminating()); | 327 CHECK(!v8::V8::IsExecutionTerminating()); |
(...skipping 23 matching lines...) Expand all Loading... |
349 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( | 351 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( |
350 isolate, TerminateCurrentThread, DoLoopCancelTerminate); | 352 isolate, TerminateCurrentThread, DoLoopCancelTerminate); |
351 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); | 353 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); |
352 v8::Context::Scope context_scope(context); | 354 v8::Context::Scope context_scope(context); |
353 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 355 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
354 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 356 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
355 isolate, "try { doloop(); } catch(e) { fail(); } 'completed';"); | 357 isolate, "try { doloop(); } catch(e) { fail(); } 'completed';"); |
356 // Check that execution completed with correct return value. | 358 // Check that execution completed with correct return value. |
357 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); | 359 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); |
358 } | 360 } |
OLD | NEW |