v8  3.25.30(node0.11.13)
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::Isolate *isolate, v8::TryCatch *handler)
 
v8::Handle< v8::StringReadFile (v8::Isolate *isolate, const char *name)
 
v8::Handle< v8::StringReadLine ()
 
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[])
 

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 329 of file lineprocessor.cc.

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

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