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

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

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed rest Created 7 years, 9 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 | Annotate | Revision Log
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail)); 114 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail));
115 global->Set(v8::String::New("loop"), v8::FunctionTemplate::New(Loop)); 115 global->Set(v8::String::New("loop"), v8::FunctionTemplate::New(Loop));
116 global->Set(v8::String::New("doloop"), v8::FunctionTemplate::New(doloop)); 116 global->Set(v8::String::New("doloop"), v8::FunctionTemplate::New(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; 124 v8::HandleScope scope(v8::Isolate::GetCurrent());
125 v8::Handle<v8::ObjectTemplate> global = 125 v8::Handle<v8::ObjectTemplate> global =
126 CreateGlobalTemplate(TerminateCurrentThread, DoLoop); 126 CreateGlobalTemplate(TerminateCurrentThread, DoLoop);
127 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global); 127 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
128 v8::Context::Scope context_scope(context); 128 v8::Context::Scope context_scope(context);
129 CHECK(!v8::V8::IsExecutionTerminating()); 129 CHECK(!v8::V8::IsExecutionTerminating());
130 // Run a loop that will be infinite if thread termination does not work. 130 // Run a loop that will be infinite if thread termination does not work.
131 v8::Handle<v8::String> source = 131 v8::Handle<v8::String> source =
132 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 132 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
133 v8::Script::Compile(source)->Run(); 133 v8::Script::Compile(source)->Run();
134 // Test that we can run the code again after thread termination. 134 // Test that we can run the code again after thread termination.
135 CHECK(!v8::V8::IsExecutionTerminating()); 135 CHECK(!v8::V8::IsExecutionTerminating());
136 v8::Script::Compile(source)->Run(); 136 v8::Script::Compile(source)->Run();
137 context.Dispose(context->GetIsolate()); 137 context.Dispose(context->GetIsolate());
138 } 138 }
139 139
140 140
141 // Test that a single thread of JavaScript execution can terminate 141 // Test that a single thread of JavaScript execution can terminate
142 // itself in a loop that performs no calls. 142 // itself in a loop that performs no calls.
143 TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) { 143 TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) {
144 v8::HandleScope scope; 144 v8::HandleScope scope(v8::Isolate::GetCurrent());
145 v8::Handle<v8::ObjectTemplate> global = 145 v8::Handle<v8::ObjectTemplate> global =
146 CreateGlobalTemplate(TerminateCurrentThread, DoLoopNoCall); 146 CreateGlobalTemplate(TerminateCurrentThread, DoLoopNoCall);
147 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global); 147 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
148 v8::Context::Scope context_scope(context); 148 v8::Context::Scope context_scope(context);
149 CHECK(!v8::V8::IsExecutionTerminating()); 149 CHECK(!v8::V8::IsExecutionTerminating());
150 // Run a loop that will be infinite if thread termination does not work. 150 // Run a loop that will be infinite if thread termination does not work.
151 v8::Handle<v8::String> source = 151 v8::Handle<v8::String> source =
152 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 152 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
153 v8::Script::Compile(source)->Run(); 153 v8::Script::Compile(source)->Run();
154 CHECK(!v8::V8::IsExecutionTerminating()); 154 CHECK(!v8::V8::IsExecutionTerminating());
(...skipping 19 matching lines...) Expand all
174 }; 174 };
175 175
176 176
177 // Test that a single thread of JavaScript execution can be terminated 177 // Test that a single thread of JavaScript execution can be terminated
178 // from the side by another thread. 178 // from the side by another thread.
179 TEST(TerminateOnlyV8ThreadFromOtherThread) { 179 TEST(TerminateOnlyV8ThreadFromOtherThread) {
180 semaphore = v8::internal::OS::CreateSemaphore(0); 180 semaphore = v8::internal::OS::CreateSemaphore(0);
181 TerminatorThread thread(i::Isolate::Current()); 181 TerminatorThread thread(i::Isolate::Current());
182 thread.Start(); 182 thread.Start();
183 183
184 v8::HandleScope scope; 184 v8::HandleScope scope(v8::Isolate::GetCurrent());
185 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(Signal, DoLoop); 185 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(Signal, DoLoop);
186 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global); 186 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
187 v8::Context::Scope context_scope(context); 187 v8::Context::Scope context_scope(context);
188 CHECK(!v8::V8::IsExecutionTerminating()); 188 CHECK(!v8::V8::IsExecutionTerminating());
189 // Run a loop that will be infinite if thread termination does not work. 189 // Run a loop that will be infinite if thread termination does not work.
190 v8::Handle<v8::String> source = 190 v8::Handle<v8::String> source =
191 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 191 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
192 v8::Script::Compile(source)->Run(); 192 v8::Script::Compile(source)->Run();
193 193
194 thread.Join(); 194 thread.Join();
195 delete semaphore; 195 delete semaphore;
196 semaphore = NULL; 196 semaphore = NULL;
197 context.Dispose(context->GetIsolate()); 197 context.Dispose(context->GetIsolate());
198 } 198 }
199 199
200 200
201 class LoopingThread : public v8::internal::Thread { 201 class LoopingThread : public v8::internal::Thread {
202 public: 202 public:
203 LoopingThread() : Thread("LoopingThread") { } 203 LoopingThread() : Thread("LoopingThread") { }
204 void Run() { 204 void Run() {
205 v8::Locker locker(CcTest::default_isolate()); 205 v8::Locker locker(CcTest::default_isolate());
206 v8::HandleScope scope; 206 v8::HandleScope scope(CcTest::default_isolate());
207 v8_thread_id_ = v8::V8::GetCurrentThreadId(); 207 v8_thread_id_ = v8::V8::GetCurrentThreadId();
208 v8::Handle<v8::ObjectTemplate> global = 208 v8::Handle<v8::ObjectTemplate> global =
209 CreateGlobalTemplate(Signal, DoLoop); 209 CreateGlobalTemplate(Signal, DoLoop);
210 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global); 210 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
211 v8::Context::Scope context_scope(context); 211 v8::Context::Scope context_scope(context);
212 CHECK(!v8::V8::IsExecutionTerminating()); 212 CHECK(!v8::V8::IsExecutionTerminating());
213 // Run a loop that will be infinite if thread termination does not work. 213 // Run a loop that will be infinite if thread termination does not work.
214 v8::Handle<v8::String> source = 214 v8::Handle<v8::String> source =
215 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 215 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
216 v8::Script::Compile(source)->Run(); 216 v8::Script::Compile(source)->Run();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 CHECK(try_catch.Message().IsEmpty()); 299 CHECK(try_catch.Message().IsEmpty());
300 CHECK(!try_catch.CanContinue()); 300 CHECK(!try_catch.CanContinue());
301 CHECK(v8::V8::IsExecutionTerminating()); 301 CHECK(v8::V8::IsExecutionTerminating());
302 return v8::Undefined(); 302 return v8::Undefined();
303 } 303 }
304 304
305 305
306 // Test that we correctly handle termination exceptions if they are 306 // Test that we correctly handle termination exceptions if they are
307 // triggered by the creation of error objects in connection with ICs. 307 // triggered by the creation of error objects in connection with ICs.
308 TEST(TerminateLoadICException) { 308 TEST(TerminateLoadICException) {
309 v8::HandleScope scope; 309 v8::HandleScope scope(v8::Isolate::GetCurrent());
310 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 310 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
311 global->Set(v8::String::New("terminate_or_return_object"), 311 global->Set(v8::String::New("terminate_or_return_object"),
312 v8::FunctionTemplate::New(TerminateOrReturnObject)); 312 v8::FunctionTemplate::New(TerminateOrReturnObject));
313 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail)); 313 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail));
314 global->Set(v8::String::New("loop"), 314 global->Set(v8::String::New("loop"),
315 v8::FunctionTemplate::New(LoopGetProperty)); 315 v8::FunctionTemplate::New(LoopGetProperty));
316 316
317 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global); 317 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
318 v8::Context::Scope context_scope(context); 318 v8::Context::Scope context_scope(context);
319 CHECK(!v8::V8::IsExecutionTerminating()); 319 CHECK(!v8::V8::IsExecutionTerminating());
(...skipping 30 matching lines...) Expand all
350 CHECK(try_catch.Message().IsEmpty()); 350 CHECK(try_catch.Message().IsEmpty());
351 CHECK(!try_catch.CanContinue()); 351 CHECK(!try_catch.CanContinue());
352 CHECK(v8::V8::IsExecutionTerminating()); 352 CHECK(v8::V8::IsExecutionTerminating());
353 v8::Script::Compile(v8::String::New("function f() { fail(); } f()"))->Run(); 353 v8::Script::Compile(v8::String::New("function f() { fail(); } f()"))->Run();
354 return v8::Undefined(); 354 return v8::Undefined();
355 } 355 }
356 356
357 // Test that reentry into V8 while the termination exception is still pending 357 // Test that reentry into V8 while the termination exception is still pending
358 // (has not yet unwound the 0-level JS frame) does not crash. 358 // (has not yet unwound the 0-level JS frame) does not crash.
359 TEST(TerminateAndReenterFromThreadItself) { 359 TEST(TerminateAndReenterFromThreadItself) {
360 v8::HandleScope scope; 360 v8::HandleScope scope(v8::Isolate::GetCurrent());
361 v8::Handle<v8::ObjectTemplate> global = 361 v8::Handle<v8::ObjectTemplate> global =
362 CreateGlobalTemplate(TerminateCurrentThread, ReenterAfterTermination); 362 CreateGlobalTemplate(TerminateCurrentThread, ReenterAfterTermination);
363 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global); 363 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
364 v8::Context::Scope context_scope(context); 364 v8::Context::Scope context_scope(context);
365 CHECK(!v8::V8::IsExecutionTerminating()); 365 CHECK(!v8::V8::IsExecutionTerminating());
366 v8::Handle<v8::String> source = 366 v8::Handle<v8::String> source =
367 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 367 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
368 v8::Script::Compile(source)->Run(); 368 v8::Script::Compile(source)->Run();
369 CHECK(!v8::V8::IsExecutionTerminating()); 369 CHECK(!v8::V8::IsExecutionTerminating());
370 // Check we can run JS again after termination. 370 // Check we can run JS again after termination.
371 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }" 371 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }"
372 "f()"))->Run()->IsTrue()); 372 "f()"))->Run()->IsTrue());
373 context.Dispose(context->GetIsolate()); 373 context.Dispose(context->GetIsolate());
374 } 374 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698