Home | History | Annotate | Download | only in samples

Lines Matching refs:V8

1 // Copyright 2009 the V8 project authors. All rights reserved.
28 #include <v8.h>
29 #include <v8-debug.h>
37 * standalone V8-based application.
72 * When run with "-p" argument, the program starts V8 Debugger Agent and
80 * This way V8 will suspend on the first statement and wait for
83 * 2. Unresponsive V8
84 * V8 Debugger Agent holds a connection with remote debugger, but it does
85 * respond only when V8 is running some script. In particular, when this program
86 * is waiting for input, all requests from debugger get deferred until V8
96 const char* ToCString(const v8::String::Utf8Value& value);
97 void ReportException(v8::TryCatch* handler);
98 v8::Handle<v8::String> ReadFile(const char* name);
99 v8::Handle<v8::String> ReadLine();
101 v8::Handle<v8::Value> Print(const v8::Arguments& args);
102 v8::Handle<v8::Value> ReadLine(const v8::Arguments& args);
103 bool RunCppCycle(v8::Handle<v8::Script> script, v8::Local<v8::Context> context,
106 v8::Persistent<v8::Context> debug_message_context;
110 // We are in some random thread. We should already have v8::Locker acquired
117 // We should decide which V8 context to use here. This is important for
121 v8::Context::Scope scope(debug_message_context);
123 v8::Debug::ProcessDebugMessages();
128 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
129 v8::HandleScope handle_scope;
131 v8::Handle<v8::String> script_source(NULL);
132 v8::Handle<v8::Value> script_name(NULL);
160 script_source = v8::String::New(argv[i + 1]);
161 script_name = v8::String::New("unnamed");
167 script_name = v8::String::New(str);
186 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
189 global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print));
193 global->Set(v8::String::New("read_line"),
194 v8::FunctionTemplate::New(ReadLine));
199 v8::Handle<v8::Context> context = v8::Context::New(NULL, global);
200 debug_message_context = v8::Persistent<v8::Context>::New(context);
204 v8::Context::Scope context_scope(context);
206 v8::Locker locker;
209 v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true);
214 v8::V8::SetFlagsFromString(auto_break_param, strlen(auto_break_param));
215 v8::Debug::EnableAgent("lineprocessor", port_number, wait_for_connection);
220 v8::Handle<v8::Script> script;
223 v8::TryCatch try_catch;
224 script = v8::Script::Compile(script_source, script_name);
234 v8::TryCatch try_catch;
245 bool res = RunCppCycle(script, v8::Context::GetCurrent(),
255 bool RunCppCycle(v8::Handle<v8::Script> script, v8::Local<v8::Context> context,
257 v8::Locker lock;
259 v8::Handle<v8::String> fun_name = v8::String::New("ProcessLine");
260 v8::Handle<v8::Value> process_val =
261 v8::Context::GetCurrent()->Global()->Get(fun_name);
271 v8::Handle<v8::Function> process_fun =
272 v8::Handle<v8::Function>::Cast(process_val);
276 v8::HandleScope handle_scope;
278 v8::Handle<v8::String> input_line = ReadLine();
279 if (input_line == v8::Undefined()) {
284 v8::Handle<v8::Value> argv[argc] = { input_line };
286 v8::Handle<v8::Value> result;
288 v8::TryCatch try_catch;
289 result = process_fun->Call(v8::Context::GetCurrent()->Global(),
297 v8::String::Utf8Value str(result);
307 v8::V8::Dispose();
312 // Extracts a C string from a V8 Utf8Value.
313 const char* ToCString(const v8::String::Utf8Value& value) {
318 // Reads a file into a v8 string.
319 v8::Handle<v8::String> ReadFile(const char* name) {
321 if (file == NULL) return v8::Handle<v8::String>();
334 v8::Handle<v8::String> result = v8::String::New(chars, size);
340 void ReportException(v8::TryCatch* try_catch) {
341 v8::HandleScope handle_scope;
342 v8::String::Utf8Value exception(try_catch->Exception());
344 v8::Handle<v8::Message> message = try_catch->Message();
346 // V8 didn't provide any extra information about this error; just
351 v8::String::Utf8Value filename(message->GetScriptResourceName());
356 v8::String::Utf8Value sourceline(message->GetSourceLine());
373 // The callback that is invoked by v8 whenever the JavaScript 'print'
376 v8::Handle<v8::Value> Print(const v8::Arguments& args) {
379 v8::HandleScope handle_scope;
385 v8::String::Utf8Value str(args[i]);
391 return v8::Undefined();
395 // The callback that is invoked by v8 whenever the JavaScript 'read_line'
397 v8::Handle<v8::Value> ReadLine(const v8::Arguments& args) {
399 return v8::ThrowException(v8::String::New("Unexpected arguments"));
404 v8::Handle<v8::String> ReadLine() {
410 v8::Unlocker unlocker;
414 v8::Handle<v8::Primitive> t = v8::Undefined();
415 return reinterpret_cast<v8::Handle<v8::String>&>(t);
424 return v8::String::New(buffer);