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

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

Issue 12033011: Add Isolate parameter to Persistent class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added explicit Created 7 years, 10 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
« no previous file with comments | « test/cctest/test-serialize.cc ('k') | test/cctest/test-weakmaps.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(); 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;
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());
155 // Test that we can run the code again after thread termination. 155 // Test that we can run the code again after thread termination.
156 v8::Script::Compile(source)->Run(); 156 v8::Script::Compile(source)->Run();
157 context.Dispose(); 157 context.Dispose(context->GetIsolate());
158 } 158 }
159 159
160 160
161 class TerminatorThread : public v8::internal::Thread { 161 class TerminatorThread : public v8::internal::Thread {
162 public: 162 public:
163 explicit TerminatorThread(i::Isolate* isolate) 163 explicit TerminatorThread(i::Isolate* isolate)
164 : Thread("TerminatorThread"), 164 : Thread("TerminatorThread"),
165 isolate_(reinterpret_cast<v8::Isolate*>(isolate)) { } 165 isolate_(reinterpret_cast<v8::Isolate*>(isolate)) { }
166 void Run() { 166 void Run() {
167 semaphore->Wait(); 167 semaphore->Wait();
(...skipping 19 matching lines...) Expand all
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(); 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;
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();
217 context.Dispose(); 217 context.Dispose(context->GetIsolate());
218 } 218 }
219 219
220 int GetV8ThreadId() { return v8_thread_id_; } 220 int GetV8ThreadId() { return v8_thread_id_; }
221 221
222 private: 222 private:
223 int v8_thread_id_; 223 int v8_thread_id_;
224 }; 224 };
225 225
226 226
227 // Test that multiple threads using default isolate can be terminated 227 // Test that multiple threads using default isolate can be terminated
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 CHECK(!v8::V8::IsExecutionTerminating()); 319 CHECK(!v8::V8::IsExecutionTerminating());
320 // Run a loop that will be infinite if thread termination does not work. 320 // Run a loop that will be infinite if thread termination does not work.
321 v8::Handle<v8::String> source = 321 v8::Handle<v8::String> source =
322 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); 322 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
323 call_count = 0; 323 call_count = 0;
324 v8::Script::Compile(source)->Run(); 324 v8::Script::Compile(source)->Run();
325 // Test that we can run the code again after thread termination. 325 // Test that we can run the code again after thread termination.
326 CHECK(!v8::V8::IsExecutionTerminating()); 326 CHECK(!v8::V8::IsExecutionTerminating());
327 call_count = 0; 327 call_count = 0;
328 v8::Script::Compile(source)->Run(); 328 v8::Script::Compile(source)->Run();
329 context.Dispose(); 329 context.Dispose(context->GetIsolate());
330 } 330 }
331 331
332 v8::Handle<v8::Value> ReenterAfterTermination(const v8::Arguments& args) { 332 v8::Handle<v8::Value> ReenterAfterTermination(const v8::Arguments& args) {
333 v8::TryCatch try_catch; 333 v8::TryCatch try_catch;
334 CHECK(!v8::V8::IsExecutionTerminating()); 334 CHECK(!v8::V8::IsExecutionTerminating());
335 v8::Script::Compile(v8::String::New("function f() {" 335 v8::Script::Compile(v8::String::New("function f() {"
336 " var term = true;" 336 " var term = true;"
337 " try {" 337 " try {"
338 " while(true) {" 338 " while(true) {"
339 " if (term) terminate();" 339 " if (term) terminate();"
(...skipping 23 matching lines...) Expand all
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(); 373 context.Dispose(context->GetIsolate());
374 } 374 }
OLDNEW
« no previous file with comments | « test/cctest/test-serialize.cc ('k') | test/cctest/test-weakmaps.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698