Revision f230a1cf deps/v8/test/cctest/test-thread-termination.cc
deps/v8/test/cctest/test-thread-termination.cc | ||
---|---|---|
39 | 39 |
|
40 | 40 |
|
41 | 41 |
void TerminateCurrentThread(const v8::FunctionCallbackInfo<v8::Value>& args) { |
42 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
43 |
v8::V8::TerminateExecution(); |
|
42 |
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
43 |
v8::V8::TerminateExecution(args.GetIsolate());
|
|
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
|
... | ... | |
50 | 50 |
|
51 | 51 |
|
52 | 52 |
void Loop(const v8::FunctionCallbackInfo<v8::Value>& args) { |
53 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
53 |
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
54 | 54 |
v8::Handle<v8::String> source = |
55 | 55 |
v8::String::New("try { doloop(); fail(); } catch(e) { fail(); }"); |
56 | 56 |
v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run(); |
57 | 57 |
CHECK(result.IsEmpty()); |
58 |
CHECK(v8::V8::IsExecutionTerminating()); |
|
58 |
CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
|
62 | 62 |
void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) { |
63 | 63 |
v8::TryCatch try_catch; |
64 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
64 |
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
65 | 65 |
v8::Script::Compile(v8::String::New("function f() {" |
66 | 66 |
" var term = true;" |
67 | 67 |
" try {" |
... | ... | |
79 | 79 |
CHECK(try_catch.Exception()->IsNull()); |
80 | 80 |
CHECK(try_catch.Message().IsEmpty()); |
81 | 81 |
CHECK(!try_catch.CanContinue()); |
82 |
CHECK(v8::V8::IsExecutionTerminating()); |
|
82 |
CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
|
86 | 86 |
void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) { |
87 | 87 |
v8::TryCatch try_catch; |
88 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
88 |
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
89 | 89 |
v8::Script::Compile(v8::String::New("var term = true;" |
90 | 90 |
"while(true) {" |
91 | 91 |
" if (term) terminate();" |
... | ... | |
95 | 95 |
CHECK(try_catch.Exception()->IsNull()); |
96 | 96 |
CHECK(try_catch.Message().IsEmpty()); |
97 | 97 |
CHECK(!try_catch.CanContinue()); |
98 |
CHECK(v8::V8::IsExecutionTerminating()); |
|
98 |
CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
99 | 99 |
} |
100 | 100 |
|
101 | 101 |
|
... | ... | |
115 | 115 |
// Test that a single thread of JavaScript execution can terminate |
116 | 116 |
// itself. |
117 | 117 |
TEST(TerminateOnlyV8ThreadFromThreadItself) { |
118 |
v8::HandleScope scope(v8::Isolate::GetCurrent());
|
|
118 |
v8::HandleScope scope(CcTest::isolate());
|
|
119 | 119 |
v8::Handle<v8::ObjectTemplate> global = |
120 | 120 |
CreateGlobalTemplate(TerminateCurrentThread, DoLoop); |
121 | 121 |
v8::Handle<v8::Context> context = |
122 |
v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
|
|
122 |
v8::Context::New(CcTest::isolate(), NULL, global);
|
|
123 | 123 |
v8::Context::Scope context_scope(context); |
124 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
124 |
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
|
125 | 125 |
// Run a loop that will be infinite if thread termination does not work. |
126 | 126 |
v8::Handle<v8::String> source = |
127 | 127 |
v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); |
128 | 128 |
v8::Script::Compile(source)->Run(); |
129 | 129 |
// Test that we can run the code again after thread termination. |
130 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
130 |
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
|
131 | 131 |
v8::Script::Compile(source)->Run(); |
132 | 132 |
} |
133 | 133 |
|
... | ... | |
135 | 135 |
// Test that a single thread of JavaScript execution can terminate |
136 | 136 |
// itself in a loop that performs no calls. |
137 | 137 |
TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) { |
138 |
v8::HandleScope scope(v8::Isolate::GetCurrent());
|
|
138 |
v8::HandleScope scope(CcTest::isolate());
|
|
139 | 139 |
v8::Handle<v8::ObjectTemplate> global = |
140 | 140 |
CreateGlobalTemplate(TerminateCurrentThread, DoLoopNoCall); |
141 | 141 |
v8::Handle<v8::Context> context = |
142 |
v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
|
|
142 |
v8::Context::New(CcTest::isolate(), NULL, global);
|
|
143 | 143 |
v8::Context::Scope context_scope(context); |
144 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
144 |
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
|
145 | 145 |
// Run a loop that will be infinite if thread termination does not work. |
146 | 146 |
v8::Handle<v8::String> source = |
147 | 147 |
v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); |
148 | 148 |
v8::Script::Compile(source)->Run(); |
149 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
149 |
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
|
150 | 150 |
// Test that we can run the code again after thread termination. |
151 | 151 |
v8::Script::Compile(source)->Run(); |
152 | 152 |
} |
... | ... | |
172 | 172 |
// from the side by another thread. |
173 | 173 |
TEST(TerminateOnlyV8ThreadFromOtherThread) { |
174 | 174 |
semaphore = new v8::internal::Semaphore(0); |
175 |
TerminatorThread thread(i::Isolate::Current());
|
|
175 |
TerminatorThread thread(CcTest::i_isolate());
|
|
176 | 176 |
thread.Start(); |
177 | 177 |
|
178 |
v8::HandleScope scope(v8::Isolate::GetCurrent());
|
|
178 |
v8::HandleScope scope(CcTest::isolate());
|
|
179 | 179 |
v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(Signal, DoLoop); |
180 | 180 |
v8::Handle<v8::Context> context = |
181 |
v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
|
|
181 |
v8::Context::New(CcTest::isolate(), NULL, global);
|
|
182 | 182 |
v8::Context::Scope context_scope(context); |
183 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
183 |
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
|
184 | 184 |
// Run a loop that will be infinite if thread termination does not work. |
185 | 185 |
v8::Handle<v8::String> source = |
186 | 186 |
v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); |
... | ... | |
197 | 197 |
|
198 | 198 |
void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) { |
199 | 199 |
if (++call_count == 10) { |
200 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
201 |
v8::V8::TerminateExecution(); |
|
200 |
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
201 |
v8::V8::TerminateExecution(args.GetIsolate());
|
|
202 | 202 |
return; |
203 | 203 |
} |
204 | 204 |
v8::Local<v8::Object> result = v8::Object::New(); |
... | ... | |
209 | 209 |
|
210 | 210 |
void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) { |
211 | 211 |
v8::TryCatch try_catch; |
212 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
212 |
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
213 | 213 |
v8::Script::Compile(v8::String::New("function f() {" |
214 | 214 |
" try {" |
215 | 215 |
" while(true) {" |
... | ... | |
225 | 225 |
CHECK(try_catch.Exception()->IsNull()); |
226 | 226 |
CHECK(try_catch.Message().IsEmpty()); |
227 | 227 |
CHECK(!try_catch.CanContinue()); |
228 |
CHECK(v8::V8::IsExecutionTerminating()); |
|
228 |
CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
229 | 229 |
} |
230 | 230 |
|
231 | 231 |
|
232 | 232 |
// Test that we correctly handle termination exceptions if they are |
233 | 233 |
// triggered by the creation of error objects in connection with ICs. |
234 | 234 |
TEST(TerminateLoadICException) { |
235 |
v8::HandleScope scope(v8::Isolate::GetCurrent());
|
|
235 |
v8::HandleScope scope(CcTest::isolate());
|
|
236 | 236 |
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); |
237 | 237 |
global->Set(v8::String::New("terminate_or_return_object"), |
238 | 238 |
v8::FunctionTemplate::New(TerminateOrReturnObject)); |
... | ... | |
241 | 241 |
v8::FunctionTemplate::New(LoopGetProperty)); |
242 | 242 |
|
243 | 243 |
v8::Handle<v8::Context> context = |
244 |
v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
|
|
244 |
v8::Context::New(CcTest::isolate(), NULL, global);
|
|
245 | 245 |
v8::Context::Scope context_scope(context); |
246 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
246 |
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
|
247 | 247 |
// Run a loop that will be infinite if thread termination does not work. |
248 | 248 |
v8::Handle<v8::String> source = |
249 | 249 |
v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); |
250 | 250 |
call_count = 0; |
251 | 251 |
v8::Script::Compile(source)->Run(); |
252 | 252 |
// Test that we can run the code again after thread termination. |
253 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
253 |
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
|
254 | 254 |
call_count = 0; |
255 | 255 |
v8::Script::Compile(source)->Run(); |
256 | 256 |
} |
... | ... | |
258 | 258 |
|
259 | 259 |
void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { |
260 | 260 |
v8::TryCatch try_catch; |
261 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
261 |
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
262 | 262 |
v8::Script::Compile(v8::String::New("function f() {" |
263 | 263 |
" var term = true;" |
264 | 264 |
" try {" |
... | ... | |
276 | 276 |
CHECK(try_catch.Exception()->IsNull()); |
277 | 277 |
CHECK(try_catch.Message().IsEmpty()); |
278 | 278 |
CHECK(!try_catch.CanContinue()); |
279 |
CHECK(v8::V8::IsExecutionTerminating()); |
|
279 |
CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
280 | 280 |
v8::Script::Compile(v8::String::New("function f() { fail(); } f()"))->Run(); |
281 | 281 |
} |
282 | 282 |
|
... | ... | |
284 | 284 |
// Test that reentry into V8 while the termination exception is still pending |
285 | 285 |
// (has not yet unwound the 0-level JS frame) does not crash. |
286 | 286 |
TEST(TerminateAndReenterFromThreadItself) { |
287 |
v8::HandleScope scope(v8::Isolate::GetCurrent());
|
|
287 |
v8::HandleScope scope(CcTest::isolate());
|
|
288 | 288 |
v8::Handle<v8::ObjectTemplate> global = |
289 | 289 |
CreateGlobalTemplate(TerminateCurrentThread, ReenterAfterTermination); |
290 | 290 |
v8::Handle<v8::Context> context = |
291 |
v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
|
|
291 |
v8::Context::New(CcTest::isolate(), NULL, global);
|
|
292 | 292 |
v8::Context::Scope context_scope(context); |
293 | 293 |
CHECK(!v8::V8::IsExecutionTerminating()); |
294 | 294 |
v8::Handle<v8::String> source = |
295 | 295 |
v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); |
296 | 296 |
v8::Script::Compile(source)->Run(); |
297 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
297 |
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
|
298 | 298 |
// Check we can run JS again after termination. |
299 | 299 |
CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }" |
300 | 300 |
"f()"))->Run()->IsTrue()); |
... | ... | |
316 | 316 |
CHECK(!try_catch.CanContinue()); |
317 | 317 |
CHECK(v8::V8::IsExecutionTerminating()); |
318 | 318 |
CHECK(try_catch.HasTerminated()); |
319 |
v8::V8::CancelTerminateExecution(v8::Isolate::GetCurrent());
|
|
319 |
v8::V8::CancelTerminateExecution(CcTest::isolate());
|
|
320 | 320 |
CHECK(!v8::V8::IsExecutionTerminating()); |
321 | 321 |
} |
322 | 322 |
|
... | ... | |
324 | 324 |
// Test that a single thread of JavaScript execution can terminate |
325 | 325 |
// itself and then resume execution. |
326 | 326 |
TEST(TerminateCancelTerminateFromThreadItself) { |
327 |
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
327 |
v8::Isolate* isolate = CcTest::isolate();
|
|
328 | 328 |
v8::HandleScope scope(isolate); |
329 | 329 |
v8::Handle<v8::ObjectTemplate> global = |
330 | 330 |
CreateGlobalTemplate(TerminateCurrentThread, DoLoopCancelTerminate); |
331 | 331 |
v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); |
332 | 332 |
v8::Context::Scope context_scope(context); |
333 |
CHECK(!v8::V8::IsExecutionTerminating()); |
|
333 |
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
|
334 | 334 |
v8::Handle<v8::String> source = |
335 | 335 |
v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';"); |
336 | 336 |
// Check that execution completed with correct return value. |
Also available in: Unified diff