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 v8::Handle<v8::Value> Signal(const v8::Arguments& args) {
38 return v8::Undefined();
42 v8::Handle<v8::Value> TerminateCurrentThread(const v8::Arguments& args) {
43 v8::V8::TerminateExecution();
44 return v8::Undefined();
48 v8::Handle<v8::Value> Fail(const v8::Arguments& args) {
50 return v8::Undefined();
54 v8::Handle<v8::Value> Loop(const v8::Arguments& args) {
55 v8::Handle<v8::String> source =
56 v8::String::New("try { doloop(); fail(); } catch(e) { fail(); }");
57 v8::Script::Compile(source)->Run();
58 return v8::Undefined();
62 v8::Handle<v8::Value> DoLoop(const v8::Arguments& args) {
63 v8::TryCatch try_catch;
64 v8::Script::Compile(v8::String::New("function f() {"
81 return v8::Undefined();
85 v8::Handle<v8::Value> DoLoopNoCall(const v8::Arguments& args) {
86 v8::TryCatch try_catch;
87 v8::Script::Compile(v8::String::New("var term = true;"
96 return v8::Undefined();
100 v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate(
101 v8::InvocationCallback terminate,
102 v8::InvocationCallback doloop) {
103 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
104 global->Set(v8::String::New("terminate"),
105 v8::FunctionTemplate::New(terminate));
106 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail));
107 global->Set(v8::String::New("loop"), v8::FunctionTemplate::New(Loop));
108 global->Set(v8::String::New("doloop"), v8::FunctionTemplate::New(doloop));
116 v8::HandleScope scope;
117 v8::Handle<v8::ObjectTemplate> global =
119 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
120 v8::Context::Scope context_scope(context);
122 v8::Handle<v8::String> source =
123 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
124 v8::Script::Compile(source)->Run();
126 v8::Script::Compile(source)->Run();
134 v8::HandleScope scope;
135 v8::Handle<v8::ObjectTemplate> global =
137 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
138 v8::Context::Scope context_scope(context);
140 v8::Handle<v8::String> source =
141 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
142 v8::Script::Compile(source)->Run();
144 v8::Script::Compile(source)->Run();
149 class TerminatorThread : public v8::internal::Thread {
152 v8::V8::TerminateExecution();
160 semaphore = v8::internal::OS::CreateSemaphore(0);
164 v8::HandleScope scope;
165 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(Signal, DoLoop);
166 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
167 v8::Context::Scope context_scope(context);
169 v8::Handle<v8::String> source =
170 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
171 v8::Script::Compile(source)->Run();
180 class LoopingThread : public v8::internal::Thread {
183 v8::Locker locker;
184 v8::HandleScope scope;
185 v8_thread_id_ = v8::V8::GetCurrentThreadId();
186 v8::Handle<v8::ObjectTemplate> global =
188 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
189 v8::Context::Scope context_scope(context);
191 v8::Handle<v8::String> source =
192 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
193 v8::Script::Compile(source)->Run();
204 // Test that multiple threads using V8 can be terminated from another
208 v8::Locker locker;
209 v8::V8::Initialize();
210 v8::Locker::StartPreemption(1);
211 semaphore = v8::internal::OS::CreateSemaphore(0);
221 v8::Locker locker;
222 v8::V8::TerminateExecution(thread1.GetV8ThreadId());
223 v8::V8::TerminateExecution(thread2.GetV8ThreadId());
236 v8::Handle<v8::Value> TerminateOrReturnObject(const v8::Arguments& args) {
238 v8::V8::TerminateExecution();
239 return v8::Undefined();
241 v8::Local<v8::Object> result = v8::Object::New();
242 result->Set(v8::String::New("x"), v8::Integer::New(42));
247 v8::Handle<v8::Value> LoopGetProperty(const v8::Arguments& args) {
248 v8::TryCatch try_catch;
249 v8::Script::Compile(v8::String::New("function f() {"
264 return v8::Undefined();
271 v8::HandleScope scope;
272 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
273 global->Set(v8::String::New("terminate_or_return_object"),
274 v8::FunctionTemplate::New(TerminateOrReturnObject));
275 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail));
276 global->Set(v8::String::New("loop"),
277 v8::FunctionTemplate::New(LoopGetProperty));
279 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
280 v8::Context::Scope context_scope(context);
282 v8::Handle<v8::String> source =
283 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
285 v8::Script::Compile(source)->Run();
288 v8::Script::Compile(source)->Run();