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 CHECK(!v8::V8::IsExecutionTerminating());
44 v8::V8::TerminateExecution();
45 return v8::Undefined();
49 v8::Handle<v8::Value> Fail(const v8::Arguments& args) {
51 return v8::Undefined();
55 v8::Handle<v8::Value> Loop(const v8::Arguments& args) {
56 CHECK(!v8::V8::IsExecutionTerminating());
57 v8::Handle<v8::String> source =
58 v8::String::New("try { doloop(); fail(); } catch(e) { fail(); }");
59 v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run();
61 CHECK(v8::V8::IsExecutionTerminating());
62 return v8::Undefined();
66 v8::Handle<v8::Value> DoLoop(const v8::Arguments& args) {
67 v8::TryCatch try_catch;
68 CHECK(!v8::V8::IsExecutionTerminating());
69 v8::Script::Compile(v8::String::New("function f() {"
86 CHECK(v8::V8::IsExecutionTerminating());
87 return v8::Undefined();
91 v8::Handle<v8::Value> DoLoopNoCall(const v8::Arguments& args) {
92 v8::TryCatch try_catch;
93 CHECK(!v8::V8::IsExecutionTerminating());
94 v8::Script::Compile(v8::String::New("var term = true;"
103 CHECK(v8::V8::IsExecutionTerminating());
104 return v8::Undefined();
108 v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate(
109 v8::InvocationCallback terminate,
110 v8::InvocationCallback doloop) {
111 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
112 global->Set(v8::String::New("terminate"),
113 v8::FunctionTemplate::New(terminate));
114 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail));
115 global->Set(v8::String::New("loop"), v8::FunctionTemplate::New(Loop));
116 global->Set(v8::String::New("doloop"), v8::FunctionTemplate::New(doloop));
124 v8::HandleScope scope;
125 v8::Handle<v8::ObjectTemplate> global =
127 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
128 v8::Context::Scope context_scope(context);
129 CHECK(!v8::V8::IsExecutionTerminating());
131 v8::Handle<v8::String> source =
132 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
133 v8::Script::Compile(source)->Run();
135 CHECK(!v8::V8::IsExecutionTerminating());
136 v8::Script::Compile(source)->Run();
144 v8::HandleScope scope;
145 v8::Handle<v8::ObjectTemplate> global =
147 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
148 v8::Context::Scope context_scope(context);
149 CHECK(!v8::V8::IsExecutionTerminating());
151 v8::Handle<v8::String> source =
152 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
153 v8::Script::Compile(source)->Run();
154 CHECK(!v8::V8::IsExecutionTerminating());
156 v8::Script::Compile(source)->Run();
161 class TerminatorThread : public v8::internal::Thread {
167 CHECK(!v8::V8::IsExecutionTerminating());
168 v8::V8::TerminateExecution();
176 semaphore = v8::internal::OS::CreateSemaphore(0);
180 v8::HandleScope scope;
181 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(Signal, DoLoop);
182 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
183 v8::Context::Scope context_scope(context);
184 CHECK(!v8::V8::IsExecutionTerminating());
186 v8::Handle<v8::String> source =
187 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
188 v8::Script::Compile(source)->Run();
197 class LoopingThread : public v8::internal::Thread {
202 v8::Locker locker;
203 v8::HandleScope scope;
204 v8_thread_id_ = v8::V8::GetCurrentThreadId();
205 v8::Handle<v8::ObjectTemplate> global =
207 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
208 v8::Context::Scope context_scope(context);
209 CHECK(!v8::V8::IsExecutionTerminating());
211 v8::Handle<v8::String> source =
212 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
213 v8::Script::Compile(source)->Run();
224 // Test that multiple threads using V8 can be terminated from another
228 v8::Locker locker;
229 v8::V8::Initialize();
230 v8::Locker::StartPreemption(1);
231 semaphore = v8::internal::OS::CreateSemaphore(0);
241 v8::Locker locker;
242 v8::V8::TerminateExecution(thread1.GetV8ThreadId());
243 v8::V8::TerminateExecution(thread2.GetV8ThreadId());
256 v8::Handle<v8::Value> TerminateOrReturnObject(const v8::Arguments& args) {
258 CHECK(!v8::V8::IsExecutionTerminating());
259 v8::V8::TerminateExecution();
260 return v8::Undefined();
262 v8::Local<v8::Object> result = v8::Object::New();
263 result->Set(v8::String::New("x"), v8::Integer::New(42));
268 v8::Handle<v8::Value> LoopGetProperty(const v8::Arguments& args) {
269 v8::TryCatch try_catch;
270 CHECK(!v8::V8::IsExecutionTerminating());
271 v8::Script::Compile(v8::String::New("function f() {"
286 CHECK(v8::V8::IsExecutionTerminating());
287 return v8::Undefined();
294 v8::HandleScope scope;
295 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
296 global->Set(v8::String::New("terminate_or_return_object"),
297 v8::FunctionTemplate::New(TerminateOrReturnObject));
298 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail));
299 global->Set(v8::String::New("loop"),
300 v8::FunctionTemplate::New(LoopGetProperty));
302 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
303 v8::Context::Scope context_scope(context);
304 CHECK(!v8::V8::IsExecutionTerminating());
306 v8::Handle<v8::String> source =
307 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
309 v8::Script::Compile(source)->Run();
311 CHECK(!v8::V8::IsExecutionTerminating());
313 v8::Script::Compile(source)->Run();
317 v8::Handle<v8::Value> ReenterAfterTermination(const v8::Arguments& args) {
318 v8::TryCatch try_catch;
319 CHECK(!v8::V8::IsExecutionTerminating());
320 v8::Script::Compile(v8::String::New("function f() {"
337 CHECK(v8::V8::IsExecutionTerminating());
338 v8::Script::Compile(v8::String::New("function f() { fail(); } f()"))->Run();
339 return v8::Undefined();
342 // Test that reentry into V8 while the termination exception is still pending
345 v8::HandleScope scope;
346 v8::Handle<v8::ObjectTemplate> global =
348 v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
349 v8::Context::Scope context_scope(context);
350 CHECK(!v8::V8::IsExecutionTerminating());
351 v8::Handle<v8::String> source =
352 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
353 v8::Script::Compile(source)->Run();
354 CHECK(!v8::V8::IsExecutionTerminating());
356 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }"