int Fragment::Script::ScriptEngine::Init(int argc, char* argv[]) { v8::V8::InitializeICU(); v8::V8::InitializeExternalStartupData(argv[0]); v8::Platform *platform = v8::platform::CreateDefaultPlatform(); v8::V8::InitializePlatform(platform); v8::V8::Initialize(); v8::V8::SetFlagsFromCommandLine(&argc, argv, true); ShellArrayBufferAllocator array_buffer_allocator; v8::Isolate::CreateParams create_params; create_params.array_buffer_allocator = &array_buffer_allocator; v8::Isolate *isolate = v8::Isolate::New(create_params); run_shell = (argc == 1); int result; { v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> context = CreateShellContext(isolate); if (context.IsEmpty()) { fprintf(stderr, "Error creating context\n"); return 1; } v8::Context::Scope context_scope(context); result = RunMain(isolate, platform, argc, argv); if (run_shell) RunShell(context, platform); } isolate->Dispose(); v8::V8::Dispose(); v8::V8::ShutdownPlatform(); delete platform; return result; }
int main(int argc, char** argv) { /* Prepare runtime environment */ GWBE_Environment* env = gwbe_NewEnvironment(); RunShell(env); return 0; }
int Shell::runMain(int argc, char* argv[]) { V8::SetFlagsFromCommandLine(&argc, argv, true); HandleScope handle_scope; // Create a new execution environment containing the built-in // functions Context::Scope context_scope(globalContext); bool run_shell = (argc == 1); for (int i = 1; i < argc; i++) { const char* str = argv[i]; if (strcmp(str, "--shell") == 0) { run_shell = true; } else if (strcmp(str, "-f") == 0) { // Ignore any -f flags for compatibility with the other stand- // alone JavaScript engines. continue; } else if (strncmp(str, "--", 2) == 0) { printf("Warning: unknown flag %s.\nTry --help for options\n", str); } else if (strcmp(str, "-e") == 0 && i + 1 < argc) { // Execute argument given to -e option directly HandleScope handle_scope; Handle<String> file_name = String::New("unnamed"); Handle<String> source = String::New(argv[i + 1]); if (!ExecuteString(source, file_name, false, true)) return 1; i++; } else { // Use all other arguments as names of files to load and run. HandleScope handle_scope; Handle<String> file_name = String::New(str); Handle<String> source = ReadFile(str); if (source.IsEmpty()) { printf("Error reading '%s'\n", str); return 1; } if (!ExecuteString(source, file_name, false, true)) return 1; } } if (run_shell) RunShell(globalContext); return(0); }