v8
3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
|
#include <v8.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
Go to the source code of this file.
Enumerations | |
enum | MainCycleType { CycleInCpp, CycleInJs } |
Functions | |
const char * | ToCString (const v8::String::Utf8Value &value) |
void | ReportException (v8::Isolate *isolate, v8::TryCatch *handler) |
v8::Handle< v8::String > | ReadFile (v8::Isolate *isolate, const char *name) |
v8::Handle< v8::String > | ReadLine () |
void | Print (const v8::FunctionCallbackInfo< v8::Value > &args) |
void | ReadLine (const v8::FunctionCallbackInfo< v8::Value > &args) |
bool | RunCppCycle (v8::Handle< v8::Script > script, v8::Local< v8::Context > context, bool report_exceptions) |
int | RunMain (int argc, char *argv[]) |
int | main (int argc, char *argv[]) |
enum MainCycleType |
This sample program should demonstrate certain aspects of debugging standalone V8-based application.
The program reads input stream, processes it line by line and print the result to output. The actual processing is done by custom JavaScript script. The script is specified with command line parameters.
The main cycle of the program will sequentially read lines from standard input, process them and print to standard output until input closes. There are 2 possible configuration in regard to main cycle.
function ProcessLine(input_line) { return ">>>" + input_line + "<<<"; }
while (true) { var line = read_line(); if (!line) { break; } var res = line + " | " + line; print(res); }
When run with "-p" argument, the program starts V8 Debugger Agent and allows remote debugger to attach and debug JavaScript code.
Interesting aspects:
Enumerator | |
---|---|
CycleInCpp | |
CycleInJs |
Definition at line 95 of file lineprocessor.cc.
int main | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 329 of file lineprocessor.cc.
References V8::Dispose(), V8::InitializeICU(), and RunMain().
void Print | ( | const v8::FunctionCallbackInfo< v8::Value > & | args | ) |
Definition at line 402 of file lineprocessor.cc.
References FunctionCallbackInfo< T >::GetIsolate(), FunctionCallbackInfo< T >::Length(), and ToCString().
Referenced by RunMain(), TEST(), Interface::Unify(), and CppByteSink::WriteSnapshot().
v8::Handle< v8::String > ReadFile | ( | v8::Isolate * | isolate, |
const char * | name | ||
) |
Definition at line 344 of file lineprocessor.cc.
References String::kNormalString, String::NewFromUtf8(), NULL, and size.
Referenced by RunMain().
v8::Handle< v8::String > ReadLine | ( | ) |
Definition at line 432 of file lineprocessor.cc.
References Handle< T >::Cast(), Isolate::GetCurrent(), String::NewFromUtf8(), NULL, and v8::Undefined().
Referenced by ReadLine(), RunCppCycle(), and RunMain().
void ReadLine | ( | const v8::FunctionCallbackInfo< v8::Value > & | args | ) |
Definition at line 422 of file lineprocessor.cc.
References FunctionCallbackInfo< T >::GetIsolate(), FunctionCallbackInfo< T >::GetReturnValue(), FunctionCallbackInfo< T >::Length(), String::NewFromUtf8(), and ReadLine().
void ReportException | ( | v8::Isolate * | isolate, |
v8::TryCatch * | handler | ||
) |
Definition at line 366 of file lineprocessor.cc.
References TryCatch::Exception(), Message::GetEndColumn(), Message::GetLineNumber(), Message::GetScriptResourceName(), Message::GetSourceLine(), Message::GetStartColumn(), Handle< T >::IsEmpty(), message, TryCatch::Message(), and ToCString().
Referenced by RunCppCycle(), and RunMain().
bool RunCppCycle | ( | v8::Handle< v8::Script > | script, |
v8::Local< v8::Context > | context, | ||
bool | report_exceptions | ||
) |
Definition at line 274 of file lineprocessor.cc.
References Function::Call(), Handle< T >::Cast(), Isolate::GetCurrentContext(), Context::GetIsolate(), Context::Global(), TryCatch::HasCaught(), Value::IsFunction(), String::NewFromUtf8(), ReadLine(), ReportException(), ToCString(), and v8::Undefined().
Referenced by RunMain().
int RunMain | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 138 of file lineprocessor.cc.
References Script::Compile(), CycleInCpp, CycleInJs, Debug::EnableAgent(), Isolate::GetCurrent(), Isolate::GetCurrentContext(), TryCatch::HasCaught(), Handle< T >::IsEmpty(), FunctionTemplate::New(), ObjectTemplate::New(), Context::New(), String::NewFromUtf8(), NULL, Print(), ReadFile(), ReadLine(), ReportException(), PersistentBase< T >::Reset(), Script::Run(), RunCppCycle(), Template::Set(), Debug::SetDebugMessageDispatchHandler(), and V8::SetFlagsFromCommandLine().
Referenced by Shell::Main(), and main().
const char * ToCString | ( | const v8::String::Utf8Value & | value | ) |
Definition at line 338 of file lineprocessor.cc.
Referenced by Logger::ApiNamedPropertyAccess(), Logger::ApiNamedSecurityCheck(), Isolate::DoThrow(), Print(), ReportException(), Shell::ReportException(), and RunCppCycle().