v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lineprocessor.cc File Reference
#include <v8.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for lineprocessor.cc:

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::StringReadFile (const char *name)
 
v8::Handle< v8::StringReadLine ()
 
v8::Handle< v8::ValuePrint (const v8::Arguments &args)
 
v8::Handle< v8::ValueReadLine (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[])
 

Enumeration Type Documentation

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.

  1. The main cycle is on C++ side. Program should be run with –main-cycle-in-cpp option. Script must declare a function named "ProcessLine". The main cycle in C++ reads lines and calls this function for processing every time. This is a sample script:

function ProcessLine(input_line) { return ">>>" + input_line + "<<<"; }

  1. The main cycle is in JavaScript. Program should be run with –main-cycle-in-js option. Script gets run one time at all and gets API of 2 global functions: "read_line" and "print". It should read input and print converted lines to output itself. This a sample script:

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:

  1. Wait for remote debugger to attach Normally the program compiles custom script and immediately runs it. If programmer needs to debug script from the very beginning, he should run this sample program with "--wait-for-connection" command line parameter. This way V8 will suspend on the first statement and wait for debugger to attach.
  2. Unresponsive V8 V8 Debugger Agent holds a connection with remote debugger, but it does respond only when V8 is running some script. In particular, when this program is waiting for input, all requests from debugger get deferred until V8 is called again. See how "--callback" command-line parameter in this sample fixes this issue.
Enumerator
CycleInCpp 
CycleInJs 

Definition at line 95 of file lineprocessor.cc.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 317 of file lineprocessor.cc.

References V8::Dispose(), and RunMain().

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().

bool RunCppCycle ( v8::Handle< v8::Script script,
v8::Local< v8::Context context,
bool  report_exceptions 
)