v8
3.14.5(node0.10.28)
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::Persistent< v8::Context > | CreateShellContext () |
void | RunShell (v8::Handle< v8::Context > context) |
int | RunMain (int argc, char *argv[]) |
bool | ExecuteString (v8::Handle< v8::String > source, v8::Handle< v8::Value > name, bool print_result, bool report_exceptions) |
v8::Handle< v8::Value > | Print (const v8::Arguments &args) |
v8::Handle< v8::Value > | Read (const v8::Arguments &args) |
v8::Handle< v8::Value > | Load (const v8::Arguments &args) |
v8::Handle< v8::Value > | Quit (const v8::Arguments &args) |
v8::Handle< v8::Value > | Version (const v8::Arguments &args) |
v8::Handle< v8::String > | ReadFile (const char *name) |
void | ReportException (v8::TryCatch *handler) |
int | main (int argc, char *argv[]) |
const char * | ToCString (const v8::String::Utf8Value &value) |
v8::Persistent< v8::Context > CreateShellContext | ( | ) |
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 97 of file shell.cc.
References Load(), String::New(), FunctionTemplate::New(), ObjectTemplate::New(), Context::New(), NULL, Print(), Quit(), Read(), Template::Set(), and Version().
Referenced by main().
bool ExecuteString | ( | v8::Handle< v8::String > | source, |
v8::Handle< v8::Value > | name, | ||
bool | print_result, | ||
bool | report_exceptions | ||
) |
Definition at line 270 of file shell.cc.
References Script::Compile(), TryCatch::HasCaught(), Handle< T >::IsEmpty(), Value::IsUndefined(), ReportException(), Script::Run(), and ToCString().
Referenced by Load(), RunMain(), and RunShell().
v8::Handle< v8::Value > Load | ( | const v8::Arguments & | args | ) |
Definition at line 159 of file shell.cc.
References ExecuteString(), Handle< T >::IsEmpty(), Arguments::Length(), String::New(), NULL, ReadFile(), v8::ThrowException(), and v8::Undefined().
Referenced by CreateShellContext().
int main | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 67 of file shell.cc.
References CreateShellContext(), Persistent< T >::Dispose(), V8::Dispose(), Handle< T >::IsEmpty(), RunMain(), RunShell(), and V8::SetFlagsFromCommandLine().
v8::Handle<v8::Value> Print | ( | const v8::Arguments & | args | ) |
Definition at line 118 of file shell.cc.
References Arguments::Length(), ToCString(), and v8::Undefined().
Referenced by CreateShellContext().
v8::Handle< v8::Value > Quit | ( | const v8::Arguments & | args | ) |
Definition at line 180 of file shell.cc.
References v8::Undefined().
Referenced by CreateShellContext().
v8::Handle< v8::Value > Read | ( | const v8::Arguments & | args | ) |
Definition at line 140 of file shell.cc.
References Handle< T >::IsEmpty(), Arguments::Length(), String::New(), NULL, ReadFile(), and v8::ThrowException().
Referenced by ScriptDataImpl::BuildArgs(), CreateShellContext(), ScriptDataImpl::MessageLocation(), and ScriptDataImpl::SanityCheck().
v8::Handle<v8::String> ReadFile | ( | const char * | name | ) |
void ReportException | ( | v8::TryCatch * | handler | ) |
Definition at line 305 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 | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 219 of file shell.cc.
References ExecuteString(), Handle< T >::IsEmpty(), String::New(), and ReadFile().
Referenced by main().
void RunShell | ( | v8::Handle< v8::Context > | context | ) |
Definition at line 251 of file shell.cc.
References ExecuteString(), V8::GetVersion(), String::New(), and NULL.
Referenced by main().
const char* ToCString | ( | const v8::String::Utf8Value & | value | ) |
Definition at line 90 of file shell.cc.
Referenced by ExecuteString(), Print(), and ReportException().
v8::Handle< v8::Value > Version | ( | const v8::Arguments & | args | ) |
Definition at line 191 of file shell.cc.
References V8::GetVersion(), and String::New().
Referenced by CreateShellContext().