Home | History | Annotate | Download | only in cctest

Lines Matching refs:V8

1 // Copyright 2009 the V8 project authors. All rights reserved.
28 #include "v8.h"
33 v8::internal::Semaphore* semaphore = NULL;
36 void Signal(const v8::FunctionCallbackInfo<v8::Value>& args) {
41 void TerminateCurrentThread(const v8::FunctionCallbackInfo<v8::Value>& args) {
42 CHECK(!v8::V8::IsExecutionTerminating());
43 v8::V8::TerminateExecution();
47 void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) {
52 void Loop(const v8::FunctionCallbackInfo<v8::Value>& args) {
53 CHECK(!v8::V8::IsExecutionTerminating());
54 v8::Handle<v8::String> source =
55 v8::String::New("try { doloop(); fail(); } catch(e) { fail(); }");
56 v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run();
58 CHECK(v8::V8::IsExecutionTerminating());
62 void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) {
63 v8::TryCatch try_catch;
64 CHECK(!v8::V8::IsExecutionTerminating());
65 v8::Script::Compile(v8::String::New("function f() {"
82 CHECK(v8::V8::IsExecutionTerminating());
86 void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) {
87 v8::TryCatch try_catch;
88 CHECK(!v8::V8::IsExecutionTerminating());
89 v8::Script::Compile(v8::String::New("var term = true;"
98 CHECK(v8::V8::IsExecutionTerminating());
102 v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate(
103 v8::FunctionCallback terminate,
104 v8::FunctionCallback doloop) {
105 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
106 global->Set(v8::String::New("terminate"),
107 v8::FunctionTemplate::New(terminate));
108 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail));
109 global->Set(v8::String::New("loop"), v8::FunctionTemplate::New(Loop));
110 global->Set(v8::String::New("doloop"), v8::FunctionTemplate::New(doloop));
118 v8::HandleScope scope(v8::Isolate::GetCurrent());
119 v8::Handle<v8::ObjectTemplate> global =
121 v8::Handle<v8::Context> context =
122 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
123 v8::Context::Scope context_scope(context);
124 CHECK(!v8::V8::IsExecutionTerminating());
126 v8::Handle<v8::String> source =
127 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
128 v8::Script::Compile(source)->Run();
130 CHECK(!v8::V8::IsExecutionTerminating());
131 v8::Script::Compile(source)->Run();
138 v8::HandleScope scope(v8::Isolate::GetCurrent());
139 v8::Handle<v8::ObjectTemplate> global =
141 v8::Handle<v8::Context> context =
142 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
143 v8::Context::Scope context_scope(context);
144 CHECK(!v8::V8::IsExecutionTerminating());
146 v8::Handle<v8::String> source =
147 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
148 v8::Script::Compile(source)->Run();
149 CHECK(!v8::V8::IsExecutionTerminating());
151 v8::Script::Compile(source)->Run();
155 class TerminatorThread : public v8::internal::Thread {
159 isolate_(reinterpret_cast<v8::Isolate*>(isolate)) { }
162 CHECK(!v8::V8::IsExecutionTerminating(isolate_));
163 v8::V8::TerminateExecution(isolate_);
167 v8::Isolate* isolate_;
174 semaphore = v8::internal::OS::CreateSemaphore(0);
178 v8::HandleScope scope(v8::Isolate::GetCurrent());
179 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(Signal, DoLoop);
180 v8::Handle<v8::Context> context =
181 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
182 v8::Context::Scope context_scope(context);
183 CHECK(!v8::V8::IsExecutionTerminating());
185 v8::Handle<v8::String> source =
186 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
187 v8::Script::Compile(source)->Run();
195 class LoopingThread : public v8::internal::Thread {
199 v8::Locker locker(CcTest::default_isolate());
200 v8::HandleScope scope(CcTest::default_isolate());
201 v8_thread_id_ = v8::V8::GetCurrentThreadId();
202 v8::Handle<v8::ObjectTemplate> global =
204 v8::Handle<v8::Context> context =
205 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
206 v8::Context::Scope context_scope(context);
207 CHECK(!v8::V8::IsExecutionTerminating());
209 v8::Handle<v8::String> source =
210 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
211 v8::Script::Compile(source)->Run();
225 v8::Locker locker(CcTest::default_isolate());
226 v8::V8::Initialize();
227 v8::Locker::StartPreemption(1);
228 semaphore = v8::internal::OS::CreateSemaphore(0);
243 v8::Locker locker(CcTest::default_isolate());
245 v8::V8::TerminateExecution(threads[i]->GetV8ThreadId());
253 v8::Locker locker(CcTest::default_isolate());
254 v8::Locker::StopPreemption();
265 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) {
267 CHECK(!v8::V8::IsExecutionTerminating());
268 v8::V8::TerminateExecution();
271 v8::Local<v8::Object> result = v8::Object::New();
272 result->Set(v8::String::New("x"), v8::Integer::New(42));
277 void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) {
278 v8::TryCatch try_catch;
279 CHECK(!v8::V8::IsExecutionTerminating());
280 v8::Script::Compile(v8::String::New("function f() {"
295 CHECK(v8::V8::IsExecutionTerminating());
302 v8::HandleScope scope(v8::Isolate::GetCurrent());
303 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
304 global->Set(v8::String::New("terminate_or_return_object"),
305 v8::FunctionTemplate::New(TerminateOrReturnObject));
306 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail));
307 global->Set(v8::String::New("loop"),
308 v8::FunctionTemplate::New(LoopGetProperty));
310 v8::Handle<v8::Context> context =
311 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
312 v8::Context::Scope context_scope(context);
313 CHECK(!v8::V8::IsExecutionTerminating());
315 v8::Handle<v8::String> source =
316 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
318 v8::Script::Compile(source)->Run();
320 CHECK(!v8::V8::IsExecutionTerminating());
322 v8::Script::Compile(source)->Run();
326 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) {
327 v8::TryCatch try_catch;
328 CHECK(!v8::V8::IsExecutionTerminating());
329 v8::Script::Compile(v8::String::New("function f() {"
346 CHECK(v8::V8::IsExecutionTerminating());
347 v8::Script::Compile(v8::String::New("function f() { fail(); } f()"))->Run();
351 // Test that reentry into V8 while the termination exception is still pending
354 v8::HandleScope scope(v8::Isolate::GetCurrent());
355 v8::Handle<v8::ObjectTemplate> global =
357 v8::Handle<v8::Context> context =
358 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
359 v8::Context::Scope context_scope(context);
360 CHECK(!v8::V8::IsExecutionTerminating());
361 v8::Handle<v8::String> source =
362 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
363 v8::Script::Compile(source)->Run();
364 CHECK(!v8::V8::IsExecutionTerminating());
366 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }"
371 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
372 v8::TryCatch try_catch;
373 CHECK(!v8::V8::IsExecutionTerminating());
374 v8::Script::Compile(v8::String::New("var term = true;"
384 CHECK(v8::V8::IsExecutionTerminating());
386 v8::V8::CancelTerminateExecution(v8::Isolate::GetCurrent());
387 CHECK(!v8::V8::IsExecutionTerminating());
394 v8::HandleScope scope;
395 v8::Handle<v8::ObjectTemplate> global =
397 v8::Handle<v8::Context> context =
398 v8::Context::New(v8::Isolate::GetCurrent(), NULL, global);
399 v8::Context::Scope context_scope(context);
400 CHECK(!v8::V8::IsExecutionTerminating());
401 v8::Handle<v8::String> source =
402 v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';");
404 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed")));