Chromium Code Reviews| Index: samples/shell.cc |
| diff --git a/samples/shell.cc b/samples/shell.cc |
| index e9057f9e90ab523ba33929fabf755eae6222ba75..86c99036a0c9000cde972407722c2590d707154f 100644 |
| --- a/samples/shell.cc |
| +++ b/samples/shell.cc |
| @@ -47,8 +47,9 @@ |
| 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, |
| +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); |
| @@ -58,7 +59,7 @@ 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); |
| +void ReportException(v8::Isolate* isolate, v8::TryCatch* handler); |
| static bool run_shell; |
| @@ -66,20 +67,21 @@ static bool run_shell; |
| int main(int argc, char* argv[]) { |
| v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| + v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| run_shell = (argc == 1); |
| int result; |
| { |
| - v8::HandleScope handle_scope; |
| v8::Persistent<v8::Context> context = CreateShellContext(); |
| + v8::HandleScope handle_scope(isolate); |
|
Michael Starzinger
2013/03/14 19:10:26
Why was this HandleScope moved down? I think it sh
Sven Panne
2013/03/15 07:59:09
Done. Ceterum censeo shell.cc esse delendam! :-P
|
| if (context.IsEmpty()) { |
| fprintf(stderr, "Error creating context\n"); |
| return 1; |
| } |
| context->Enter(); |
| - result = RunMain(argc, argv); |
| + result = RunMain(isolate, argc, argv); |
| if (run_shell) RunShell(context); |
| context->Exit(); |
| - context.Dispose(context->GetIsolate()); |
| + context.Dispose(isolate); |
| } |
| v8::V8::Dispose(); |
| return result; |
| @@ -118,7 +120,7 @@ v8::Persistent<v8::Context> CreateShellContext() { |
| v8::Handle<v8::Value> Print(const v8::Arguments& args) { |
| bool first = true; |
| for (int i = 0; i < args.Length(); i++) { |
| - v8::HandleScope handle_scope; |
| + v8::HandleScope handle_scope(args.GetIsolate()); |
| if (first) { |
| first = false; |
| } else { |
| @@ -158,7 +160,7 @@ v8::Handle<v8::Value> Read(const v8::Arguments& args) { |
| // JavaScript file. |
| v8::Handle<v8::Value> Load(const v8::Arguments& args) { |
| for (int i = 0; i < args.Length(); i++) { |
| - v8::HandleScope handle_scope; |
| + v8::HandleScope handle_scope(args.GetIsolate()); |
| v8::String::Utf8Value file(args[i]); |
| if (*file == NULL) { |
| return v8::ThrowException(v8::String::New("Error loading file")); |
| @@ -167,7 +169,11 @@ v8::Handle<v8::Value> Load(const v8::Arguments& args) { |
| if (source.IsEmpty()) { |
| return v8::ThrowException(v8::String::New("Error loading file")); |
| } |
| - if (!ExecuteString(source, v8::String::New(*file), false, false)) { |
| + if (!ExecuteString(args.GetIsolate(), |
| + source, |
| + v8::String::New(*file), |
| + false, |
| + false)) { |
| return v8::ThrowException(v8::String::New("Error executing file")); |
| } |
| } |
| @@ -216,7 +222,7 @@ v8::Handle<v8::String> ReadFile(const char* name) { |
| // Process remaining command line arguments and execute files |
| -int RunMain(int argc, char* argv[]) { |
| +int RunMain(v8::Isolate* isolate, int argc, char* argv[]) { |
| for (int i = 1; i < argc; i++) { |
| const char* str = argv[i]; |
| if (strcmp(str, "--shell") == 0) { |
| @@ -232,7 +238,7 @@ int RunMain(int argc, char* argv[]) { |
| // Execute argument given to -e option directly. |
| v8::Handle<v8::String> file_name = v8::String::New("unnamed"); |
| v8::Handle<v8::String> source = v8::String::New(argv[++i]); |
| - if (!ExecuteString(source, file_name, false, true)) return 1; |
| + if (!ExecuteString(isolate, source, file_name, false, true)) return 1; |
| } else { |
| // Use all other arguments as names of files to load and run. |
| v8::Handle<v8::String> file_name = v8::String::New(str); |
| @@ -241,7 +247,7 @@ int RunMain(int argc, char* argv[]) { |
| fprintf(stderr, "Error reading '%s'\n", str); |
| continue; |
| } |
| - if (!ExecuteString(source, file_name, false, true)) return 1; |
| + if (!ExecuteString(isolate, source, file_name, false, true)) return 1; |
| } |
| } |
| return 0; |
| @@ -260,25 +266,30 @@ void RunShell(v8::Handle<v8::Context> context) { |
| fprintf(stderr, "> "); |
| char* str = fgets(buffer, kBufferSize, stdin); |
| if (str == NULL) break; |
| - v8::HandleScope handle_scope; |
| - ExecuteString(v8::String::New(str), name, true, true); |
| + v8::HandleScope handle_scope(context->GetIsolate()); |
| + ExecuteString(context->GetIsolate(), |
| + v8::String::New(str), |
| + name, |
| + true, |
| + true); |
| } |
| fprintf(stderr, "\n"); |
| } |
| // Executes a string within the current v8 context. |
| -bool ExecuteString(v8::Handle<v8::String> source, |
| +bool ExecuteString(v8::Isolate* isolate, |
| + v8::Handle<v8::String> source, |
| v8::Handle<v8::Value> name, |
| bool print_result, |
| bool report_exceptions) { |
| - v8::HandleScope handle_scope; |
| + v8::HandleScope handle_scope(isolate); |
| v8::TryCatch try_catch; |
| v8::Handle<v8::Script> script = v8::Script::Compile(source, name); |
| if (script.IsEmpty()) { |
| // Print errors that happened during compilation. |
| if (report_exceptions) |
| - ReportException(&try_catch); |
| + ReportException(isolate, &try_catch); |
| return false; |
| } else { |
| v8::Handle<v8::Value> result = script->Run(); |
| @@ -286,7 +297,7 @@ bool ExecuteString(v8::Handle<v8::String> source, |
| assert(try_catch.HasCaught()); |
| // Print errors that happened during execution. |
| if (report_exceptions) |
| - ReportException(&try_catch); |
| + ReportException(isolate, &try_catch); |
| return false; |
| } else { |
| assert(!try_catch.HasCaught()); |
| @@ -303,8 +314,8 @@ bool ExecuteString(v8::Handle<v8::String> source, |
| } |
| -void ReportException(v8::TryCatch* try_catch) { |
| - v8::HandleScope handle_scope; |
| +void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) { |
| + v8::HandleScope handle_scope(isolate); |
| v8::String::Utf8Value exception(try_catch->Exception()); |
| const char* exception_string = ToCString(exception); |
| v8::Handle<v8::Message> message = try_catch->Message(); |