v8
3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
|
#include <v8.h>
#include <assert.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
Go to the source code of this file.
Functions | |
v8::Handle< v8::Context > | CreateShellContext (v8::Isolate *isolate) |
void | RunShell (v8::Handle< v8::Context > context) |
int | RunMain (v8::Isolate *isolate, int argc, char *argv[]) |
bool | ExecuteString (v8::Isolate *isolate, v8::Handle< v8::String > source, v8::Handle< v8::Value > name, bool print_result, bool report_exceptions) |
void | Print (const v8::FunctionCallbackInfo< v8::Value > &args) |
void | Read (const v8::FunctionCallbackInfo< v8::Value > &args) |
void | Load (const v8::FunctionCallbackInfo< v8::Value > &args) |
void | Quit (const v8::FunctionCallbackInfo< v8::Value > &args) |
void | Version (const v8::FunctionCallbackInfo< v8::Value > &args) |
v8::Handle< v8::String > | ReadFile (v8::Isolate *isolate, const char *name) |
void | ReportException (v8::Isolate *isolate, v8::TryCatch *handler) |
int | main (int argc, char *argv[]) |
const char * | ToCString (const v8::String::Utf8Value &value) |
v8::Handle< v8::Context > CreateShellContext | ( | v8::Isolate * | isolate | ) |
This sample program shows how to implement a simple javascript shell based on V8. This includes initializing V8 with command line options, creating global functions, compiling and executing strings.
For a more sophisticated shell, consider using the debug shell D8.
Definition at line 99 of file shell.cc.
References Load(), FunctionTemplate::New(), ObjectTemplate::New(), Context::New(), String::NewFromUtf8(), NULL, Print(), Quit(), Read(), Template::Set(), and Version().
Referenced by main().
bool ExecuteString | ( | v8::Isolate * | isolate, |
v8::Handle< v8::String > | source, | ||
v8::Handle< v8::Value > | name, | ||
bool | print_result, | ||
bool | report_exceptions | ||
) |
Definition at line 300 of file shell.cc.
References Script::Compile(), TryCatch::HasCaught(), Handle< T >::IsEmpty(), Value::IsUndefined(), ReportException(), Script::Run(), and ToCString().
Referenced by Load(), Shell::Load(), RunMain(), and RunShell().
void Load | ( | const v8::FunctionCallbackInfo< v8::Value > & | args | ) |
Definition at line 171 of file shell.cc.
References ExecuteString(), FunctionCallbackInfo< T >::GetIsolate(), Handle< T >::IsEmpty(), FunctionCallbackInfo< T >::Length(), String::NewFromUtf8(), NULL, and ReadFile().
Referenced by CreateShellContext(), and TEST().
int main | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 68 of file shell.cc.
References CreateShellContext(), V8::Dispose(), Context::Enter(), Context::Exit(), Isolate::GetCurrent(), V8::InitializeICU(), Handle< T >::IsEmpty(), RunMain(), RunShell(), and V8::SetFlagsFromCommandLine().
void Print | ( | const v8::FunctionCallbackInfo< v8::Value > & | args | ) |
Definition at line 125 of file shell.cc.
References FunctionCallbackInfo< T >::GetIsolate(), FunctionCallbackInfo< T >::Length(), and ToCString().
Referenced by CreateShellContext().
void Quit | ( | const v8::FunctionCallbackInfo< v8::Value > & | args | ) |
Definition at line 201 of file shell.cc.
Referenced by CreateShellContext().
void Read | ( | const v8::FunctionCallbackInfo< v8::Value > & | args | ) |
Definition at line 146 of file shell.cc.
References FunctionCallbackInfo< T >::GetIsolate(), FunctionCallbackInfo< T >::GetReturnValue(), Handle< T >::IsEmpty(), FunctionCallbackInfo< T >::Length(), String::NewFromUtf8(), NULL, and ReadFile().
Referenced by CreateShellContext().
v8::Handle<v8::String> ReadFile | ( | v8::Isolate * | isolate, |
const char * | name | ||
) |
Definition at line 218 of file shell.cc.
References String::kNormalString, String::NewFromUtf8(), NULL, and size.
void ReportException | ( | v8::Isolate * | isolate, |
v8::TryCatch * | handler | ||
) |
Definition at line 337 of file shell.cc.
References TryCatch::Exception(), Message::GetEndColumn(), Message::GetLineNumber(), Message::GetScriptResourceName(), Message::GetSourceLine(), Message::GetStartColumn(), Handle< T >::IsEmpty(), message, TryCatch::Message(), TryCatch::StackTrace(), and ToCString().
Referenced by ExecuteString().
int RunMain | ( | v8::Isolate * | isolate, |
int | argc, | ||
char * | argv[] | ||
) |
Definition at line 241 of file shell.cc.
References ExecuteString(), Handle< T >::IsEmpty(), String::NewFromUtf8(), and ReadFile().
Referenced by main().
void RunShell | ( | v8::Handle< v8::Context > | context | ) |
Definition at line 276 of file shell.cc.
References ExecuteString(), Context::GetIsolate(), V8::GetVersion(), name, String::NewFromUtf8(), and NULL.
Referenced by main(), and Shell::Main().
const char* ToCString | ( | const v8::String::Utf8Value & | value | ) |
Definition at line 92 of file shell.cc.
Referenced by ExecuteString(), Print(), and ReportException().
void Version | ( | const v8::FunctionCallbackInfo< v8::Value > & | args | ) |
Definition at line 211 of file shell.cc.
References FunctionCallbackInfo< T >::GetIsolate(), FunctionCallbackInfo< T >::GetReturnValue(), V8::GetVersion(), and String::NewFromUtf8().
Referenced by CreateShellContext().