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

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

Issue 179062: Fix the handling of termination exceptions thrown when creating error... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 3 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 | « src/top.cc ('k') | no next file » | 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 v8::Locker locker; 186 v8::Locker locker;
187 v8::V8::TerminateExecution(thread1.GetV8ThreadId()); 187 v8::V8::TerminateExecution(thread1.GetV8ThreadId());
188 v8::V8::TerminateExecution(thread2.GetV8ThreadId()); 188 v8::V8::TerminateExecution(thread2.GetV8ThreadId());
189 } 189 }
190 thread1.Join(); 190 thread1.Join();
191 thread2.Join(); 191 thread2.Join();
192 192
193 delete semaphore; 193 delete semaphore;
194 semaphore = NULL; 194 semaphore = NULL;
195 } 195 }
196
197
198 int call_count = 0;
199
200
201 v8::Handle<v8::Value> TerminateOrReturnObject(const v8::Arguments& args) {
202 if (++call_count == 10) {
203 v8::V8::TerminateExecution();
204 return v8::Undefined();
205 }
206 v8::Local<v8::Object> result = v8::Object::New();
207 result->Set(v8::String::New("x"), v8::Integer::New(42));
208 return result;
209 }
210
211
212 v8::Handle<v8::Value> LoopGetProperty(const v8::Arguments& args) {
213 v8::TryCatch try_catch;
214 v8::Script::Compile(v8::String::New("function f() {"
215 " try {"
216 " while(true) {"
217 " terminate_or_return_object().x;"
218 " }"
219 " fail();"
220 " } catch(e) {"
221 " fail();"
222 " }"
223 "}"
224 "f()"))->Run();
225 CHECK(try_catch.HasCaught());
226 CHECK(try_catch.Exception()->IsNull());
227 CHECK(try_catch.Message().IsEmpty());
228 CHECK(!try_catch.CanContinue());
229 return v8::Undefined();
230 }
231
232
233 // Test that we correctly handle termination exceptions if they are
234 // triggered by the creation of error objects in connection with ICs.
235 TEST(TerminateLoadICException) {
236 v8::HandleScope scope;
237 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
238 global->Set(v8::String::New("terminate_or_return_object"),
239 v8::FunctionTemplate::New(TerminateOrReturnObject));
240 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail));
241 global->Set(v8::String::New("loop"),
242 v8::FunctionTemplate::New(LoopGetProperty));
243
244 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
245 v8::Context::Scope context_scope(context);
246 // Run a loop that will be infinite if thread termination does not work.
247 v8::Handle<v8::String> source =
248 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
249 call_count = 0;
250 v8::Script::Compile(source)->Run();
251 // Test that we can run the code again after thread termination.
252 call_count = 0;
253 v8::Script::Compile(source)->Run();
254 context.Dispose();
255 }
OLDNEW
« no previous file with comments | « src/top.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698