From d180390f7f44e95a0808d0cd67da71504f63d864 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 20 Jul 2015 00:05:42 -0700 Subject: [PATCH] Reland of "Make d8 stop using to-be-deprecated APIs" Original issue's description: > BUG=v8:4134 > LOG=n > R=yangguo@chromium.org > > Review URL: https://codereview.chromium.org/1239053004 BUG=v8:4134 LOG=n R=yangguo@chromium.org Review URL: https://codereview.chromium.org/1235603004 Cr-Commit-Position: refs/heads/master@{#29742} --- src/d8-debug.cc | 77 +++++--- src/d8-posix.cc | 209 +++++++++++++------- src/d8-readline.cc | 14 +- src/d8-windows.cc | 3 +- src/d8.cc | 555 ++++++++++++++++++++++++++++++++--------------------- src/d8.gyp | 4 + src/d8.h | 35 ++-- 7 files changed, 556 insertions(+), 341 deletions(-) diff --git a/src/d8-debug.cc b/src/d8-debug.cc index a356bd4..e0090bb 100644 --- a/src/d8-debug.cc +++ b/src/d8-debug.cc @@ -29,24 +29,30 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) { // Get the toJSONProtocol function on the event and get the JSON format. Local to_json_fun_name = - String::NewFromUtf8(isolate, "toJSONProtocol"); - Handle event_data = event_details.GetEventData(); + String::NewFromUtf8(isolate, "toJSONProtocol", NewStringType::kNormal) + .ToLocalChecked(); + Local event_data = event_details.GetEventData(); Local to_json_fun = - Local::Cast(event_data->Get(to_json_fun_name)); - Local event_json = to_json_fun->Call(event_data, 0, NULL); - if (try_catch.HasCaught()) { + Local::Cast(event_data->Get(isolate->GetCurrentContext(), + to_json_fun_name).ToLocalChecked()); + Local event_json; + if (!to_json_fun->Call(isolate->GetCurrentContext(), event_data, 0, NULL) + .ToLocal(&event_json)) { Shell::ReportException(isolate, &try_catch); return; } // Print the event details. - Handle details = - Shell::DebugMessageDetails(isolate, Handle::Cast(event_json)); + Local details = + Shell::DebugMessageDetails(isolate, Local::Cast(event_json)); if (try_catch.HasCaught()) { Shell::ReportException(isolate, &try_catch); return; } - String::Utf8Value str(details->Get(String::NewFromUtf8(isolate, "text"))); + String::Utf8Value str( + details->Get(isolate->GetCurrentContext(), + String::NewFromUtf8(isolate, "text", NewStringType::kNormal) + .ToLocalChecked()).ToLocalChecked()); if (str.length() == 0) { // Empty string is used to signal not to process this event. return; @@ -55,15 +61,18 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) { // Get the debug command processor. Local fun_name = - String::NewFromUtf8(isolate, "debugCommandProcessor"); - Handle exec_state = event_details.GetExecutionState(); - Local fun = Local::Cast(exec_state->Get(fun_name)); - Local cmd_processor = - Local::Cast(fun->Call(exec_state, 0, NULL)); - if (try_catch.HasCaught()) { + String::NewFromUtf8(isolate, "debugCommandProcessor", + NewStringType::kNormal).ToLocalChecked(); + Local exec_state = event_details.GetExecutionState(); + Local fun = Local::Cast( + exec_state->Get(isolate->GetCurrentContext(), fun_name).ToLocalChecked()); + Local cmd_processor_value; + if (!fun->Call(isolate->GetCurrentContext(), exec_state, 0, NULL) + .ToLocal(&cmd_processor_value)) { Shell::ReportException(isolate, &try_catch); return; } + Local cmd_processor = Local::Cast(cmd_processor_value); static const int kBufferSize = 256; bool running = false; @@ -79,8 +88,9 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) { TryCatch try_catch(isolate); // Convert the debugger command to a JSON debugger request. - Handle request = Shell::DebugCommandToJSONRequest( - isolate, String::NewFromUtf8(isolate, command)); + Local request = Shell::DebugCommandToJSONRequest( + isolate, String::NewFromUtf8(isolate, command, NewStringType::kNormal) + .ToLocalChecked()); if (try_catch.HasCaught()) { Shell::ReportException(isolate, &try_catch); continue; @@ -92,39 +102,50 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) { continue; } - Handle fun_name; - Handle fun; + Local fun_name; + Local fun; // All the functions used below take one argument. static const int kArgc = 1; - Handle args[kArgc]; + Local args[kArgc]; // Invoke the JavaScript to convert the debug command line to a JSON // request, invoke the JSON request and convert the JSON respose to a text // representation. - fun_name = String::NewFromUtf8(isolate, "processDebugRequest"); - fun = Handle::Cast(cmd_processor->Get(fun_name)); + fun_name = String::NewFromUtf8(isolate, "processDebugRequest", + NewStringType::kNormal).ToLocalChecked(); + fun = Local::Cast(cmd_processor->Get(isolate->GetCurrentContext(), + fun_name).ToLocalChecked()); args[0] = request; - Handle response_val = fun->Call(cmd_processor, kArgc, args); - if (try_catch.HasCaught()) { + Local response_val; + if (!fun->Call(isolate->GetCurrentContext(), cmd_processor, kArgc, args) + .ToLocal(&response_val)) { Shell::ReportException(isolate, &try_catch); continue; } - Handle response = Handle::Cast(response_val); + Local response = Local::Cast(response_val); // Convert the debugger response into text details and the running state. - Handle response_details = + Local response_details = Shell::DebugMessageDetails(isolate, response); if (try_catch.HasCaught()) { Shell::ReportException(isolate, &try_catch); continue; } String::Utf8Value text_str( - response_details->Get(String::NewFromUtf8(isolate, "text"))); + response_details->Get(isolate->GetCurrentContext(), + String::NewFromUtf8(isolate, "text", + NewStringType::kNormal) + .ToLocalChecked()).ToLocalChecked()); if (text_str.length() > 0) { printf("%s\n", *text_str); } - running = response_details->Get(String::NewFromUtf8(isolate, "running")) - ->ToBoolean(isolate) + running = response_details->Get(isolate->GetCurrentContext(), + String::NewFromUtf8(isolate, "running", + NewStringType::kNormal) + .ToLocalChecked()) + .ToLocalChecked() + ->ToBoolean(isolate->GetCurrentContext()) + .ToLocalChecked() ->Value(); } } diff --git a/src/d8-posix.cc b/src/d8-posix.cc index 3bca14f..36d83b5 100644 --- a/src/d8-posix.cc +++ b/src/d8-posix.cc @@ -170,12 +170,14 @@ class ExecArgs { ExecArgs() { exec_args_[0] = NULL; } - bool Init(Isolate* isolate, Handle arg0, Handle command_args) { + bool Init(Isolate* isolate, Local arg0, Local command_args) { String::Utf8Value prog(arg0); if (*prog == NULL) { const char* message = "os.system(): String conversion of program name failed"; - isolate->ThrowException(String::NewFromUtf8(isolate, message)); + isolate->ThrowException( + String::NewFromUtf8(isolate, message, NewStringType::kNormal) + .ToLocalChecked()); return false; } int len = prog.length() + 3; @@ -184,13 +186,17 @@ class ExecArgs { exec_args_[0] = c_arg; int i = 1; for (unsigned j = 0; j < command_args->Length(); i++, j++) { - Handle arg(command_args->Get(Integer::New(isolate, j))); + Local arg( + command_args->Get(isolate->GetCurrentContext(), + Integer::New(isolate, j)).ToLocalChecked()); String::Utf8Value utf8_arg(arg); if (*utf8_arg == NULL) { exec_args_[i] = NULL; // Consistent state for destructor. const char* message = "os.system(): String conversion of argument failed."; - isolate->ThrowException(String::NewFromUtf8(isolate, message)); + isolate->ThrowException( + String::NewFromUtf8(isolate, message, NewStringType::kNormal) + .ToLocalChecked()); return false; } int len = utf8_arg.length() + 1; @@ -225,19 +231,27 @@ static bool GetTimeouts(const v8::FunctionCallbackInfo& args, int* total_timeout) { if (args.Length() > 3) { if (args[3]->IsNumber()) { - *total_timeout = args[3]->Int32Value(); + *total_timeout = args[3] + ->Int32Value(args.GetIsolate()->GetCurrentContext()) + .FromJust(); } else { - args.GetIsolate()->ThrowException(String::NewFromUtf8( - args.GetIsolate(), "system: Argument 4 must be a number")); + args.GetIsolate()->ThrowException( + String::NewFromUtf8(args.GetIsolate(), + "system: Argument 4 must be a number", + NewStringType::kNormal).ToLocalChecked()); return false; } } if (args.Length() > 2) { if (args[2]->IsNumber()) { - *read_timeout = args[2]->Int32Value(); + *read_timeout = args[2] + ->Int32Value(args.GetIsolate()->GetCurrentContext()) + .FromJust(); } else { - args.GetIsolate()->ThrowException(String::NewFromUtf8( - args.GetIsolate(), "system: Argument 3 must be a number")); + args.GetIsolate()->ThrowException( + String::NewFromUtf8(args.GetIsolate(), + "system: Argument 3 must be a number", + NewStringType::kNormal).ToLocalChecked()); return false; } } @@ -282,7 +296,9 @@ static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) { bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err)); } while (bytes_read == -1 && errno == EINTR); if (bytes_read != 0) { - isolate->ThrowException(String::NewFromUtf8(isolate, strerror(err))); + isolate->ThrowException( + String::NewFromUtf8(isolate, strerror(err), NewStringType::kNormal) + .ToLocalChecked()); return false; } return true; @@ -291,12 +307,10 @@ static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) { // Accumulates the output from the child in a string handle. Returns true if it // succeeded or false if an exception was thrown. -static Handle GetStdout(Isolate* isolate, - int child_fd, - const struct timeval& start_time, - int read_timeout, - int total_timeout) { - Handle accumulator = String::Empty(isolate); +static Local GetStdout(Isolate* isolate, int child_fd, + const struct timeval& start_time, + int read_timeout, int total_timeout) { + Local accumulator = String::Empty(isolate); int fullness = 0; static const int kStdoutReadBufferSize = 4096; @@ -304,7 +318,8 @@ static Handle GetStdout(Isolate* isolate, if (fcntl(child_fd, F_SETFL, O_NONBLOCK) != 0) { return isolate->ThrowException( - String::NewFromUtf8(isolate, strerror(errno))); + String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal) + .ToLocalChecked()); } int bytes_read; @@ -319,7 +334,8 @@ static Handle GetStdout(Isolate* isolate, start_time) || (TimeIsOut(start_time, total_timeout))) { return isolate->ThrowException( - String::NewFromUtf8(isolate, "Timed out waiting for output")); + String::NewFromUtf8(isolate, "Timed out waiting for output", + NewStringType::kNormal).ToLocalChecked()); } continue; } else if (errno == EINTR) { @@ -332,8 +348,9 @@ static Handle GetStdout(Isolate* isolate, int length = bytes_read == 0 ? bytes_read + fullness : LengthWithoutIncompleteUtf8(buffer, bytes_read + fullness); - Handle addition = - String::NewFromUtf8(isolate, buffer, String::kNormalString, length); + Local addition = + String::NewFromUtf8(isolate, buffer, NewStringType::kNormal, length) + .ToLocalChecked(); accumulator = String::Concat(accumulator, addition); fullness = bytes_read + fullness - length; memcpy(buffer, buffer + length, fullness); @@ -380,8 +397,10 @@ static bool WaitForChild(Isolate* isolate, if (useconds < 1000000) useconds <<= 1; if ((read_timeout != -1 && useconds / 1000 > read_timeout) || (TimeIsOut(start_time, total_timeout))) { - isolate->ThrowException(String::NewFromUtf8( - isolate, "Timed out waiting for process to terminate")); + isolate->ThrowException( + String::NewFromUtf8(isolate, + "Timed out waiting for process to terminate", + NewStringType::kNormal).ToLocalChecked()); kill(pid, SIGINT); return false; } @@ -392,7 +411,9 @@ static bool WaitForChild(Isolate* isolate, sizeof(message), "Child killed by signal %d", child_info.si_status); - isolate->ThrowException(String::NewFromUtf8(isolate, message)); + isolate->ThrowException( + String::NewFromUtf8(isolate, message, NewStringType::kNormal) + .ToLocalChecked()); return false; } if (child_info.si_code == CLD_EXITED && child_info.si_status != 0) { @@ -401,7 +422,9 @@ static bool WaitForChild(Isolate* isolate, sizeof(message), "Child exited with status %d", child_info.si_status); - isolate->ThrowException(String::NewFromUtf8(isolate, message)); + isolate->ThrowException( + String::NewFromUtf8(isolate, message, NewStringType::kNormal) + .ToLocalChecked()); return false; } @@ -416,7 +439,9 @@ static bool WaitForChild(Isolate* isolate, sizeof(message), "Child killed by signal %d", WTERMSIG(child_status)); - isolate->ThrowException(String::NewFromUtf8(isolate, message)); + isolate->ThrowException( + String::NewFromUtf8(isolate, message, NewStringType::kNormal) + .ToLocalChecked()); return false; } if (WEXITSTATUS(child_status) != 0) { @@ -426,7 +451,9 @@ static bool WaitForChild(Isolate* isolate, sizeof(message), "Child exited with status %d", exit_status); - isolate->ThrowException(String::NewFromUtf8(isolate, message)); + isolate->ThrowException( + String::NewFromUtf8(isolate, message, NewStringType::kNormal) + .ToLocalChecked()); return false; } @@ -442,25 +469,29 @@ void Shell::System(const v8::FunctionCallbackInfo& args) { int read_timeout = -1; int total_timeout = -1; if (!GetTimeouts(args, &read_timeout, &total_timeout)) return; - Handle command_args; + Local command_args; if (args.Length() > 1) { if (!args[1]->IsArray()) { - args.GetIsolate()->ThrowException(String::NewFromUtf8( - args.GetIsolate(), "system: Argument 2 must be an array")); + args.GetIsolate()->ThrowException( + String::NewFromUtf8(args.GetIsolate(), + "system: Argument 2 must be an array", + NewStringType::kNormal).ToLocalChecked()); return; } - command_args = Handle::Cast(args[1]); + command_args = Local::Cast(args[1]); } else { command_args = Array::New(args.GetIsolate(), 0); } if (command_args->Length() > ExecArgs::kMaxArgs) { - args.GetIsolate()->ThrowException(String::NewFromUtf8( - args.GetIsolate(), "Too many arguments to system()")); + args.GetIsolate()->ThrowException( + String::NewFromUtf8(args.GetIsolate(), "Too many arguments to system()", + NewStringType::kNormal).ToLocalChecked()); return; } if (args.Length() < 1) { - args.GetIsolate()->ThrowException(String::NewFromUtf8( - args.GetIsolate(), "Too few arguments to system()")); + args.GetIsolate()->ThrowException( + String::NewFromUtf8(args.GetIsolate(), "Too few arguments to system()", + NewStringType::kNormal).ToLocalChecked()); return; } @@ -476,12 +507,14 @@ void Shell::System(const v8::FunctionCallbackInfo& args) { if (pipe(exec_error_fds) != 0) { args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.")); + String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.", + NewStringType::kNormal).ToLocalChecked()); return; } if (pipe(stdout_fds) != 0) { args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.")); + String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.", + NewStringType::kNormal).ToLocalChecked()); return; } @@ -500,11 +533,8 @@ void Shell::System(const v8::FunctionCallbackInfo& args) { if (!ChildLaunchedOK(args.GetIsolate(), exec_error_fds)) return; - Handle accumulator = GetStdout(args.GetIsolate(), - stdout_fds[kReadFD], - start_time, - read_timeout, - total_timeout); + Local accumulator = GetStdout(args.GetIsolate(), stdout_fds[kReadFD], + start_time, read_timeout, total_timeout); if (accumulator->IsUndefined()) { kill(pid, SIGINT); // On timeout, kill the subprocess. args.GetReturnValue().Set(accumulator); @@ -528,19 +558,22 @@ void Shell::ChangeDirectory(const v8::FunctionCallbackInfo& args) { if (args.Length() != 1) { const char* message = "chdir() takes one argument"; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } String::Utf8Value directory(args[0]); if (*directory == NULL) { const char* message = "os.chdir(): String conversion of argument failed."; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } if (chdir(*directory) != 0) { args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), strerror(errno))); + String::NewFromUtf8(args.GetIsolate(), strerror(errno), + NewStringType::kNormal).ToLocalChecked()); return; } } @@ -550,7 +583,8 @@ void Shell::SetUMask(const v8::FunctionCallbackInfo& args) { if (args.Length() != 1) { const char* message = "umask() takes one argument"; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } if (args[0]->IsNumber()) { @@ -558,14 +592,16 @@ void Shell::SetUMask(const v8::FunctionCallbackInfo& args) { // PNaCL has no support for umask. int previous = 0; #else - int previous = umask(args[0]->Int32Value()); + int previous = umask( + args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust()); #endif args.GetReturnValue().Set(previous); return; } else { const char* message = "umask() argument must be numeric"; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } } @@ -575,11 +611,15 @@ static bool CheckItsADirectory(Isolate* isolate, char* directory) { struct stat stat_buf; int stat_result = stat(directory, &stat_buf); if (stat_result != 0) { - isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno))); + isolate->ThrowException( + String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal) + .ToLocalChecked()); return false; } if ((stat_buf.st_mode & S_IFDIR) != 0) return true; - isolate->ThrowException(String::NewFromUtf8(isolate, strerror(EEXIST))); + isolate->ThrowException( + String::NewFromUtf8(isolate, strerror(EEXIST), NewStringType::kNormal) + .ToLocalChecked()); return false; } @@ -594,7 +634,9 @@ static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) { } else if (errno == ENOENT) { // Intermediate path element is missing. char* last_slash = strrchr(directory, '/'); if (last_slash == NULL) { - isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno))); + isolate->ThrowException( + String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal) + .ToLocalChecked()); return false; } *last_slash = 0; @@ -605,10 +647,14 @@ static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) { if (errno == EEXIST) { return CheckItsADirectory(isolate, directory); } - isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno))); + isolate->ThrowException( + String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal) + .ToLocalChecked()); return false; } else { - isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno))); + isolate->ThrowException( + String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal) + .ToLocalChecked()); return false; } } @@ -618,24 +664,29 @@ void Shell::MakeDirectory(const v8::FunctionCallbackInfo& args) { mode_t mask = 0777; if (args.Length() == 2) { if (args[1]->IsNumber()) { - mask = args[1]->Int32Value(); + mask = args[1] + ->Int32Value(args.GetIsolate()->GetCurrentContext()) + .FromJust(); } else { const char* message = "mkdirp() second argument must be numeric"; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, + NewStringType::kNormal).ToLocalChecked()); return; } } else if (args.Length() != 1) { const char* message = "mkdirp() takes one or two arguments"; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } String::Utf8Value directory(args[0]); if (*directory == NULL) { const char* message = "os.mkdirp(): String conversion of argument failed."; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } mkdirp(args.GetIsolate(), *directory, mask); @@ -646,14 +697,16 @@ void Shell::RemoveDirectory(const v8::FunctionCallbackInfo& args) { if (args.Length() != 1) { const char* message = "rmdir() takes one or two arguments"; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } String::Utf8Value directory(args[0]); if (*directory == NULL) { const char* message = "os.rmdir(): String conversion of argument failed."; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } rmdir(*directory); @@ -664,7 +717,8 @@ void Shell::SetEnvironment(const v8::FunctionCallbackInfo& args) { if (args.Length() != 2) { const char* message = "setenv() takes two arguments"; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } String::Utf8Value var(args[0]); @@ -673,14 +727,16 @@ void Shell::SetEnvironment(const v8::FunctionCallbackInfo& args) { const char* message = "os.setenv(): String conversion of variable name failed."; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } if (*value == NULL) { const char* message = "os.setenv(): String conversion of variable contents failed."; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } setenv(*var, *value, 1); @@ -691,7 +747,8 @@ void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo& args) { if (args.Length() != 1) { const char* message = "unsetenv() takes one argument"; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } String::Utf8Value var(args[0]); @@ -699,27 +756,35 @@ void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo& args) { const char* message = "os.setenv(): String conversion of variable name failed."; args.GetIsolate()->ThrowException( - String::NewFromUtf8(args.GetIsolate(), message)); + String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal) + .ToLocalChecked()); return; } unsetenv(*var); } -void Shell::AddOSMethods(Isolate* isolate, Handle os_templ) { - os_templ->Set(String::NewFromUtf8(isolate, "system"), +void Shell::AddOSMethods(Isolate* isolate, Local os_templ) { + os_templ->Set(String::NewFromUtf8(isolate, "system", NewStringType::kNormal) + .ToLocalChecked(), FunctionTemplate::New(isolate, System)); - os_templ->Set(String::NewFromUtf8(isolate, "chdir"), + os_templ->Set(String::NewFromUtf8(isolate, "chdir", NewStringType::kNormal) + .ToLocalChecked(), FunctionTemplate::New(isolate, ChangeDirectory)); - os_templ->Set(String::NewFromUtf8(isolate, "setenv"), + os_templ->Set(String::NewFromUtf8(isolate, "setenv", NewStringType::kNormal) + .ToLocalChecked(), FunctionTemplate::New(isolate, SetEnvironment)); - os_templ->Set(String::NewFromUtf8(isolate, "unsetenv"), + os_templ->Set(String::NewFromUtf8(isolate, "unsetenv", NewStringType::kNormal) + .ToLocalChecked(), FunctionTemplate::New(isolate, UnsetEnvironment)); - os_templ->Set(String::NewFromUtf8(isolate, "umask"), + os_templ->Set(String::NewFromUtf8(isolate, "umask", NewStringType::kNormal) + .ToLocalChecked(), FunctionTemplate::New(isolate, SetUMask)); - os_templ->Set(String::NewFromUtf8(isolate, "mkdirp"), + os_templ->Set(String::NewFromUtf8(isolate, "mkdirp", NewStringType::kNormal) + .ToLocalChecked(), FunctionTemplate::New(isolate, MakeDirectory)); - os_templ->Set(String::NewFromUtf8(isolate, "rmdir"), + os_templ->Set(String::NewFromUtf8(isolate, "rmdir", NewStringType::kNormal) + .ToLocalChecked(), FunctionTemplate::New(isolate, RemoveDirectory)); } diff --git a/src/d8-readline.cc b/src/d8-readline.cc index 39c93d3..eca6553 100644 --- a/src/d8-readline.cc +++ b/src/d8-readline.cc @@ -25,7 +25,7 @@ namespace v8 { class ReadLineEditor: public LineEditor { public: ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { } - virtual Handle Prompt(const char* prompt); + virtual Local Prompt(const char* prompt); virtual bool Open(Isolate* isolate); virtual bool Close(); virtual void AddHistory(const char* str); @@ -80,10 +80,10 @@ bool ReadLineEditor::Close() { } -Handle ReadLineEditor::Prompt(const char* prompt) { +Local ReadLineEditor::Prompt(const char* prompt) { char* result = NULL; result = readline(prompt); - if (result == NULL) return Handle(); + if (result == NULL) return Local(); AddHistory(result); return String::NewFromUtf8(isolate_, result); } @@ -118,10 +118,10 @@ char** ReadLineEditor::AttemptedCompletion(const char* text, char* ReadLineEditor::CompletionGenerator(const char* text, int state) { static unsigned current_index; - static Persistent current_completions; + static Global current_completions; Isolate* isolate = read_line_editor.isolate_; HandleScope scope(isolate); - Handle completions; + Local completions; if (state == 0) { Local full_text = String::NewFromUtf8(isolate, rl_line_buffer, @@ -136,8 +136,8 @@ char* ReadLineEditor::CompletionGenerator(const char* text, int state) { completions = Local::New(isolate, current_completions); } if (current_index < completions->Length()) { - Handle index = Integer::New(isolate, current_index); - Handle str_obj = completions->Get(index); + Local index = Integer::New(isolate, current_index); + Local str_obj = completions->Get(index); current_index++; String::Utf8Value str(str_obj); return strdup(*str); diff --git a/src/d8-windows.cc b/src/d8-windows.cc index 06c0a4e..ba89c41 100644 --- a/src/d8-windows.cc +++ b/src/d8-windows.cc @@ -8,8 +8,7 @@ namespace v8 { -void Shell::AddOSMethods(Isolate* isolate, Handle os_templ) { -} +void Shell::AddOSMethods(Isolate* isolate, Local os_templ) {} } // namespace v8 diff --git a/src/d8.cc b/src/d8.cc index 457b4c1..06499ef 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -108,7 +108,7 @@ v8::Platform* g_platform = NULL; #ifndef V8_SHARED -bool FindInObjectList(Handle object, const Shell::ObjectList& list) { +bool FindInObjectList(Local object, const Shell::ObjectList& list) { for (int i = 0; i < list.length(); ++i) { if (list[i]->StrictEquals(object)) { return true; @@ -122,8 +122,10 @@ bool FindInObjectList(Handle object, const Shell::ObjectList& list) { } // namespace -static Handle Throw(Isolate* isolate, const char* message) { - return isolate->ThrowException(String::NewFromUtf8(isolate, message)); +static Local Throw(Isolate* isolate, const char* message) { + return isolate->ThrowException( + String::NewFromUtf8(isolate, message, NewStringType::kNormal) + .ToLocalChecked()); } @@ -158,12 +160,12 @@ class PerIsolateData { int realm_count_; int realm_current_; int realm_switch_; - Persistent* realms_; - Persistent realm_shared_; + Global* realms_; + Global realm_shared_; int RealmIndexOrThrow(const v8::FunctionCallbackInfo& args, int arg_offset); - int RealmFind(Handle context); + int RealmFind(Local context); }; @@ -180,13 +182,14 @@ class DumbLineEditor: public LineEditor { public: explicit DumbLineEditor(Isolate* isolate) : LineEditor(LineEditor::DUMB, "dumb"), isolate_(isolate) { } - virtual Handle Prompt(const char* prompt); + virtual Local Prompt(const char* prompt); + private: Isolate* isolate_; }; -Handle DumbLineEditor::Prompt(const char* prompt) { +Local DumbLineEditor::Prompt(const char* prompt) { printf("%s", prompt); #if defined(__native_client__) // Native Client libc is used to being embedded in Chrome and @@ -205,14 +208,14 @@ CounterCollection* Shell::counters_ = &local_counters_; base::LazyMutex Shell::context_mutex_; const base::TimeTicks Shell::kInitialTicks = base::TimeTicks::HighResolutionNow(); -Persistent Shell::utility_context_; +Global Shell::utility_context_; base::LazyMutex Shell::workers_mutex_; bool Shell::allow_new_workers_ = true; i::List Shell::workers_; i::List Shell::externalized_shared_contents_; #endif // !V8_SHARED -Persistent Shell::evaluation_context_; +Global Shell::evaluation_context_; ArrayBuffer::Allocator* Shell::array_buffer_allocator; ShellOptions Shell::options; const char* Shell::kPrompt = "d8> "; @@ -255,19 +258,22 @@ ScriptCompiler::CachedData* CompileForCachedData( Isolate::Scope isolate_scope(temp_isolate); HandleScope handle_scope(temp_isolate); Context::Scope context_scope(Context::New(temp_isolate)); - Local source_copy = v8::String::NewFromTwoByte( - temp_isolate, source_buffer, v8::String::kNormalString, source_length); + Local source_copy = + v8::String::NewFromTwoByte(temp_isolate, source_buffer, + v8::NewStringType::kNormal, + source_length).ToLocalChecked(); Local name_copy; if (name_buffer) { - name_copy = v8::String::NewFromTwoByte( - temp_isolate, name_buffer, v8::String::kNormalString, name_length); + name_copy = v8::String::NewFromTwoByte(temp_isolate, name_buffer, + v8::NewStringType::kNormal, + name_length).ToLocalChecked(); } else { name_copy = v8::Undefined(temp_isolate); } ScriptCompiler::Source script_source(source_copy, ScriptOrigin(name_copy)); - ScriptCompiler::CompileUnbound(temp_isolate, &script_source, - compile_options); - if (script_source.GetCachedData()) { + if (!ScriptCompiler::CompileUnboundScript(temp_isolate, &script_source, + compile_options).IsEmpty() && + script_source.GetCachedData()) { int length = script_source.GetCachedData()->length; uint8_t* cache = new uint8_t[length]; memcpy(cache, script_source.GetCachedData()->data, length); @@ -283,16 +289,17 @@ ScriptCompiler::CachedData* CompileForCachedData( // Compile a string within the current v8 context. -Local