Home | History | Annotate | Download | only in samples

Lines Matching refs:v8

1 // Copyright 2009 the V8 project authors. All rights reserved.
32 // Note that V8 itself should be compiled with enabled debugger support
36 #include <v8.h>
39 #include <v8-debug.h>
49 * standalone V8-based application.
84 * When run with "-p" argument, the program starts V8 Debugger Agent and
92 * This way V8 will suspend on the first statement and wait for
95 * 2. Unresponsive V8
96 * V8 Debugger Agent holds a connection with remote debugger, but it does
97 * respond only when V8 is running some script. In particular, when this program
98 * is waiting for input, all requests from debugger get deferred until V8
108 const char* ToCString(const v8::String::Utf8Value& value);
109 void ReportException(v8::TryCatch* handler);
110 v8::Handle<v8::String> ReadFile(const char* name);
111 v8::Handle<v8::String> ReadLine();
113 v8::Handle<v8::Value> Print(const v8::Arguments& args);
114 v8::Handle<v8::Value> ReadLine(const v8::Arguments& args);
115 bool RunCppCycle(v8::Handle<v8::Script> script, v8::Local<v8::Context> context,
120 v8::Persistent<v8::Context> debug_message_context;
123 // We are in some random thread. We should already have v8::Locker acquired
130 // We should decide which V8 context to use here. This is important for
134 v8::Context::Scope scope(debug_message_context);
136 v8::Debug::ProcessDebugMessages();
142 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
143 v8::HandleScope handle_scope;
145 v8::Handle<v8::String> script_source(NULL);
146 v8::Handle<v8::Value> script_name(NULL);
179 script_source = v8::String::New(argv[i + 1]);
180 script_name = v8::String::New("unnamed");
186 script_name = v8::String::New(str);
205 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
208 global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print));
212 global->Set(v8::String::New("read_line"),
213 v8::FunctionTemplate::New(ReadLine));
218 v8::Handle<v8::Context> context = v8::Context::New(NULL, global);
220 v8::Context::Scope context_scope(context);
223 debug_message_context = v8::Persistent<v8::Context>::New(context);
225 v8::Locker locker;
228 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true);
232 v8::Debug::EnableAgent("lineprocessor", port_number, wait_for_connection);
238 v8::Handle<v8::Script> script;
241 v8::TryCatch try_catch;
242 script = v8::Script::Compile(script_source, script_name);
252 v8::TryCatch try_catch;
263 bool res = RunCppCycle(script, v8::Context::GetCurrent(),
273 bool RunCppCycle(v8::Handle<v8::Script> script, v8::Local<v8::Context> context,
276 v8::Locker lock;
279 v8::Handle<v8::String> fun_name = v8::String::New("ProcessLine");
280 v8::Handle<v8::Value> process_val =
281 v8::Context::GetCurrent()->Global()->Get(fun_name);
291 v8::Handle<v8::Function> process_fun =
292 v8::Handle<v8::Function>::Cast(process_val);
296 v8::HandleScope handle_scope;
298 v8::Handle<v8::String> input_line = ReadLine();
299 if (input_line == v8::Undefined()) {
304 v8::Handle<v8::Value> argv[argc] = { input_line };
306 v8::Handle<v8::Value> result;
308 v8::TryCatch try_catch;
309 result = process_fun->Call(v8::Context::GetCurrent()->Global(),
317 v8::String::Utf8Value str(result);
327 v8::V8::Dispose();
332 // Extracts a C string from a V8 Utf8Value.
333 const char* ToCString(const v8::String::Utf8Value& value) {
338 // Reads a file into a v8 string.
339 v8::Handle<v8::String> ReadFile(const char* name) {
341 if (file == NULL) return v8::Handle<v8::String>();
354 v8::Handle<v8::String> result = v8::String::New(chars, size);
360 void ReportException(v8::TryCatch* try_catch) {
361 v8::HandleScope handle_scope;
362 v8::String::Utf8Value exception(try_catch->Exception());
364 v8::Handle<v8::Message> message = try_catch->Message();
366 // V8 didn't provide any extra information about this error; just
371 v8::String::Utf8Value filename(message->GetScriptResourceName());
376 v8::String::Utf8Value sourceline(message->GetSourceLine());
393 // The callback that is invoked by v8 whenever the JavaScript 'print'
396 v8::Handle<v8::Value> Print(const v8::Arguments& args) {
399 v8::HandleScope handle_scope;
405 v8::String::Utf8Value str(args[i]);
411 return v8::Undefined();
415 // The callback that is invoked by v8 whenever the JavaScript 'read_line'
417 v8::Handle<v8::Value> ReadLine(const v8::Arguments& args) {
419 return v8::ThrowException(v8::String::New("Unexpected arguments"));
424 v8::Handle<v8::String> ReadLine() {
431 v8::Unlocker unlocker;
436 v8::Handle<v8::Primitive> t = v8::Undefined();
437 return reinterpret_cast<v8::Handle<v8::String>&>(t);
446 return v8::String::New(buffer);