v8
3.14.5(node0.10.28)
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::TryCatch *handler) |
v8::Handle< v8::String > | ReadFile (const char *name) |
v8::Handle< v8::String > | ReadLine () |
v8::Handle< v8::Value > | Print (const v8::Arguments &args) |
v8::Handle< v8::Value > | ReadLine (const v8::Arguments &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 317 of file lineprocessor.cc.
References V8::Dispose(), and RunMain().
v8::Handle< v8::Value > Print | ( | const v8::Arguments & | args | ) |
Definition at line 388 of file lineprocessor.cc.
References Arguments::Length(), ToCString(), and v8::Undefined().
Referenced by Heap::GarbageCollectionEpilogue(), Heap::GarbageCollectionPrologue(), JSObject::NormalizeElements(), JSObject::NormalizeProperties(), RunMain(), JSObject::SetDictionaryElement(), TEST(), ToBooleanStub::Types::TraceTransition(), Interface::Unify(), and CppByteSink::WriteSnapshot().
v8::Handle< v8::String > ReadFile | ( | const char * | name | ) |
Definition at line 331 of file lineprocessor.cc.
References String::New(), and NULL.
Referenced by RunMain().
v8::Handle< v8::String > ReadLine | ( | ) |
Definition at line 416 of file lineprocessor.cc.
References String::Cast(), String::New(), NULL, and v8::Undefined().
Referenced by ReadLine(), RunCppCycle(), and RunMain().
v8::Handle< v8::Value > ReadLine | ( | const v8::Arguments & | args | ) |
Definition at line 409 of file lineprocessor.cc.
References Arguments::Length(), String::New(), ReadLine(), and v8::ThrowException().
void ReportException | ( | v8::TryCatch * | handler | ) |
Definition at line 352 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 265 of file lineprocessor.cc.
References Function::Call(), Handle< T >::Cast(), Context::GetCurrent(), TryCatch::HasCaught(), Value::IsFunction(), String::New(), ReadLine(), ReportException(), ToCString(), and v8::Undefined().
Referenced by RunMain().
int RunMain | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 133 of file lineprocessor.cc.
References Script::Compile(), CycleInCpp, CycleInJs, Debug::EnableAgent(), Context::GetCurrent(), TryCatch::HasCaught(), Handle< T >::IsEmpty(), Persistent< T >::New(), String::New(), FunctionTemplate::New(), ObjectTemplate::New(), Context::New(), NULL, Print(), ReadFile(), ReadLine(), ReportException(), Script::Run(), RunCppCycle(), Template::Set(), Debug::SetDebugMessageDispatchHandler(), and V8::SetFlagsFromCommandLine().
Referenced by main().
const char * ToCString | ( | const v8::String::Utf8Value & | value | ) |
Definition at line 325 of file lineprocessor.cc.
Referenced by SharedFunctionInfo::DisableOptimization(), Isolate::DoThrow(), Print(), LStoreNamedField::PrintDataTo(), LStoreNamedGeneric::PrintDataTo(), LTypeofIsAndBranch::PrintDataTo(), HLoadNamedFieldPolymorphic::PrintDataTo(), HLoadNamedGeneric::PrintDataTo(), HStoreNamedField::PrintDataTo(), HStoreNamedGeneric::PrintDataTo(), ReportException(), RunCppCycle(), and String::ToCString().