Commit af82ef84 authored by jochen's avatar jochen Committed by Commit bot

Make d8 stop using to-be-deprecated APIs

BUG=v8:4134
LOG=n
R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/1239053004

Cr-Commit-Position: refs/heads/master@{#29726}
parent 76b3b21c
...@@ -29,24 +29,30 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) { ...@@ -29,24 +29,30 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) {
// Get the toJSONProtocol function on the event and get the JSON format. // Get the toJSONProtocol function on the event and get the JSON format.
Local<String> to_json_fun_name = Local<String> to_json_fun_name =
String::NewFromUtf8(isolate, "toJSONProtocol"); String::NewFromUtf8(isolate, "toJSONProtocol", NewStringType::kNormal)
Handle<Object> event_data = event_details.GetEventData(); .ToLocalChecked();
Local<Object> event_data = event_details.GetEventData();
Local<Function> to_json_fun = Local<Function> to_json_fun =
Local<Function>::Cast(event_data->Get(to_json_fun_name)); Local<Function>::Cast(event_data->Get(isolate->GetCurrentContext(),
Local<Value> event_json = to_json_fun->Call(event_data, 0, NULL); to_json_fun_name).ToLocalChecked());
if (try_catch.HasCaught()) { Local<Value> event_json;
if (!to_json_fun->Call(isolate->GetCurrentContext(), event_data, 0, NULL)
.ToLocal(&event_json)) {
Shell::ReportException(isolate, &try_catch); Shell::ReportException(isolate, &try_catch);
return; return;
} }
// Print the event details. // Print the event details.
Handle<Object> details = Local<Object> details =
Shell::DebugMessageDetails(isolate, Handle<String>::Cast(event_json)); Shell::DebugMessageDetails(isolate, Local<String>::Cast(event_json));
if (try_catch.HasCaught()) { if (try_catch.HasCaught()) {
Shell::ReportException(isolate, &try_catch); Shell::ReportException(isolate, &try_catch);
return; 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) { if (str.length() == 0) {
// Empty string is used to signal not to process this event. // Empty string is used to signal not to process this event.
return; return;
...@@ -55,15 +61,18 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) { ...@@ -55,15 +61,18 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) {
// Get the debug command processor. // Get the debug command processor.
Local<String> fun_name = Local<String> fun_name =
String::NewFromUtf8(isolate, "debugCommandProcessor"); String::NewFromUtf8(isolate, "debugCommandProcessor",
Handle<Object> exec_state = event_details.GetExecutionState(); NewStringType::kNormal).ToLocalChecked();
Local<Function> fun = Local<Function>::Cast(exec_state->Get(fun_name)); Local<Object> exec_state = event_details.GetExecutionState();
Local<Object> cmd_processor = Local<Function> fun = Local<Function>::Cast(
Local<Object>::Cast(fun->Call(exec_state, 0, NULL)); exec_state->Get(isolate->GetCurrentContext(), fun_name).ToLocalChecked());
if (try_catch.HasCaught()) { Local<Value> cmd_processor_value;
if (!fun->Call(isolate->GetCurrentContext(), exec_state, 0, NULL)
.ToLocal(&cmd_processor_value)) {
Shell::ReportException(isolate, &try_catch); Shell::ReportException(isolate, &try_catch);
return; return;
} }
Local<Object> cmd_processor = Local<Object>::Cast(cmd_processor_value);
static const int kBufferSize = 256; static const int kBufferSize = 256;
bool running = false; bool running = false;
...@@ -79,8 +88,9 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) { ...@@ -79,8 +88,9 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) {
TryCatch try_catch(isolate); TryCatch try_catch(isolate);
// Convert the debugger command to a JSON debugger request. // Convert the debugger command to a JSON debugger request.
Handle<Value> request = Shell::DebugCommandToJSONRequest( Local<Value> request = Shell::DebugCommandToJSONRequest(
isolate, String::NewFromUtf8(isolate, command)); isolate, String::NewFromUtf8(isolate, command, NewStringType::kNormal)
.ToLocalChecked());
if (try_catch.HasCaught()) { if (try_catch.HasCaught()) {
Shell::ReportException(isolate, &try_catch); Shell::ReportException(isolate, &try_catch);
continue; continue;
...@@ -92,39 +102,50 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) { ...@@ -92,39 +102,50 @@ void HandleDebugEvent(const Debug::EventDetails& event_details) {
continue; continue;
} }
Handle<String> fun_name; Local<String> fun_name;
Handle<Function> fun; Local<Function> fun;
// All the functions used below take one argument. // All the functions used below take one argument.
static const int kArgc = 1; static const int kArgc = 1;
Handle<Value> args[kArgc]; Local<Value> args[kArgc];
// Invoke the JavaScript to convert the debug command line to a JSON // 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 // request, invoke the JSON request and convert the JSON respose to a text
// representation. // representation.
fun_name = String::NewFromUtf8(isolate, "processDebugRequest"); fun_name = String::NewFromUtf8(isolate, "processDebugRequest",
fun = Handle<Function>::Cast(cmd_processor->Get(fun_name)); NewStringType::kNormal).ToLocalChecked();
fun = Local<Function>::Cast(cmd_processor->Get(isolate->GetCurrentContext(),
fun_name).ToLocalChecked());
args[0] = request; args[0] = request;
Handle<Value> response_val = fun->Call(cmd_processor, kArgc, args); Local<Value> response_val;
if (try_catch.HasCaught()) { if (!fun->Call(isolate->GetCurrentContext(), cmd_processor, kArgc, args)
.ToLocal(&response_val)) {
Shell::ReportException(isolate, &try_catch); Shell::ReportException(isolate, &try_catch);
continue; continue;
} }
Handle<String> response = Handle<String>::Cast(response_val); Local<String> response = Local<String>::Cast(response_val);
// Convert the debugger response into text details and the running state. // Convert the debugger response into text details and the running state.
Handle<Object> response_details = Local<Object> response_details =
Shell::DebugMessageDetails(isolate, response); Shell::DebugMessageDetails(isolate, response);
if (try_catch.HasCaught()) { if (try_catch.HasCaught()) {
Shell::ReportException(isolate, &try_catch); Shell::ReportException(isolate, &try_catch);
continue; continue;
} }
String::Utf8Value text_str( 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) { if (text_str.length() > 0) {
printf("%s\n", *text_str); printf("%s\n", *text_str);
} }
running = response_details->Get(String::NewFromUtf8(isolate, "running")) running = response_details->Get(isolate->GetCurrentContext(),
->ToBoolean(isolate) String::NewFromUtf8(isolate, "running",
NewStringType::kNormal)
.ToLocalChecked())
.ToLocalChecked()
->ToBoolean(isolate->GetCurrentContext())
.ToLocalChecked()
->Value(); ->Value();
} }
} }
......
...@@ -170,12 +170,14 @@ class ExecArgs { ...@@ -170,12 +170,14 @@ class ExecArgs {
ExecArgs() { ExecArgs() {
exec_args_[0] = NULL; exec_args_[0] = NULL;
} }
bool Init(Isolate* isolate, Handle<Value> arg0, Handle<Array> command_args) { bool Init(Isolate* isolate, Local<Value> arg0, Local<Array> command_args) {
String::Utf8Value prog(arg0); String::Utf8Value prog(arg0);
if (*prog == NULL) { if (*prog == NULL) {
const char* message = const char* message =
"os.system(): String conversion of program name failed"; "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; return false;
} }
int len = prog.length() + 3; int len = prog.length() + 3;
...@@ -184,13 +186,17 @@ class ExecArgs { ...@@ -184,13 +186,17 @@ class ExecArgs {
exec_args_[0] = c_arg; exec_args_[0] = c_arg;
int i = 1; int i = 1;
for (unsigned j = 0; j < command_args->Length(); i++, j++) { for (unsigned j = 0; j < command_args->Length(); i++, j++) {
Handle<Value> arg(command_args->Get(Integer::New(isolate, j))); Local<Value> arg(
command_args->Get(isolate->GetCurrentContext(),
Integer::New(isolate, j)).ToLocalChecked());
String::Utf8Value utf8_arg(arg); String::Utf8Value utf8_arg(arg);
if (*utf8_arg == NULL) { if (*utf8_arg == NULL) {
exec_args_[i] = NULL; // Consistent state for destructor. exec_args_[i] = NULL; // Consistent state for destructor.
const char* message = const char* message =
"os.system(): String conversion of argument failed."; "os.system(): String conversion of argument failed.";
isolate->ThrowException(String::NewFromUtf8(isolate, message)); isolate->ThrowException(
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
.ToLocalChecked());
return false; return false;
} }
int len = utf8_arg.length() + 1; int len = utf8_arg.length() + 1;
...@@ -225,19 +231,27 @@ static bool GetTimeouts(const v8::FunctionCallbackInfo<v8::Value>& args, ...@@ -225,19 +231,27 @@ static bool GetTimeouts(const v8::FunctionCallbackInfo<v8::Value>& args,
int* total_timeout) { int* total_timeout) {
if (args.Length() > 3) { if (args.Length() > 3) {
if (args[3]->IsNumber()) { if (args[3]->IsNumber()) {
*total_timeout = args[3]->Int32Value(); *total_timeout = args[3]
->Int32Value(args.GetIsolate()->GetCurrentContext())
.FromJust();
} else { } else {
args.GetIsolate()->ThrowException(String::NewFromUtf8( args.GetIsolate()->ThrowException(
args.GetIsolate(), "system: Argument 4 must be a number")); String::NewFromUtf8(args.GetIsolate(),
"system: Argument 4 must be a number",
NewStringType::kNormal).ToLocalChecked());
return false; return false;
} }
} }
if (args.Length() > 2) { if (args.Length() > 2) {
if (args[2]->IsNumber()) { if (args[2]->IsNumber()) {
*read_timeout = args[2]->Int32Value(); *read_timeout = args[2]
->Int32Value(args.GetIsolate()->GetCurrentContext())
.FromJust();
} else { } else {
args.GetIsolate()->ThrowException(String::NewFromUtf8( args.GetIsolate()->ThrowException(
args.GetIsolate(), "system: Argument 3 must be a number")); String::NewFromUtf8(args.GetIsolate(),
"system: Argument 3 must be a number",
NewStringType::kNormal).ToLocalChecked());
return false; return false;
} }
} }
...@@ -282,7 +296,9 @@ static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) { ...@@ -282,7 +296,9 @@ static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) {
bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err)); bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err));
} while (bytes_read == -1 && errno == EINTR); } while (bytes_read == -1 && errno == EINTR);
if (bytes_read != 0) { if (bytes_read != 0) {
isolate->ThrowException(String::NewFromUtf8(isolate, strerror(err))); isolate->ThrowException(
String::NewFromUtf8(isolate, strerror(err), NewStringType::kNormal)
.ToLocalChecked());
return false; return false;
} }
return true; return true;
...@@ -291,12 +307,10 @@ static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) { ...@@ -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 // Accumulates the output from the child in a string handle. Returns true if it
// succeeded or false if an exception was thrown. // succeeded or false if an exception was thrown.
static Handle<Value> GetStdout(Isolate* isolate, static Local<Value> GetStdout(Isolate* isolate, int child_fd,
int child_fd,
const struct timeval& start_time, const struct timeval& start_time,
int read_timeout, int read_timeout, int total_timeout) {
int total_timeout) { Local<String> accumulator = String::Empty(isolate);
Handle<String> accumulator = String::Empty(isolate);
int fullness = 0; int fullness = 0;
static const int kStdoutReadBufferSize = 4096; static const int kStdoutReadBufferSize = 4096;
...@@ -304,7 +318,8 @@ static Handle<Value> GetStdout(Isolate* isolate, ...@@ -304,7 +318,8 @@ static Handle<Value> GetStdout(Isolate* isolate,
if (fcntl(child_fd, F_SETFL, O_NONBLOCK) != 0) { if (fcntl(child_fd, F_SETFL, O_NONBLOCK) != 0) {
return isolate->ThrowException( return isolate->ThrowException(
String::NewFromUtf8(isolate, strerror(errno))); String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
.ToLocalChecked());
} }
int bytes_read; int bytes_read;
...@@ -319,7 +334,8 @@ static Handle<Value> GetStdout(Isolate* isolate, ...@@ -319,7 +334,8 @@ static Handle<Value> GetStdout(Isolate* isolate,
start_time) || start_time) ||
(TimeIsOut(start_time, total_timeout))) { (TimeIsOut(start_time, total_timeout))) {
return isolate->ThrowException( return isolate->ThrowException(
String::NewFromUtf8(isolate, "Timed out waiting for output")); String::NewFromUtf8(isolate, "Timed out waiting for output",
NewStringType::kNormal).ToLocalChecked());
} }
continue; continue;
} else if (errno == EINTR) { } else if (errno == EINTR) {
...@@ -332,8 +348,9 @@ static Handle<Value> GetStdout(Isolate* isolate, ...@@ -332,8 +348,9 @@ static Handle<Value> GetStdout(Isolate* isolate,
int length = bytes_read == 0 ? int length = bytes_read == 0 ?
bytes_read + fullness : bytes_read + fullness :
LengthWithoutIncompleteUtf8(buffer, bytes_read + fullness); LengthWithoutIncompleteUtf8(buffer, bytes_read + fullness);
Handle<String> addition = Local<String> addition =
String::NewFromUtf8(isolate, buffer, String::kNormalString, length); String::NewFromUtf8(isolate, buffer, NewStringType::kNormal, length)
.ToLocalChecked();
accumulator = String::Concat(accumulator, addition); accumulator = String::Concat(accumulator, addition);
fullness = bytes_read + fullness - length; fullness = bytes_read + fullness - length;
memcpy(buffer, buffer + length, fullness); memcpy(buffer, buffer + length, fullness);
...@@ -380,8 +397,10 @@ static bool WaitForChild(Isolate* isolate, ...@@ -380,8 +397,10 @@ static bool WaitForChild(Isolate* isolate,
if (useconds < 1000000) useconds <<= 1; if (useconds < 1000000) useconds <<= 1;
if ((read_timeout != -1 && useconds / 1000 > read_timeout) || if ((read_timeout != -1 && useconds / 1000 > read_timeout) ||
(TimeIsOut(start_time, total_timeout))) { (TimeIsOut(start_time, total_timeout))) {
isolate->ThrowException(String::NewFromUtf8( isolate->ThrowException(
isolate, "Timed out waiting for process to terminate")); String::NewFromUtf8(isolate,
"Timed out waiting for process to terminate",
NewStringType::kNormal).ToLocalChecked());
kill(pid, SIGINT); kill(pid, SIGINT);
return false; return false;
} }
...@@ -392,7 +411,9 @@ static bool WaitForChild(Isolate* isolate, ...@@ -392,7 +411,9 @@ static bool WaitForChild(Isolate* isolate,
sizeof(message), sizeof(message),
"Child killed by signal %d", "Child killed by signal %d",
child_info.si_status); child_info.si_status);
isolate->ThrowException(String::NewFromUtf8(isolate, message)); isolate->ThrowException(
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
.ToLocalChecked());
return false; return false;
} }
if (child_info.si_code == CLD_EXITED && child_info.si_status != 0) { if (child_info.si_code == CLD_EXITED && child_info.si_status != 0) {
...@@ -401,7 +422,9 @@ static bool WaitForChild(Isolate* isolate, ...@@ -401,7 +422,9 @@ static bool WaitForChild(Isolate* isolate,
sizeof(message), sizeof(message),
"Child exited with status %d", "Child exited with status %d",
child_info.si_status); child_info.si_status);
isolate->ThrowException(String::NewFromUtf8(isolate, message)); isolate->ThrowException(
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
.ToLocalChecked());
return false; return false;
} }
...@@ -416,7 +439,9 @@ static bool WaitForChild(Isolate* isolate, ...@@ -416,7 +439,9 @@ static bool WaitForChild(Isolate* isolate,
sizeof(message), sizeof(message),
"Child killed by signal %d", "Child killed by signal %d",
WTERMSIG(child_status)); WTERMSIG(child_status));
isolate->ThrowException(String::NewFromUtf8(isolate, message)); isolate->ThrowException(
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
.ToLocalChecked());
return false; return false;
} }
if (WEXITSTATUS(child_status) != 0) { if (WEXITSTATUS(child_status) != 0) {
...@@ -426,7 +451,9 @@ static bool WaitForChild(Isolate* isolate, ...@@ -426,7 +451,9 @@ static bool WaitForChild(Isolate* isolate,
sizeof(message), sizeof(message),
"Child exited with status %d", "Child exited with status %d",
exit_status); exit_status);
isolate->ThrowException(String::NewFromUtf8(isolate, message)); isolate->ThrowException(
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
.ToLocalChecked());
return false; return false;
} }
...@@ -442,25 +469,29 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -442,25 +469,29 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
int read_timeout = -1; int read_timeout = -1;
int total_timeout = -1; int total_timeout = -1;
if (!GetTimeouts(args, &read_timeout, &total_timeout)) return; if (!GetTimeouts(args, &read_timeout, &total_timeout)) return;
Handle<Array> command_args; Local<Array> command_args;
if (args.Length() > 1) { if (args.Length() > 1) {
if (!args[1]->IsArray()) { if (!args[1]->IsArray()) {
args.GetIsolate()->ThrowException(String::NewFromUtf8( args.GetIsolate()->ThrowException(
args.GetIsolate(), "system: Argument 2 must be an array")); String::NewFromUtf8(args.GetIsolate(),
"system: Argument 2 must be an array",
NewStringType::kNormal).ToLocalChecked());
return; return;
} }
command_args = Handle<Array>::Cast(args[1]); command_args = Local<Array>::Cast(args[1]);
} else { } else {
command_args = Array::New(args.GetIsolate(), 0); command_args = Array::New(args.GetIsolate(), 0);
} }
if (command_args->Length() > ExecArgs::kMaxArgs) { if (command_args->Length() > ExecArgs::kMaxArgs) {
args.GetIsolate()->ThrowException(String::NewFromUtf8( args.GetIsolate()->ThrowException(
args.GetIsolate(), "Too many arguments to system()")); String::NewFromUtf8(args.GetIsolate(), "Too many arguments to system()",
NewStringType::kNormal).ToLocalChecked());
return; return;
} }
if (args.Length() < 1) { if (args.Length() < 1) {
args.GetIsolate()->ThrowException(String::NewFromUtf8( args.GetIsolate()->ThrowException(
args.GetIsolate(), "Too few arguments to system()")); String::NewFromUtf8(args.GetIsolate(), "Too few arguments to system()",
NewStringType::kNormal).ToLocalChecked());
return; return;
} }
...@@ -476,12 +507,14 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -476,12 +507,14 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (pipe(exec_error_fds) != 0) { if (pipe(exec_error_fds) != 0) {
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.")); String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.",
NewStringType::kNormal).ToLocalChecked());
return; return;
} }
if (pipe(stdout_fds) != 0) { if (pipe(stdout_fds) != 0) {
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.")); String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.",
NewStringType::kNormal).ToLocalChecked());
return; return;
} }
...@@ -500,11 +533,8 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -500,11 +533,8 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (!ChildLaunchedOK(args.GetIsolate(), exec_error_fds)) return; if (!ChildLaunchedOK(args.GetIsolate(), exec_error_fds)) return;
Handle<Value> accumulator = GetStdout(args.GetIsolate(), Local<Value> accumulator = GetStdout(args.GetIsolate(), stdout_fds[kReadFD],
stdout_fds[kReadFD], start_time, read_timeout, total_timeout);
start_time,
read_timeout,
total_timeout);
if (accumulator->IsUndefined()) { if (accumulator->IsUndefined()) {
kill(pid, SIGINT); // On timeout, kill the subprocess. kill(pid, SIGINT); // On timeout, kill the subprocess.
args.GetReturnValue().Set(accumulator); args.GetReturnValue().Set(accumulator);
...@@ -528,19 +558,22 @@ void Shell::ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -528,19 +558,22 @@ void Shell::ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) { if (args.Length() != 1) {
const char* message = "chdir() takes one argument"; const char* message = "chdir() takes one argument";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
String::Utf8Value directory(args[0]); String::Utf8Value directory(args[0]);
if (*directory == NULL) { if (*directory == NULL) {
const char* message = "os.chdir(): String conversion of argument failed."; const char* message = "os.chdir(): String conversion of argument failed.";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
if (chdir(*directory) != 0) { if (chdir(*directory) != 0) {
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), strerror(errno))); String::NewFromUtf8(args.GetIsolate(), strerror(errno),
NewStringType::kNormal).ToLocalChecked());
return; return;
} }
} }
...@@ -550,7 +583,8 @@ void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -550,7 +583,8 @@ void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) { if (args.Length() != 1) {
const char* message = "umask() takes one argument"; const char* message = "umask() takes one argument";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
if (args[0]->IsNumber()) { if (args[0]->IsNumber()) {
...@@ -558,14 +592,16 @@ void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -558,14 +592,16 @@ void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) {
// PNaCL has no support for umask. // PNaCL has no support for umask.
int previous = 0; int previous = 0;
#else #else
int previous = umask(args[0]->Int32Value()); int previous = umask(
args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust());
#endif #endif
args.GetReturnValue().Set(previous); args.GetReturnValue().Set(previous);
return; return;
} else { } else {
const char* message = "umask() argument must be numeric"; const char* message = "umask() argument must be numeric";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
} }
...@@ -575,11 +611,15 @@ static bool CheckItsADirectory(Isolate* isolate, char* directory) { ...@@ -575,11 +611,15 @@ static bool CheckItsADirectory(Isolate* isolate, char* directory) {
struct stat stat_buf; struct stat stat_buf;
int stat_result = stat(directory, &stat_buf); int stat_result = stat(directory, &stat_buf);
if (stat_result != 0) { if (stat_result != 0) {
isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno))); isolate->ThrowException(
String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
.ToLocalChecked());
return false; return false;
} }
if ((stat_buf.st_mode & S_IFDIR) != 0) return true; 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; return false;
} }
...@@ -594,7 +634,9 @@ static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) { ...@@ -594,7 +634,9 @@ static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) {
} else if (errno == ENOENT) { // Intermediate path element is missing. } else if (errno == ENOENT) { // Intermediate path element is missing.
char* last_slash = strrchr(directory, '/'); char* last_slash = strrchr(directory, '/');
if (last_slash == NULL) { if (last_slash == NULL) {
isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno))); isolate->ThrowException(
String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
.ToLocalChecked());
return false; return false;
} }
*last_slash = 0; *last_slash = 0;
...@@ -605,10 +647,14 @@ static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) { ...@@ -605,10 +647,14 @@ static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) {
if (errno == EEXIST) { if (errno == EEXIST) {
return CheckItsADirectory(isolate, directory); return CheckItsADirectory(isolate, directory);
} }
isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno))); isolate->ThrowException(
String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
.ToLocalChecked());
return false; return false;
} else { } else {
isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno))); isolate->ThrowException(
String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
.ToLocalChecked());
return false; return false;
} }
} }
...@@ -618,24 +664,29 @@ void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -618,24 +664,29 @@ void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
mode_t mask = 0777; mode_t mask = 0777;
if (args.Length() == 2) { if (args.Length() == 2) {
if (args[1]->IsNumber()) { if (args[1]->IsNumber()) {
mask = args[1]->Int32Value(); mask = args[1]
->Int32Value(args.GetIsolate()->GetCurrentContext())
.FromJust();
} else { } else {
const char* message = "mkdirp() second argument must be numeric"; const char* message = "mkdirp() second argument must be numeric";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message,
NewStringType::kNormal).ToLocalChecked());
return; return;
} }
} else if (args.Length() != 1) { } else if (args.Length() != 1) {
const char* message = "mkdirp() takes one or two arguments"; const char* message = "mkdirp() takes one or two arguments";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
String::Utf8Value directory(args[0]); String::Utf8Value directory(args[0]);
if (*directory == NULL) { if (*directory == NULL) {
const char* message = "os.mkdirp(): String conversion of argument failed."; const char* message = "os.mkdirp(): String conversion of argument failed.";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
mkdirp(args.GetIsolate(), *directory, mask); mkdirp(args.GetIsolate(), *directory, mask);
...@@ -646,14 +697,16 @@ void Shell::RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -646,14 +697,16 @@ void Shell::RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) { if (args.Length() != 1) {
const char* message = "rmdir() takes one or two arguments"; const char* message = "rmdir() takes one or two arguments";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
String::Utf8Value directory(args[0]); String::Utf8Value directory(args[0]);
if (*directory == NULL) { if (*directory == NULL) {
const char* message = "os.rmdir(): String conversion of argument failed."; const char* message = "os.rmdir(): String conversion of argument failed.";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
rmdir(*directory); rmdir(*directory);
...@@ -664,7 +717,8 @@ void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -664,7 +717,8 @@ void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 2) { if (args.Length() != 2) {
const char* message = "setenv() takes two arguments"; const char* message = "setenv() takes two arguments";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
String::Utf8Value var(args[0]); String::Utf8Value var(args[0]);
...@@ -673,14 +727,16 @@ void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -673,14 +727,16 @@ void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
const char* message = const char* message =
"os.setenv(): String conversion of variable name failed."; "os.setenv(): String conversion of variable name failed.";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
if (*value == NULL) { if (*value == NULL) {
const char* message = const char* message =
"os.setenv(): String conversion of variable contents failed."; "os.setenv(): String conversion of variable contents failed.";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
setenv(*var, *value, 1); setenv(*var, *value, 1);
...@@ -691,7 +747,8 @@ void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -691,7 +747,8 @@ void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) { if (args.Length() != 1) {
const char* message = "unsetenv() takes one argument"; const char* message = "unsetenv() takes one argument";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
String::Utf8Value var(args[0]); String::Utf8Value var(args[0]);
...@@ -699,27 +756,35 @@ void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -699,27 +756,35 @@ void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
const char* message = const char* message =
"os.setenv(): String conversion of variable name failed."; "os.setenv(): String conversion of variable name failed.";
args.GetIsolate()->ThrowException( args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message)); String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
.ToLocalChecked());
return; return;
} }
unsetenv(*var); unsetenv(*var);
} }
void Shell::AddOSMethods(Isolate* isolate, Handle<ObjectTemplate> os_templ) { void Shell::AddOSMethods(Isolate* isolate, Local<ObjectTemplate> os_templ) {
os_templ->Set(String::NewFromUtf8(isolate, "system"), os_templ->Set(String::NewFromUtf8(isolate, "system", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, System)); 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)); 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)); 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)); 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)); 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)); 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)); FunctionTemplate::New(isolate, RemoveDirectory));
} }
......
...@@ -25,7 +25,7 @@ namespace v8 { ...@@ -25,7 +25,7 @@ namespace v8 {
class ReadLineEditor: public LineEditor { class ReadLineEditor: public LineEditor {
public: public:
ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { } ReadLineEditor() : LineEditor(LineEditor::READLINE, "readline") { }
virtual Handle<String> Prompt(const char* prompt); virtual Local<String> Prompt(const char* prompt);
virtual bool Open(Isolate* isolate); virtual bool Open(Isolate* isolate);
virtual bool Close(); virtual bool Close();
virtual void AddHistory(const char* str); virtual void AddHistory(const char* str);
...@@ -80,10 +80,10 @@ bool ReadLineEditor::Close() { ...@@ -80,10 +80,10 @@ bool ReadLineEditor::Close() {
} }
Handle<String> ReadLineEditor::Prompt(const char* prompt) { Local<String> ReadLineEditor::Prompt(const char* prompt) {
char* result = NULL; char* result = NULL;
result = readline(prompt); result = readline(prompt);
if (result == NULL) return Handle<String>(); if (result == NULL) return Local<String>();
AddHistory(result); AddHistory(result);
return String::NewFromUtf8(isolate_, result); return String::NewFromUtf8(isolate_, result);
} }
...@@ -118,10 +118,10 @@ char** ReadLineEditor::AttemptedCompletion(const char* text, ...@@ -118,10 +118,10 @@ char** ReadLineEditor::AttemptedCompletion(const char* text,
char* ReadLineEditor::CompletionGenerator(const char* text, int state) { char* ReadLineEditor::CompletionGenerator(const char* text, int state) {
static unsigned current_index; static unsigned current_index;
static Persistent<Array> current_completions; static Global<Array> current_completions;
Isolate* isolate = read_line_editor.isolate_; Isolate* isolate = read_line_editor.isolate_;
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<Array> completions; Local<Array> completions;
if (state == 0) { if (state == 0) {
Local<String> full_text = String::NewFromUtf8(isolate, Local<String> full_text = String::NewFromUtf8(isolate,
rl_line_buffer, rl_line_buffer,
...@@ -136,8 +136,8 @@ char* ReadLineEditor::CompletionGenerator(const char* text, int state) { ...@@ -136,8 +136,8 @@ char* ReadLineEditor::CompletionGenerator(const char* text, int state) {
completions = Local<Array>::New(isolate, current_completions); completions = Local<Array>::New(isolate, current_completions);
} }
if (current_index < completions->Length()) { if (current_index < completions->Length()) {
Handle<Integer> index = Integer::New(isolate, current_index); Local<Integer> index = Integer::New(isolate, current_index);
Handle<Value> str_obj = completions->Get(index); Local<Value> str_obj = completions->Get(index);
current_index++; current_index++;
String::Utf8Value str(str_obj); String::Utf8Value str(str_obj);
return strdup(*str); return strdup(*str);
......
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
namespace v8 { namespace v8 {
void Shell::AddOSMethods(Isolate* isolate, Handle<ObjectTemplate> os_templ) { void Shell::AddOSMethods(Isolate* isolate, Local<ObjectTemplate> os_templ) {}
}
} // namespace v8 } // namespace v8
...@@ -108,7 +108,7 @@ v8::Platform* g_platform = NULL; ...@@ -108,7 +108,7 @@ v8::Platform* g_platform = NULL;
#ifndef V8_SHARED #ifndef V8_SHARED
bool FindInObjectList(Handle<Object> object, const Shell::ObjectList& list) { bool FindInObjectList(Local<Object> object, const Shell::ObjectList& list) {
for (int i = 0; i < list.length(); ++i) { for (int i = 0; i < list.length(); ++i) {
if (list[i]->StrictEquals(object)) { if (list[i]->StrictEquals(object)) {
return true; return true;
...@@ -122,8 +122,10 @@ bool FindInObjectList(Handle<Object> object, const Shell::ObjectList& list) { ...@@ -122,8 +122,10 @@ bool FindInObjectList(Handle<Object> object, const Shell::ObjectList& list) {
} // namespace } // namespace
static Handle<Value> Throw(Isolate* isolate, const char* message) { static Local<Value> Throw(Isolate* isolate, const char* message) {
return isolate->ThrowException(String::NewFromUtf8(isolate, message)); return isolate->ThrowException(
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
.ToLocalChecked());
} }
...@@ -158,12 +160,12 @@ class PerIsolateData { ...@@ -158,12 +160,12 @@ class PerIsolateData {
int realm_count_; int realm_count_;
int realm_current_; int realm_current_;
int realm_switch_; int realm_switch_;
Persistent<Context>* realms_; Global<Context>* realms_;
Persistent<Value> realm_shared_; Global<Value> realm_shared_;
int RealmIndexOrThrow(const v8::FunctionCallbackInfo<v8::Value>& args, int RealmIndexOrThrow(const v8::FunctionCallbackInfo<v8::Value>& args,
int arg_offset); int arg_offset);
int RealmFind(Handle<Context> context); int RealmFind(Local<Context> context);
}; };
...@@ -180,13 +182,14 @@ class DumbLineEditor: public LineEditor { ...@@ -180,13 +182,14 @@ class DumbLineEditor: public LineEditor {
public: public:
explicit DumbLineEditor(Isolate* isolate) explicit DumbLineEditor(Isolate* isolate)
: LineEditor(LineEditor::DUMB, "dumb"), isolate_(isolate) { } : LineEditor(LineEditor::DUMB, "dumb"), isolate_(isolate) { }
virtual Handle<String> Prompt(const char* prompt); virtual Local<String> Prompt(const char* prompt);
private: private:
Isolate* isolate_; Isolate* isolate_;
}; };
Handle<String> DumbLineEditor::Prompt(const char* prompt) { Local<String> DumbLineEditor::Prompt(const char* prompt) {
printf("%s", prompt); printf("%s", prompt);
#if defined(__native_client__) #if defined(__native_client__)
// Native Client libc is used to being embedded in Chrome and // Native Client libc is used to being embedded in Chrome and
...@@ -205,14 +208,14 @@ CounterCollection* Shell::counters_ = &local_counters_; ...@@ -205,14 +208,14 @@ CounterCollection* Shell::counters_ = &local_counters_;
base::LazyMutex Shell::context_mutex_; base::LazyMutex Shell::context_mutex_;
const base::TimeTicks Shell::kInitialTicks = const base::TimeTicks Shell::kInitialTicks =
base::TimeTicks::HighResolutionNow(); base::TimeTicks::HighResolutionNow();
Persistent<Context> Shell::utility_context_; Global<Context> Shell::utility_context_;
base::LazyMutex Shell::workers_mutex_; base::LazyMutex Shell::workers_mutex_;
bool Shell::allow_new_workers_ = true; bool Shell::allow_new_workers_ = true;
i::List<Worker*> Shell::workers_; i::List<Worker*> Shell::workers_;
i::List<SharedArrayBuffer::Contents> Shell::externalized_shared_contents_; i::List<SharedArrayBuffer::Contents> Shell::externalized_shared_contents_;
#endif // !V8_SHARED #endif // !V8_SHARED
Persistent<Context> Shell::evaluation_context_; Global<Context> Shell::evaluation_context_;
ArrayBuffer::Allocator* Shell::array_buffer_allocator; ArrayBuffer::Allocator* Shell::array_buffer_allocator;
ShellOptions Shell::options; ShellOptions Shell::options;
const char* Shell::kPrompt = "d8> "; const char* Shell::kPrompt = "d8> ";
...@@ -255,18 +258,21 @@ ScriptCompiler::CachedData* CompileForCachedData( ...@@ -255,18 +258,21 @@ ScriptCompiler::CachedData* CompileForCachedData(
Isolate::Scope isolate_scope(temp_isolate); Isolate::Scope isolate_scope(temp_isolate);
HandleScope handle_scope(temp_isolate); HandleScope handle_scope(temp_isolate);
Context::Scope context_scope(Context::New(temp_isolate)); Context::Scope context_scope(Context::New(temp_isolate));
Local<String> source_copy = v8::String::NewFromTwoByte( Local<String> source_copy =
temp_isolate, source_buffer, v8::String::kNormalString, source_length); v8::String::NewFromTwoByte(temp_isolate, source_buffer,
v8::NewStringType::kNormal,
source_length).ToLocalChecked();
Local<Value> name_copy; Local<Value> name_copy;
if (name_buffer) { if (name_buffer) {
name_copy = v8::String::NewFromTwoByte( name_copy = v8::String::NewFromTwoByte(temp_isolate, name_buffer,
temp_isolate, name_buffer, v8::String::kNormalString, name_length); v8::NewStringType::kNormal,
name_length).ToLocalChecked();
} else { } else {
name_copy = v8::Undefined(temp_isolate); name_copy = v8::Undefined(temp_isolate);
} }
ScriptCompiler::Source script_source(source_copy, ScriptOrigin(name_copy)); ScriptCompiler::Source script_source(source_copy, ScriptOrigin(name_copy));
ScriptCompiler::CompileUnbound(temp_isolate, &script_source, ScriptCompiler::CompileUnboundScript(temp_isolate, &script_source,
compile_options); compile_options).ToLocalChecked();
if (script_source.GetCachedData()) { if (script_source.GetCachedData()) {
int length = script_source.GetCachedData()->length; int length = script_source.GetCachedData()->length;
uint8_t* cache = new uint8_t[length]; uint8_t* cache = new uint8_t[length];
...@@ -283,16 +289,17 @@ ScriptCompiler::CachedData* CompileForCachedData( ...@@ -283,16 +289,17 @@ ScriptCompiler::CachedData* CompileForCachedData(
// Compile a string within the current v8 context. // Compile a string within the current v8 context.
Local<Script> Shell::CompileString( MaybeLocal<Script> Shell::CompileString(
Isolate* isolate, Local<String> source, Local<Value> name, Isolate* isolate, Local<String> source, Local<Value> name,
ScriptCompiler::CompileOptions compile_options, SourceType source_type) { ScriptCompiler::CompileOptions compile_options, SourceType source_type) {
Local<Context> context(isolate->GetCurrentContext());
ScriptOrigin origin(name); ScriptOrigin origin(name);
if (compile_options == ScriptCompiler::kNoCompileOptions) { if (compile_options == ScriptCompiler::kNoCompileOptions) {
ScriptCompiler::Source script_source(source, origin); ScriptCompiler::Source script_source(source, origin);
return source_type == SCRIPT return source_type == SCRIPT
? ScriptCompiler::Compile(isolate, &script_source, ? ScriptCompiler::Compile(context, &script_source,
compile_options) compile_options)
: ScriptCompiler::CompileModule(isolate, &script_source, : ScriptCompiler::CompileModule(context, &script_source,
compile_options); compile_options);
} }
...@@ -307,10 +314,10 @@ Local<Script> Shell::CompileString( ...@@ -307,10 +314,10 @@ Local<Script> Shell::CompileString(
DCHECK(false); // A new compile option? DCHECK(false); // A new compile option?
} }
if (data == NULL) compile_options = ScriptCompiler::kNoCompileOptions; if (data == NULL) compile_options = ScriptCompiler::kNoCompileOptions;
Local<Script> result = MaybeLocal<Script> result =
source_type == SCRIPT source_type == SCRIPT
? ScriptCompiler::Compile(isolate, &cached_source, compile_options) ? ScriptCompiler::Compile(context, &cached_source, compile_options)
: ScriptCompiler::CompileModule(isolate, &cached_source, : ScriptCompiler::CompileModule(context, &cached_source,
compile_options); compile_options);
CHECK(data == NULL || !data->rejected); CHECK(data == NULL || !data->rejected);
return result; return result;
...@@ -318,8 +325,8 @@ Local<Script> Shell::CompileString( ...@@ -318,8 +325,8 @@ Local<Script> Shell::CompileString(
// Executes a string within the current v8 context. // Executes a string within the current v8 context.
bool Shell::ExecuteString(Isolate* isolate, Handle<String> source, bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
Handle<Value> name, bool print_result, Local<Value> name, bool print_result,
bool report_exceptions, SourceType source_type) { bool report_exceptions, SourceType source_type) {
#ifndef V8_SHARED #ifndef V8_SHARED
bool FLAG_debugger = i::FLAG_debugger; bool FLAG_debugger = i::FLAG_debugger;
...@@ -334,25 +341,26 @@ bool Shell::ExecuteString(Isolate* isolate, Handle<String> source, ...@@ -334,25 +341,26 @@ bool Shell::ExecuteString(Isolate* isolate, Handle<String> source,
try_catch.SetVerbose(true); try_catch.SetVerbose(true);
} }
Handle<Value> result; MaybeLocal<Value> maybe_result;
{ {
PerIsolateData* data = PerIsolateData::Get(isolate); PerIsolateData* data = PerIsolateData::Get(isolate);
Local<Context> realm = Local<Context> realm =
Local<Context>::New(isolate, data->realms_[data->realm_current_]); Local<Context>::New(isolate, data->realms_[data->realm_current_]);
Context::Scope context_scope(realm); Context::Scope context_scope(realm);
Handle<Script> script = Shell::CompileString( Local<Script> script;
isolate, source, name, options.compile_options, source_type); if (!Shell::CompileString(isolate, source, name, options.compile_options,
if (script.IsEmpty()) { source_type).ToLocal(&script)) {
// Print errors that happened during compilation. // Print errors that happened during compilation.
if (report_exceptions && !FLAG_debugger) if (report_exceptions && !FLAG_debugger)
ReportException(isolate, &try_catch); ReportException(isolate, &try_catch);
return false; return false;
} }
result = script->Run(); maybe_result = script->Run(realm);
EmptyMessageQueues(isolate); EmptyMessageQueues(isolate);
data->realm_current_ = data->realm_switch_; data->realm_current_ = data->realm_switch_;
} }
if (result.IsEmpty()) { Local<Value> result;
if (!maybe_result.ToLocal(&result)) {
DCHECK(try_catch.HasCaught()); DCHECK(try_catch.HasCaught());
// Print errors that happened during execution. // Print errors that happened during execution.
if (report_exceptions && !FLAG_debugger) if (report_exceptions && !FLAG_debugger)
...@@ -377,12 +385,19 @@ bool Shell::ExecuteString(Isolate* isolate, Handle<String> source, ...@@ -377,12 +385,19 @@ bool Shell::ExecuteString(Isolate* isolate, Handle<String> source,
v8::Local<v8::Context> context = v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate, utility_context_); v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
Handle<Object> global = context->Global(); Local<Object> global = context->Global();
Handle<Value> fun = Local<Value> fun =
global->Get(String::NewFromUtf8(isolate, "Stringify")); global->Get(context, String::NewFromUtf8(isolate, "Stringify",
Handle<Value> argv[1] = {result}; v8::NewStringType::kNormal)
Handle<Value> s = Handle<Function>::Cast(fun)->Call(global, 1, argv); .ToLocalChecked()).ToLocalChecked();
if (try_catch.HasCaught()) return true; Local<Value> argv[1] = {result};
Local<Value> s;
if (!Local<Function>::Cast(fun)
->Call(context, global, 1, argv)
.ToLocal(&s)) {
return true;
}
DCHECK(!try_catch.HasCaught());
v8::String::Utf8Value str(s); v8::String::Utf8Value str(s);
fwrite(*str, sizeof(**str), str.length(), stdout); fwrite(*str, sizeof(**str), str.length(), stdout);
printf("\n"); printf("\n");
...@@ -397,7 +412,7 @@ PerIsolateData::RealmScope::RealmScope(PerIsolateData* data) : data_(data) { ...@@ -397,7 +412,7 @@ PerIsolateData::RealmScope::RealmScope(PerIsolateData* data) : data_(data) {
data_->realm_count_ = 1; data_->realm_count_ = 1;
data_->realm_current_ = 0; data_->realm_current_ = 0;
data_->realm_switch_ = 0; data_->realm_switch_ = 0;
data_->realms_ = new Persistent<Context>[1]; data_->realms_ = new Global<Context>[1];
data_->realms_[0].Reset(data_->isolate_, data_->realms_[0].Reset(data_->isolate_,
data_->isolate_->GetEnteredContext()); data_->isolate_->GetEnteredContext());
} }
...@@ -413,7 +428,7 @@ PerIsolateData::RealmScope::~RealmScope() { ...@@ -413,7 +428,7 @@ PerIsolateData::RealmScope::~RealmScope() {
} }
int PerIsolateData::RealmFind(Handle<Context> context) { int PerIsolateData::RealmFind(Local<Context> context) {
for (int i = 0; i < realm_count_; ++i) { for (int i = 0; i < realm_count_; ++i) {
if (realms_[i] == context) return i; if (realms_[i] == context) return i;
} }
...@@ -428,10 +443,10 @@ int PerIsolateData::RealmIndexOrThrow( ...@@ -428,10 +443,10 @@ int PerIsolateData::RealmIndexOrThrow(
Throw(args.GetIsolate(), "Invalid argument"); Throw(args.GetIsolate(), "Invalid argument");
return -1; return -1;
} }
int index = args[arg_offset]->Int32Value(); int index = args[arg_offset]
if (index < 0 || ->Int32Value(args.GetIsolate()->GetCurrentContext())
index >= realm_count_ || .FromMaybe(-1);
realms_[index].IsEmpty()) { if (index < 0 || index >= realm_count_ || realms_[index].IsEmpty()) {
Throw(args.GetIsolate(), "Invalid realm index"); Throw(args.GetIsolate(), "Invalid realm index");
return -1; return -1;
} }
...@@ -475,7 +490,10 @@ void Shell::RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -475,7 +490,10 @@ void Shell::RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args) {
Throw(args.GetIsolate(), "Invalid argument"); Throw(args.GetIsolate(), "Invalid argument");
return; return;
} }
int index = data->RealmFind(args[0]->ToObject(isolate)->CreationContext()); int index = data->RealmFind(args[0]
->ToObject(isolate->GetCurrentContext())
.ToLocalChecked()
->CreationContext());
if (index == -1) return; if (index == -1) return;
args.GetReturnValue().Set(index); args.GetReturnValue().Set(index);
} }
...@@ -497,15 +515,15 @@ void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -497,15 +515,15 @@ void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate(); Isolate* isolate = args.GetIsolate();
TryCatch try_catch(isolate); TryCatch try_catch(isolate);
PerIsolateData* data = PerIsolateData::Get(isolate); PerIsolateData* data = PerIsolateData::Get(isolate);
Persistent<Context>* old_realms = data->realms_; Global<Context>* old_realms = data->realms_;
int index = data->realm_count_; int index = data->realm_count_;
data->realms_ = new Persistent<Context>[++data->realm_count_]; data->realms_ = new Global<Context>[++data->realm_count_];
for (int i = 0; i < index; ++i) { for (int i = 0; i < index; ++i) {
data->realms_[i].Reset(isolate, old_realms[i]); data->realms_[i].Reset(isolate, old_realms[i]);
old_realms[i].Reset(); old_realms[i].Reset();
} }
delete[] old_realms; delete[] old_realms;
Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
Local<Context> context = Context::New(isolate, NULL, global_template); Local<Context> context = Context::New(isolate, NULL, global_template);
if (context.IsEmpty()) { if (context.IsEmpty()) {
DCHECK(try_catch.HasCaught()); DCHECK(try_catch.HasCaught());
...@@ -554,13 +572,20 @@ void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -554,13 +572,20 @@ void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) {
Throw(args.GetIsolate(), "Invalid argument"); Throw(args.GetIsolate(), "Invalid argument");
return; return;
} }
ScriptCompiler::Source script_source(args[1]->ToString(isolate)); ScriptCompiler::Source script_source(
Handle<UnboundScript> script = ScriptCompiler::CompileUnbound( args[1]->ToString(isolate->GetCurrentContext()).ToLocalChecked());
isolate, &script_source); Local<UnboundScript> script;
if (script.IsEmpty()) return; if (!ScriptCompiler::CompileUnboundScript(isolate, &script_source)
.ToLocal(&script)) {
return;
}
Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]); Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]);
realm->Enter(); realm->Enter();
Handle<Value> result = script->BindToCurrentContext()->Run(); Local<Value> result;
if (!script->BindToCurrentContext()->Run(realm).ToLocal(&result)) {
realm->Exit();
return;
}
realm->Exit(); realm->Exit();
args.GetReturnValue().Set(result); args.GetReturnValue().Set(result);
} }
...@@ -600,8 +625,10 @@ void Shell::Write(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -600,8 +625,10 @@ void Shell::Write(const v8::FunctionCallbackInfo<v8::Value>& args) {
// Explicitly catch potential exceptions in toString(). // Explicitly catch potential exceptions in toString().
v8::TryCatch try_catch(args.GetIsolate()); v8::TryCatch try_catch(args.GetIsolate());
Handle<String> str_obj = args[i]->ToString(args.GetIsolate()); Local<String> str_obj;
if (try_catch.HasCaught()) { if (!args[i]
->ToString(args.GetIsolate()->GetCurrentContext())
.ToLocal(&str_obj)) {
try_catch.ReThrow(); try_catch.ReThrow();
return; return;
} }
...@@ -622,7 +649,7 @@ void Shell::Read(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -622,7 +649,7 @@ void Shell::Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
Throw(args.GetIsolate(), "Error loading file"); Throw(args.GetIsolate(), "Error loading file");
return; return;
} }
Handle<String> source = ReadFile(args.GetIsolate(), *file); Local<String> source = ReadFile(args.GetIsolate(), *file);
if (source.IsEmpty()) { if (source.IsEmpty()) {
Throw(args.GetIsolate(), "Error loading file"); Throw(args.GetIsolate(), "Error loading file");
return; return;
...@@ -631,10 +658,11 @@ void Shell::Read(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -631,10 +658,11 @@ void Shell::Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
} }
Handle<String> Shell::ReadFromStdin(Isolate* isolate) { Local<String> Shell::ReadFromStdin(Isolate* isolate) {
static const int kBufferSize = 256; static const int kBufferSize = 256;
char buffer[kBufferSize]; char buffer[kBufferSize];
Handle<String> accumulator = String::NewFromUtf8(isolate, ""); Local<String> accumulator =
String::NewFromUtf8(isolate, "", NewStringType::kNormal).ToLocalChecked();
int length; int length;
while (true) { while (true) {
// Continue reading if the line ends with an escape '\\' or the line has // Continue reading if the line ends with an escape '\\' or the line has
...@@ -642,23 +670,26 @@ Handle<String> Shell::ReadFromStdin(Isolate* isolate) { ...@@ -642,23 +670,26 @@ Handle<String> Shell::ReadFromStdin(Isolate* isolate) {
// If fgets gets an error, just give up. // If fgets gets an error, just give up.
char* input = NULL; char* input = NULL;
input = fgets(buffer, kBufferSize, stdin); input = fgets(buffer, kBufferSize, stdin);
if (input == NULL) return Handle<String>(); if (input == NULL) return Local<String>();
length = static_cast<int>(strlen(buffer)); length = static_cast<int>(strlen(buffer));
if (length == 0) { if (length == 0) {
return accumulator; return accumulator;
} else if (buffer[length-1] != '\n') { } else if (buffer[length-1] != '\n') {
accumulator = String::Concat( accumulator = String::Concat(
accumulator, accumulator,
String::NewFromUtf8(isolate, buffer, String::kNormalString, length)); String::NewFromUtf8(isolate, buffer, NewStringType::kNormal, length)
.ToLocalChecked());
} else if (length > 1 && buffer[length-2] == '\\') { } else if (length > 1 && buffer[length-2] == '\\') {
buffer[length-2] = '\n'; buffer[length-2] = '\n';
accumulator = String::Concat( accumulator = String::Concat(
accumulator, String::NewFromUtf8(isolate, buffer, accumulator,
String::kNormalString, length - 1)); String::NewFromUtf8(isolate, buffer, NewStringType::kNormal,
length - 1).ToLocalChecked());
} else { } else {
return String::Concat( return String::Concat(
accumulator, String::NewFromUtf8(isolate, buffer, accumulator,
String::kNormalString, length - 1)); String::NewFromUtf8(isolate, buffer, NewStringType::kNormal,
length - 1).ToLocalChecked());
} }
} }
} }
...@@ -672,16 +703,16 @@ void Shell::Load(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -672,16 +703,16 @@ void Shell::Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
Throw(args.GetIsolate(), "Error loading file"); Throw(args.GetIsolate(), "Error loading file");
return; return;
} }
Handle<String> source = ReadFile(args.GetIsolate(), *file); Local<String> source = ReadFile(args.GetIsolate(), *file);
if (source.IsEmpty()) { if (source.IsEmpty()) {
Throw(args.GetIsolate(), "Error loading file"); Throw(args.GetIsolate(), "Error loading file");
return; return;
} }
if (!ExecuteString(args.GetIsolate(), if (!ExecuteString(
source, args.GetIsolate(), source,
String::NewFromUtf8(args.GetIsolate(), *file), String::NewFromUtf8(args.GetIsolate(), *file,
false, NewStringType::kNormal).ToLocalChecked(),
true)) { false, true)) {
Throw(args.GetIsolate(), "Error executing file"); Throw(args.GetIsolate(), "Error executing file");
return; return;
} }
...@@ -735,7 +766,7 @@ void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -735,7 +766,7 @@ void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
Worker* worker = Worker* worker =
static_cast<Worker*>(Local<External>::Cast(this_value)->Value()); static_cast<Worker*>(Local<External>::Cast(this_value)->Value());
Handle<Value> message = args[0]; Local<Value> message = args[0];
ObjectList to_transfer; ObjectList to_transfer;
if (args.Length() >= 2) { if (args.Length() >= 2) {
if (!args[1]->IsArray()) { if (!args[1]->IsArray()) {
...@@ -743,10 +774,10 @@ void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -743,10 +774,10 @@ void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
return; return;
} }
Handle<Array> transfer = Handle<Array>::Cast(args[1]); Local<Array> transfer = Local<Array>::Cast(args[1]);
uint32_t length = transfer->Length(); uint32_t length = transfer->Length();
for (uint32_t i = 0; i < length; ++i) { for (uint32_t i = 0; i < length; ++i) {
Handle<Value> element; Local<Value> element;
if (transfer->Get(context, i).ToLocal(&element)) { if (transfer->Get(context, i).ToLocal(&element)) {
if (!element->IsArrayBuffer() && !element->IsSharedArrayBuffer()) { if (!element->IsArrayBuffer() && !element->IsSharedArrayBuffer()) {
Throw(isolate, Throw(isolate,
...@@ -755,7 +786,7 @@ void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -755,7 +786,7 @@ void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
break; break;
} }
to_transfer.Add(Handle<Object>::Cast(element)); to_transfer.Add(Local<Object>::Cast(element));
} }
} }
} }
...@@ -812,7 +843,9 @@ void Shell::WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -812,7 +843,9 @@ void Shell::WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Shell::QuitOnce(v8::FunctionCallbackInfo<v8::Value>* args) { void Shell::QuitOnce(v8::FunctionCallbackInfo<v8::Value>* args) {
int exit_code = (*args)[0]->Int32Value(); int exit_code = (*args)[0]
->Int32Value(args->GetIsolate()->GetCurrentContext())
.FromMaybe(0);
#ifndef V8_SHARED #ifndef V8_SHARED
CleanupWorkers(); CleanupWorkers();
#endif // !V8_SHARED #endif // !V8_SHARED
...@@ -829,14 +862,15 @@ void Shell::Quit(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -829,14 +862,15 @@ void Shell::Quit(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Shell::Version(const v8::FunctionCallbackInfo<v8::Value>& args) { void Shell::Version(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set( args.GetReturnValue().Set(
String::NewFromUtf8(args.GetIsolate(), V8::GetVersion())); String::NewFromUtf8(args.GetIsolate(), V8::GetVersion(),
NewStringType::kNormal).ToLocalChecked());
} }
void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) { void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
HandleScope handle_scope(isolate); HandleScope handle_scope(isolate);
#ifndef V8_SHARED #ifndef V8_SHARED
Handle<Context> utility_context; Local<Context> utility_context;
bool enter_context = !isolate->InContext(); bool enter_context = !isolate->InContext();
if (enter_context) { if (enter_context) {
utility_context = Local<Context>::New(isolate, utility_context_); utility_context = Local<Context>::New(isolate, utility_context_);
...@@ -845,7 +879,7 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) { ...@@ -845,7 +879,7 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
#endif // !V8_SHARED #endif // !V8_SHARED
v8::String::Utf8Value exception(try_catch->Exception()); v8::String::Utf8Value exception(try_catch->Exception());
const char* exception_string = ToCString(exception); const char* exception_string = ToCString(exception);
Handle<Message> message = try_catch->Message(); Local<Message> message = try_catch->Message();
if (message.IsEmpty()) { if (message.IsEmpty()) {
// V8 didn't provide any extra information about this error; just // V8 didn't provide any extra information about this error; just
// print the exception. // print the exception.
...@@ -854,26 +888,31 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) { ...@@ -854,26 +888,31 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
// Print (filename):(line number): (message). // Print (filename):(line number): (message).
v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName()); v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
const char* filename_string = ToCString(filename); const char* filename_string = ToCString(filename);
int linenum = message->GetLineNumber(); int linenum =
message->GetLineNumber(isolate->GetCurrentContext()).FromJust();
printf("%s:%i: %s\n", filename_string, linenum, exception_string); printf("%s:%i: %s\n", filename_string, linenum, exception_string);
// Print line of source code. // Print line of source code.
v8::String::Utf8Value sourceline(message->GetSourceLine()); v8::String::Utf8Value sourceline(
message->GetSourceLine(isolate->GetCurrentContext()).ToLocalChecked());
const char* sourceline_string = ToCString(sourceline); const char* sourceline_string = ToCString(sourceline);
printf("%s\n", sourceline_string); printf("%s\n", sourceline_string);
// Print wavy underline (GetUnderline is deprecated). // Print wavy underline (GetUnderline is deprecated).
int start = message->GetStartColumn(); int start =
message->GetStartColumn(isolate->GetCurrentContext()).FromJust();
for (int i = 0; i < start; i++) { for (int i = 0; i < start; i++) {
printf(" "); printf(" ");
} }
int end = message->GetEndColumn(); int end = message->GetEndColumn(isolate->GetCurrentContext()).FromJust();
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
printf("^"); printf("^");
} }
printf("\n"); printf("\n");
v8::String::Utf8Value stack_trace(try_catch->StackTrace()); Local<Value> stack_trace_string;
if (stack_trace.length() > 0) { if (try_catch->StackTrace(isolate->GetCurrentContext())
const char* stack_trace_string = ToCString(stack_trace); .ToLocal(&stack_trace_string)) {
printf("%s\n", stack_trace_string); v8::String::Utf8Value stack_trace(
Local<String>::Cast(stack_trace_string));
printf("%s\n", ToCString(stack_trace));
} }
} }
printf("\n"); printf("\n");
...@@ -884,53 +923,65 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) { ...@@ -884,53 +923,65 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
#ifndef V8_SHARED #ifndef V8_SHARED
Handle<Array> Shell::GetCompletions(Isolate* isolate, Local<Array> Shell::GetCompletions(Isolate* isolate, Local<String> text,
Handle<String> text, Local<String> full) {
Handle<String> full) {
EscapableHandleScope handle_scope(isolate); EscapableHandleScope handle_scope(isolate);
v8::Local<v8::Context> utility_context = v8::Local<v8::Context> utility_context =
v8::Local<v8::Context>::New(isolate, utility_context_); v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(utility_context); v8::Context::Scope context_scope(utility_context);
Handle<Object> global = utility_context->Global(); Local<Object> global = utility_context->Global();
Local<Value> fun = Local<Value> fun = global->Get(utility_context,
global->Get(String::NewFromUtf8(isolate, "GetCompletions")); String::NewFromUtf8(isolate, "GetCompletions",
NewStringType::kNormal)
.ToLocalChecked()).ToLocalChecked();
static const int kArgc = 3; static const int kArgc = 3;
v8::Local<v8::Context> evaluation_context = v8::Local<v8::Context> evaluation_context =
v8::Local<v8::Context>::New(isolate, evaluation_context_); v8::Local<v8::Context>::New(isolate, evaluation_context_);
Handle<Value> argv[kArgc] = { evaluation_context->Global(), text, full }; Local<Value> argv[kArgc] = {evaluation_context->Global(), text, full};
Local<Value> val = Local<Function>::Cast(fun)->Call(global, kArgc, argv); Local<Value> val = Local<Function>::Cast(fun)
->Call(utility_context, global, kArgc, argv)
.ToLocalChecked();
return handle_scope.Escape(Local<Array>::Cast(val)); return handle_scope.Escape(Local<Array>::Cast(val));
} }
Local<Object> Shell::DebugMessageDetails(Isolate* isolate, Local<Object> Shell::DebugMessageDetails(Isolate* isolate,
Handle<String> message) { Local<String> message) {
EscapableHandleScope handle_scope(isolate); EscapableHandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate, utility_context_); v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
Handle<Object> global = context->Global(); Local<Object> global = context->Global();
Handle<Value> fun = Local<Value> fun =
global->Get(String::NewFromUtf8(isolate, "DebugMessageDetails")); global->Get(context, String::NewFromUtf8(isolate, "DebugMessageDetails",
NewStringType::kNormal)
.ToLocalChecked()).ToLocalChecked();
static const int kArgc = 1; static const int kArgc = 1;
Handle<Value> argv[kArgc] = { message }; Local<Value> argv[kArgc] = {message};
Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); Local<Value> val = Local<Function>::Cast(fun)
return handle_scope.Escape(Local<Object>(Handle<Object>::Cast(val))); ->Call(context, global, kArgc, argv)
.ToLocalChecked();
return handle_scope.Escape(Local<Object>(Local<Object>::Cast(val)));
} }
Local<Value> Shell::DebugCommandToJSONRequest(Isolate* isolate, Local<Value> Shell::DebugCommandToJSONRequest(Isolate* isolate,
Handle<String> command) { Local<String> command) {
EscapableHandleScope handle_scope(isolate); EscapableHandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate, utility_context_); v8::Local<v8::Context>::New(isolate, utility_context_);
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
Handle<Object> global = context->Global(); Local<Object> global = context->Global();
Handle<Value> fun = Local<Value> fun =
global->Get(String::NewFromUtf8(isolate, "DebugCommandToJSONRequest")); global->Get(context,
String::NewFromUtf8(isolate, "DebugCommandToJSONRequest",
NewStringType::kNormal).ToLocalChecked())
.ToLocalChecked();
static const int kArgc = 1; static const int kArgc = 1;
Handle<Value> argv[kArgc] = { command }; Local<Value> argv[kArgc] = {command};
Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); Local<Value> val = Local<Function>::Cast(fun)
->Call(context, global, kArgc, argv)
.ToLocalChecked();
return handle_scope.Escape(Local<Value>(val)); return handle_scope.Escape(Local<Value>(val));
} }
...@@ -1065,8 +1116,12 @@ void Shell::InstallUtilityScript(Isolate* isolate) { ...@@ -1065,8 +1116,12 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
i::Handle<i::Context> debug_context = debug->debug_context(); i::Handle<i::Context> debug_context = debug->debug_context();
i::Handle<i::JSObject> js_debug i::Handle<i::JSObject> js_debug
= i::Handle<i::JSObject>(debug_context->global_object()); = i::Handle<i::JSObject>(debug_context->global_object());
utility_context->Global()->Set(String::NewFromUtf8(isolate, "$debug"), utility_context->Global()
Utils::ToLocal(js_debug)); ->Set(utility_context,
String::NewFromUtf8(isolate, "$debug", NewStringType::kNormal)
.ToLocalChecked(),
Utils::ToLocal(js_debug))
.FromJust();
debug_context->set_security_token( debug_context->set_security_token(
reinterpret_cast<i::Isolate*>(isolate)->heap()->undefined_value()); reinterpret_cast<i::Isolate*>(isolate)->heap()->undefined_value());
...@@ -1076,15 +1131,17 @@ void Shell::InstallUtilityScript(Isolate* isolate) { ...@@ -1076,15 +1131,17 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
i::NativesCollection<i::D8>::GetScriptSource(source_index); i::NativesCollection<i::D8>::GetScriptSource(source_index);
i::Vector<const char> shell_source_name = i::Vector<const char> shell_source_name =
i::NativesCollection<i::D8>::GetScriptName(source_index); i::NativesCollection<i::D8>::GetScriptName(source_index);
Handle<String> source = Local<String> source =
String::NewFromUtf8(isolate, shell_source.start(), String::kNormalString, String::NewFromUtf8(isolate, shell_source.start(), NewStringType::kNormal,
shell_source.length()); shell_source.length()).ToLocalChecked();
Handle<String> name = Local<String> name =
String::NewFromUtf8(isolate, shell_source_name.start(), String::NewFromUtf8(isolate, shell_source_name.start(),
String::kNormalString, shell_source_name.length()); NewStringType::kNormal,
shell_source_name.length()).ToLocalChecked();
ScriptOrigin origin(name); ScriptOrigin origin(name);
Handle<Script> script = Script::Compile(source, &origin); Local<Script> script =
script->Run(); Script::Compile(utility_context, source, &origin).ToLocalChecked();
script->Run(utility_context).ToLocalChecked();
// Mark the d8 shell script as native to avoid it showing up as normal source // Mark the d8 shell script as native to avoid it showing up as normal source
// in the debugger. // in the debugger.
i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script); i::Handle<i::Object> compiled_script = Utils::OpenHandle(*script);
...@@ -1101,76 +1158,123 @@ void Shell::InstallUtilityScript(Isolate* isolate) { ...@@ -1101,76 +1158,123 @@ void Shell::InstallUtilityScript(Isolate* isolate) {
#endif // !V8_SHARED #endif // !V8_SHARED
Handle<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) { Local<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
Handle<ObjectTemplate> global_template = ObjectTemplate::New(isolate); Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
global_template->Set(String::NewFromUtf8(isolate, "print"), global_template->Set(
String::NewFromUtf8(isolate, "print", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, Print)); FunctionTemplate::New(isolate, Print));
global_template->Set(String::NewFromUtf8(isolate, "write"), global_template->Set(
String::NewFromUtf8(isolate, "write", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, Write)); FunctionTemplate::New(isolate, Write));
global_template->Set(String::NewFromUtf8(isolate, "read"), global_template->Set(
String::NewFromUtf8(isolate, "read", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, Read)); FunctionTemplate::New(isolate, Read));
global_template->Set(String::NewFromUtf8(isolate, "readbuffer"), global_template->Set(
String::NewFromUtf8(isolate, "readbuffer", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, ReadBuffer)); FunctionTemplate::New(isolate, ReadBuffer));
global_template->Set(String::NewFromUtf8(isolate, "readline"), global_template->Set(
String::NewFromUtf8(isolate, "readline", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, ReadLine)); FunctionTemplate::New(isolate, ReadLine));
global_template->Set(String::NewFromUtf8(isolate, "load"), global_template->Set(
String::NewFromUtf8(isolate, "load", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, Load)); FunctionTemplate::New(isolate, Load));
// Some Emscripten-generated code tries to call 'quit', which in turn would // Some Emscripten-generated code tries to call 'quit', which in turn would
// call C's exit(). This would lead to memory leaks, because there is no way // call C's exit(). This would lead to memory leaks, because there is no way
// we can terminate cleanly then, so we need a way to hide 'quit'. // we can terminate cleanly then, so we need a way to hide 'quit'.
if (!options.omit_quit) { if (!options.omit_quit) {
global_template->Set(String::NewFromUtf8(isolate, "quit"), global_template->Set(
String::NewFromUtf8(isolate, "quit", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, Quit)); FunctionTemplate::New(isolate, Quit));
} }
global_template->Set(String::NewFromUtf8(isolate, "version"), global_template->Set(
String::NewFromUtf8(isolate, "version", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, Version)); FunctionTemplate::New(isolate, Version));
// Bind the Realm object. // Bind the Realm object.
Handle<ObjectTemplate> realm_template = ObjectTemplate::New(isolate); Local<ObjectTemplate> realm_template = ObjectTemplate::New(isolate);
realm_template->Set(String::NewFromUtf8(isolate, "current"), realm_template->Set(
String::NewFromUtf8(isolate, "current", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmCurrent)); FunctionTemplate::New(isolate, RealmCurrent));
realm_template->Set(String::NewFromUtf8(isolate, "owner"), realm_template->Set(
String::NewFromUtf8(isolate, "owner", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmOwner)); FunctionTemplate::New(isolate, RealmOwner));
realm_template->Set(String::NewFromUtf8(isolate, "global"), realm_template->Set(
String::NewFromUtf8(isolate, "global", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmGlobal)); FunctionTemplate::New(isolate, RealmGlobal));
realm_template->Set(String::NewFromUtf8(isolate, "create"), realm_template->Set(
String::NewFromUtf8(isolate, "create", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmCreate)); FunctionTemplate::New(isolate, RealmCreate));
realm_template->Set(String::NewFromUtf8(isolate, "dispose"), realm_template->Set(
String::NewFromUtf8(isolate, "dispose", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmDispose)); FunctionTemplate::New(isolate, RealmDispose));
realm_template->Set(String::NewFromUtf8(isolate, "switch"), realm_template->Set(
String::NewFromUtf8(isolate, "switch", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmSwitch)); FunctionTemplate::New(isolate, RealmSwitch));
realm_template->Set(String::NewFromUtf8(isolate, "eval"), realm_template->Set(
String::NewFromUtf8(isolate, "eval", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmEval)); FunctionTemplate::New(isolate, RealmEval));
realm_template->SetAccessor(String::NewFromUtf8(isolate, "shared"), realm_template->SetAccessor(
String::NewFromUtf8(isolate, "shared", NewStringType::kNormal)
.ToLocalChecked(),
RealmSharedGet, RealmSharedSet); RealmSharedGet, RealmSharedSet);
global_template->Set(String::NewFromUtf8(isolate, "Realm"), realm_template); global_template->Set(
String::NewFromUtf8(isolate, "Realm", NewStringType::kNormal)
.ToLocalChecked(),
realm_template);
#ifndef V8_SHARED #ifndef V8_SHARED
Handle<ObjectTemplate> performance_template = ObjectTemplate::New(isolate); Local<ObjectTemplate> performance_template = ObjectTemplate::New(isolate);
performance_template->Set(String::NewFromUtf8(isolate, "now"), performance_template->Set(
String::NewFromUtf8(isolate, "now", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, PerformanceNow)); FunctionTemplate::New(isolate, PerformanceNow));
global_template->Set(String::NewFromUtf8(isolate, "performance"), global_template->Set(
String::NewFromUtf8(isolate, "performance", NewStringType::kNormal)
.ToLocalChecked(),
performance_template); performance_template);
Handle<FunctionTemplate> worker_fun_template = Local<FunctionTemplate> worker_fun_template =
FunctionTemplate::New(isolate, WorkerNew); FunctionTemplate::New(isolate, WorkerNew);
worker_fun_template->PrototypeTemplate()->Set( worker_fun_template->PrototypeTemplate()->Set(
String::NewFromUtf8(isolate, "terminate"), String::NewFromUtf8(isolate, "terminate", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, WorkerTerminate)); FunctionTemplate::New(isolate, WorkerTerminate));
worker_fun_template->PrototypeTemplate()->Set( worker_fun_template->PrototypeTemplate()->Set(
String::NewFromUtf8(isolate, "postMessage"), String::NewFromUtf8(isolate, "postMessage", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, WorkerPostMessage)); FunctionTemplate::New(isolate, WorkerPostMessage));
worker_fun_template->PrototypeTemplate()->Set( worker_fun_template->PrototypeTemplate()->Set(
String::NewFromUtf8(isolate, "getMessage"), String::NewFromUtf8(isolate, "getMessage", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, WorkerGetMessage)); FunctionTemplate::New(isolate, WorkerGetMessage));
worker_fun_template->InstanceTemplate()->SetInternalFieldCount(1); worker_fun_template->InstanceTemplate()->SetInternalFieldCount(1);
global_template->Set(String::NewFromUtf8(isolate, "Worker"), global_template->Set(
String::NewFromUtf8(isolate, "Worker", NewStringType::kNormal)
.ToLocalChecked(),
worker_fun_template); worker_fun_template);
#endif // !V8_SHARED #endif // !V8_SHARED
Handle<ObjectTemplate> os_templ = ObjectTemplate::New(isolate); Local<ObjectTemplate> os_templ = ObjectTemplate::New(isolate);
AddOSMethods(isolate, os_templ); AddOSMethods(isolate, os_templ);
global_template->Set(String::NewFromUtf8(isolate, "os"), os_templ); global_template->Set(
String::NewFromUtf8(isolate, "os", NewStringType::kNormal)
.ToLocalChecked(),
os_templ);
return global_template; return global_template;
} }
...@@ -1189,7 +1293,7 @@ void Shell::InitializeDebugger(Isolate* isolate) { ...@@ -1189,7 +1293,7 @@ void Shell::InitializeDebugger(Isolate* isolate) {
if (options.test_shell) return; if (options.test_shell) return;
#ifndef V8_SHARED #ifndef V8_SHARED
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
utility_context_.Reset(isolate, utility_context_.Reset(isolate,
Context::New(isolate, NULL, global_template)); Context::New(isolate, NULL, global_template));
if (utility_context_.IsEmpty()) { if (utility_context_.IsEmpty()) {
...@@ -1206,7 +1310,7 @@ Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { ...@@ -1206,7 +1310,7 @@ Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
base::LockGuard<base::Mutex> lock_guard(context_mutex_.Pointer()); base::LockGuard<base::Mutex> lock_guard(context_mutex_.Pointer());
#endif // !V8_SHARED #endif // !V8_SHARED
// Initialize the global objects // Initialize the global objects
Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
EscapableHandleScope handle_scope(isolate); EscapableHandleScope handle_scope(isolate);
Local<Context> context = Context::New(isolate, NULL, global_template); Local<Context> context = Context::New(isolate, NULL, global_template);
DCHECK(!context.IsEmpty()); DCHECK(!context.IsEmpty());
...@@ -1224,8 +1328,12 @@ Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { ...@@ -1224,8 +1328,12 @@ Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
} }
i::Handle<i::JSArray> arguments_jsarray = i::Handle<i::JSArray> arguments_jsarray =
factory->NewJSArrayWithElements(arguments_array); factory->NewJSArrayWithElements(arguments_array);
context->Global()->Set(String::NewFromUtf8(isolate, "arguments"), context->Global()
Utils::ToLocal(arguments_jsarray)); ->Set(context,
String::NewFromUtf8(isolate, "arguments", NewStringType::kNormal)
.ToLocalChecked(),
Utils::ToLocal(arguments_jsarray))
.FromJust();
#endif // !V8_SHARED #endif // !V8_SHARED
return handle_scope.Escape(context); return handle_scope.Escape(context);
} }
...@@ -1380,8 +1488,7 @@ void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1380,8 +1488,7 @@ void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
return; return;
} }
data->byte_length = length; data->byte_length = length;
Handle<v8::ArrayBuffer> buffer = Local<v8::ArrayBuffer> buffer = ArrayBuffer::New(isolate, data->data, length);
ArrayBuffer::New(isolate, data->data, length);
data->handle.Reset(isolate, buffer); data->handle.Reset(isolate, buffer);
data->handle.SetWeak(data, ReadBufferWeakCallback, data->handle.SetWeak(data, ReadBufferWeakCallback,
v8::WeakCallbackType::kParameter); v8::WeakCallbackType::kParameter);
...@@ -1393,12 +1500,13 @@ void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1393,12 +1500,13 @@ void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
// Reads a file into a v8 string. // Reads a file into a v8 string.
Handle<String> Shell::ReadFile(Isolate* isolate, const char* name) { Local<String> Shell::ReadFile(Isolate* isolate, const char* name) {
int size = 0; int size = 0;
char* chars = ReadChars(isolate, name, &size); char* chars = ReadChars(isolate, name, &size);
if (chars == NULL) return Handle<String>(); if (chars == NULL) return Local<String>();
Handle<String> result = Local<String> result =
String::NewFromUtf8(isolate, chars, String::kNormalString, size); String::NewFromUtf8(isolate, chars, NewStringType::kNormal, size)
.ToLocalChecked();
delete[] chars; delete[] chars;
return result; return result;
} }
...@@ -1410,13 +1518,15 @@ void Shell::RunShell(Isolate* isolate) { ...@@ -1410,13 +1518,15 @@ void Shell::RunShell(Isolate* isolate) {
v8::Local<v8::Context>::New(isolate, evaluation_context_); v8::Local<v8::Context>::New(isolate, evaluation_context_);
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
Handle<String> name = String::NewFromUtf8(isolate, "(d8)"); Local<String> name =
String::NewFromUtf8(isolate, "(d8)", NewStringType::kNormal)
.ToLocalChecked();
LineEditor* console = LineEditor::Get(); LineEditor* console = LineEditor::Get();
printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name());
console->Open(isolate); console->Open(isolate);
while (true) { while (true) {
HandleScope inner_scope(isolate); HandleScope inner_scope(isolate);
Handle<String> input = console->Prompt(Shell::kPrompt); Local<String> input = console->Prompt(Shell::kPrompt);
if (input.IsEmpty()) break; if (input.IsEmpty()) break;
ExecuteString(isolate, input, name, true, true); ExecuteString(isolate, input, name, true, true);
} }
...@@ -1440,8 +1550,12 @@ void SourceGroup::Execute(Isolate* isolate) { ...@@ -1440,8 +1550,12 @@ void SourceGroup::Execute(Isolate* isolate) {
if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) { if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) {
// Execute argument given to -e option directly. // Execute argument given to -e option directly.
HandleScope handle_scope(isolate); HandleScope handle_scope(isolate);
Handle<String> file_name = String::NewFromUtf8(isolate, "unnamed"); Local<String> file_name =
Handle<String> source = String::NewFromUtf8(isolate, argv_[i + 1]); String::NewFromUtf8(isolate, "unnamed", NewStringType::kNormal)
.ToLocalChecked();
Local<String> source =
String::NewFromUtf8(isolate, argv_[i + 1], NewStringType::kNormal)
.ToLocalChecked();
if (!Shell::ExecuteString(isolate, source, file_name, false, true)) { if (!Shell::ExecuteString(isolate, source, file_name, false, true)) {
exception_was_thrown = true; exception_was_thrown = true;
break; break;
...@@ -1459,8 +1573,10 @@ void SourceGroup::Execute(Isolate* isolate) { ...@@ -1459,8 +1573,10 @@ void SourceGroup::Execute(Isolate* isolate) {
// Use all other arguments as names of files to load and run. // Use all other arguments as names of files to load and run.
HandleScope handle_scope(isolate); HandleScope handle_scope(isolate);
Handle<String> file_name = String::NewFromUtf8(isolate, arg); Local<String> file_name =
Handle<String> source = ReadFile(isolate, arg); String::NewFromUtf8(isolate, arg, NewStringType::kNormal)
.ToLocalChecked();
Local<String> source = ReadFile(isolate, arg);
if (source.IsEmpty()) { if (source.IsEmpty()) {
printf("Error reading '%s'\n", arg); printf("Error reading '%s'\n", arg);
Shell::Exit(1); Shell::Exit(1);
...@@ -1477,12 +1593,13 @@ void SourceGroup::Execute(Isolate* isolate) { ...@@ -1477,12 +1593,13 @@ void SourceGroup::Execute(Isolate* isolate) {
} }
Handle<String> SourceGroup::ReadFile(Isolate* isolate, const char* name) { Local<String> SourceGroup::ReadFile(Isolate* isolate, const char* name) {
int size; int size;
char* chars = ReadChars(isolate, name, &size); char* chars = ReadChars(isolate, name, &size);
if (chars == NULL) return Handle<String>(); if (chars == NULL) return Local<String>();
Handle<String> result = Local<String> result =
String::NewFromUtf8(isolate, chars, String::kNormalString, size); String::NewFromUtf8(isolate, chars, NewStringType::kNormal, size)
.ToLocalChecked();
delete[] chars; delete[] chars;
return result; return result;
} }
...@@ -1735,27 +1852,35 @@ void Worker::ExecuteInThread() { ...@@ -1735,27 +1852,35 @@ void Worker::ExecuteInThread() {
Context::Scope cscope(context); Context::Scope cscope(context);
PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
Handle<Object> global = context->Global(); Local<Object> global = context->Global();
Handle<Value> this_value = External::New(isolate, this); Local<Value> this_value = External::New(isolate, this);
Handle<FunctionTemplate> postmessage_fun_template = Local<FunctionTemplate> postmessage_fun_template =
FunctionTemplate::New(isolate, PostMessageOut, this_value); FunctionTemplate::New(isolate, PostMessageOut, this_value);
Handle<Function> postmessage_fun; Local<Function> postmessage_fun;
if (postmessage_fun_template->GetFunction(context) if (postmessage_fun_template->GetFunction(context)
.ToLocal(&postmessage_fun)) { .ToLocal(&postmessage_fun)) {
global->Set(String::NewFromUtf8(isolate, "postMessage"), global->Set(context, String::NewFromUtf8(isolate, "postMessage",
postmessage_fun); NewStringType::kNormal)
.ToLocalChecked(),
postmessage_fun).FromJust();
} }
// First run the script // First run the script
Handle<String> file_name = String::NewFromUtf8(isolate, "unnamed"); Local<String> file_name =
Handle<String> source = String::NewFromUtf8(isolate, script_); String::NewFromUtf8(isolate, "unnamed", NewStringType::kNormal)
.ToLocalChecked();
Local<String> source =
String::NewFromUtf8(isolate, script_, NewStringType::kNormal)
.ToLocalChecked();
if (Shell::ExecuteString(isolate, source, file_name, false, true)) { if (Shell::ExecuteString(isolate, source, file_name, false, true)) {
// Get the message handler // Get the message handler
Handle<Value> onmessage = Local<Value> onmessage =
global->Get(String::NewFromUtf8(isolate, "onmessage")); global->Get(context, String::NewFromUtf8(isolate, "onmessage",
NewStringType::kNormal)
.ToLocalChecked()).ToLocalChecked();
if (onmessage->IsFunction()) { if (onmessage->IsFunction()) {
Handle<Function> onmessage_fun = Handle<Function>::Cast(onmessage); Local<Function> onmessage_fun = Local<Function>::Cast(onmessage);
// Now wait for messages // Now wait for messages
while (true) { while (true) {
in_semaphore_.Wait(); in_semaphore_.Wait();
...@@ -1768,7 +1893,7 @@ void Worker::ExecuteInThread() { ...@@ -1768,7 +1893,7 @@ void Worker::ExecuteInThread() {
Local<Value> data_value; Local<Value> data_value;
if (Shell::DeserializeValue(isolate, *data, &offset) if (Shell::DeserializeValue(isolate, *data, &offset)
.ToLocal(&data_value)) { .ToLocal(&data_value)) {
Handle<Value> argv[] = {data_value}; Local<Value> argv[] = {data_value};
(void)onmessage_fun->Call(context, global, 1, argv); (void)onmessage_fun->Call(context, global, 1, argv);
} }
delete data; delete data;
...@@ -1796,7 +1921,7 @@ void Worker::PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1796,7 +1921,7 @@ void Worker::PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args) {
return; return;
} }
Handle<Value> message = args[0]; Local<Value> message = args[0];
// TODO(binji): Allow transferring from worker to main thread? // TODO(binji): Allow transferring from worker to main thread?
Shell::ObjectList to_transfer; Shell::ObjectList to_transfer;
...@@ -1806,7 +1931,7 @@ void Worker::PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1806,7 +1931,7 @@ void Worker::PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (Shell::SerializeValue(isolate, message, to_transfer, &seen_objects, if (Shell::SerializeValue(isolate, message, to_transfer, &seen_objects,
data)) { data)) {
DCHECK(args.Data()->IsExternal()); DCHECK(args.Data()->IsExternal());
Handle<External> this_value = Handle<External>::Cast(args.Data()); Local<External> this_value = Local<External>::Cast(args.Data());
Worker* worker = static_cast<Worker*>(this_value->Value()); Worker* worker = static_cast<Worker*>(this_value->Value());
worker->out_queue_.Enqueue(data); worker->out_queue_.Enqueue(data);
worker->out_semaphore_.Signal(); worker->out_semaphore_.Signal();
...@@ -2016,7 +2141,7 @@ void Shell::EmptyMessageQueues(Isolate* isolate) { ...@@ -2016,7 +2141,7 @@ void Shell::EmptyMessageQueues(Isolate* isolate) {
#ifndef V8_SHARED #ifndef V8_SHARED
bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value, bool Shell::SerializeValue(Isolate* isolate, Local<Value> value,
const ObjectList& to_transfer, const ObjectList& to_transfer,
ObjectList* seen_objects, ObjectList* seen_objects,
SerializationData* out_data) { SerializationData* out_data) {
...@@ -2032,7 +2157,7 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value, ...@@ -2032,7 +2157,7 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value,
} else if (value->IsFalse()) { } else if (value->IsFalse()) {
out_data->WriteTag(kSerializationTagFalse); out_data->WriteTag(kSerializationTagFalse);
} else if (value->IsNumber()) { } else if (value->IsNumber()) {
Handle<Number> num = Handle<Number>::Cast(value); Local<Number> num = Local<Number>::Cast(value);
double value = num->Value(); double value = num->Value();
out_data->WriteTag(kSerializationTagNumber); out_data->WriteTag(kSerializationTagNumber);
out_data->Write(value); out_data->Write(value);
...@@ -2042,7 +2167,7 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value, ...@@ -2042,7 +2167,7 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value,
out_data->Write(str.length()); out_data->Write(str.length());
out_data->WriteMemory(*str, str.length()); out_data->WriteMemory(*str, str.length());
} else if (value->IsArray()) { } else if (value->IsArray()) {
Handle<Array> array = Handle<Array>::Cast(value); Local<Array> array = Local<Array>::Cast(value);
if (FindInObjectList(array, *seen_objects)) { if (FindInObjectList(array, *seen_objects)) {
Throw(isolate, "Duplicated arrays not supported"); Throw(isolate, "Duplicated arrays not supported");
return false; return false;
...@@ -2063,7 +2188,7 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value, ...@@ -2063,7 +2188,7 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value,
} }
} }
} else if (value->IsArrayBuffer()) { } else if (value->IsArrayBuffer()) {
Handle<ArrayBuffer> array_buffer = Handle<ArrayBuffer>::Cast(value); Local<ArrayBuffer> array_buffer = Local<ArrayBuffer>::Cast(value);
if (FindInObjectList(array_buffer, *seen_objects)) { if (FindInObjectList(array_buffer, *seen_objects)) {
Throw(isolate, "Duplicated array buffers not supported"); Throw(isolate, "Duplicated array buffers not supported");
return false; return false;
...@@ -2096,7 +2221,7 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value, ...@@ -2096,7 +2221,7 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value,
static_cast<int>(contents.ByteLength())); static_cast<int>(contents.ByteLength()));
} }
} else if (value->IsSharedArrayBuffer()) { } else if (value->IsSharedArrayBuffer()) {
Handle<SharedArrayBuffer> sab = Handle<SharedArrayBuffer>::Cast(value); Local<SharedArrayBuffer> sab = Local<SharedArrayBuffer>::Cast(value);
if (FindInObjectList(sab, *seen_objects)) { if (FindInObjectList(sab, *seen_objects)) {
Throw(isolate, "Duplicated shared array buffers not supported"); Throw(isolate, "Duplicated shared array buffers not supported");
return false; return false;
...@@ -2116,7 +2241,7 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value, ...@@ -2116,7 +2241,7 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value,
} }
out_data->WriteSharedArrayBufferContents(contents); out_data->WriteSharedArrayBufferContents(contents);
} else if (value->IsObject()) { } else if (value->IsObject()) {
Handle<Object> object = Handle<Object>::Cast(value); Local<Object> object = Local<Object>::Cast(value);
if (FindInObjectList(object, *seen_objects)) { if (FindInObjectList(object, *seen_objects)) {
Throw(isolate, "Duplicated objects not supported"); Throw(isolate, "Duplicated objects not supported");
return false; return false;
...@@ -2132,8 +2257,8 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value, ...@@ -2132,8 +2257,8 @@ bool Shell::SerializeValue(Isolate* isolate, Handle<Value> value,
out_data->WriteTag(kSerializationTagObject); out_data->WriteTag(kSerializationTagObject);
out_data->Write(length); out_data->Write(length);
for (uint32_t i = 0; i < length; ++i) { for (uint32_t i = 0; i < length; ++i) {
Handle<Value> name; Local<Value> name;
Handle<Value> property_value; Local<Value> property_value;
if (property_names->Get(context, i).ToLocal(&name) && if (property_names->Get(context, i).ToLocal(&name) &&
object->Get(context, name).ToLocal(&property_value)) { object->Get(context, name).ToLocal(&property_value)) {
if (!SerializeValue(isolate, name, to_transfer, seen_objects, out_data)) if (!SerializeValue(isolate, name, to_transfer, seen_objects, out_data))
...@@ -2186,38 +2311,40 @@ MaybeLocal<Value> Shell::DeserializeValue(Isolate* isolate, ...@@ -2186,38 +2311,40 @@ MaybeLocal<Value> Shell::DeserializeValue(Isolate* isolate,
CHECK(length >= 0); CHECK(length >= 0);
std::vector<char> buffer(length + 1); // + 1 so it is never empty. std::vector<char> buffer(length + 1); // + 1 so it is never empty.
data.ReadMemory(&buffer[0], length, offset); data.ReadMemory(&buffer[0], length, offset);
MaybeLocal<String> str = String::NewFromUtf8( MaybeLocal<String> str =
isolate, &buffer[0], String::kNormalString, length); String::NewFromUtf8(isolate, &buffer[0], NewStringType::kNormal,
length).ToLocalChecked();
if (!str.IsEmpty()) result = str.ToLocalChecked(); if (!str.IsEmpty()) result = str.ToLocalChecked();
break; break;
} }
case kSerializationTagArray: { case kSerializationTagArray: {
uint32_t length = data.Read<uint32_t>(offset); uint32_t length = data.Read<uint32_t>(offset);
Handle<Array> array = Array::New(isolate, length); Local<Array> array = Array::New(isolate, length);
for (uint32_t i = 0; i < length; ++i) { for (uint32_t i = 0; i < length; ++i) {
Local<Value> element_value; Local<Value> element_value;
CHECK(DeserializeValue(isolate, data, offset).ToLocal(&element_value)); CHECK(DeserializeValue(isolate, data, offset).ToLocal(&element_value));
array->Set(i, element_value); array->Set(isolate->GetCurrentContext(), i, element_value).FromJust();
} }
result = array; result = array;
break; break;
} }
case kSerializationTagObject: { case kSerializationTagObject: {
int length = data.Read<int>(offset); int length = data.Read<int>(offset);
Handle<Object> object = Object::New(isolate); Local<Object> object = Object::New(isolate);
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
Local<Value> property_name; Local<Value> property_name;
CHECK(DeserializeValue(isolate, data, offset).ToLocal(&property_name)); CHECK(DeserializeValue(isolate, data, offset).ToLocal(&property_name));
Local<Value> property_value; Local<Value> property_value;
CHECK(DeserializeValue(isolate, data, offset).ToLocal(&property_value)); CHECK(DeserializeValue(isolate, data, offset).ToLocal(&property_value));
object->Set(property_name, property_value); object->Set(isolate->GetCurrentContext(), property_name, property_value)
.FromJust();
} }
result = object; result = object;
break; break;
} }
case kSerializationTagArrayBuffer: { case kSerializationTagArrayBuffer: {
int byte_length = data.Read<int>(offset); int byte_length = data.Read<int>(offset);
Handle<ArrayBuffer> array_buffer = ArrayBuffer::New(isolate, byte_length); Local<ArrayBuffer> array_buffer = ArrayBuffer::New(isolate, byte_length);
ArrayBuffer::Contents contents = array_buffer->GetContents(); ArrayBuffer::Contents contents = array_buffer->GetContents();
DCHECK(static_cast<size_t>(byte_length) == contents.ByteLength()); DCHECK(static_cast<size_t>(byte_length) == contents.ByteLength());
data.ReadMemory(contents.Data(), byte_length, offset); data.ReadMemory(contents.Data(), byte_length, offset);
......
...@@ -53,6 +53,10 @@ ...@@ -53,6 +53,10 @@
'startup-data-util.h', 'startup-data-util.h',
'startup-data-util.cc' 'startup-data-util.cc'
], ],
'defines': [
# TODO(jochen): Remove again after this is globally turned on.
'V8_IMMINENT_DEPRECATION_WARNINGS',
],
'conditions': [ 'conditions': [
[ 'want_separate_host_toolset==1', { [ 'want_separate_host_toolset==1', {
'toolsets': [ '<(v8_toolset_for_d8)', ], 'toolsets': [ '<(v8_toolset_for_d8)', ],
......
...@@ -99,7 +99,7 @@ class LineEditor { ...@@ -99,7 +99,7 @@ class LineEditor {
LineEditor(Type type, const char* name); LineEditor(Type type, const char* name);
virtual ~LineEditor() { } virtual ~LineEditor() { }
virtual Handle<String> Prompt(const char* prompt) = 0; virtual Local<String> Prompt(const char* prompt) = 0;
virtual bool Open(Isolate* isolate) { return true; } virtual bool Open(Isolate* isolate) { return true; }
virtual bool Close() { return true; } virtual bool Close() { return true; }
virtual void AddHistory(const char* str) { } virtual void AddHistory(const char* str) { }
...@@ -163,7 +163,7 @@ class SourceGroup { ...@@ -163,7 +163,7 @@ class SourceGroup {
#endif // !V8_SHARED #endif // !V8_SHARED
void ExitShell(int exit_code); void ExitShell(int exit_code);
Handle<String> ReadFile(Isolate* isolate, const char* name); Local<String> ReadFile(Isolate* isolate, const char* name);
const char** argv_; const char** argv_;
int begin_offset_; int begin_offset_;
...@@ -349,17 +349,17 @@ class Shell : public i::AllStatic { ...@@ -349,17 +349,17 @@ class Shell : public i::AllStatic {
public: public:
enum SourceType { SCRIPT, MODULE }; enum SourceType { SCRIPT, MODULE };
static Local<Script> CompileString( static MaybeLocal<Script> CompileString(
Isolate* isolate, Local<String> source, Local<Value> name, Isolate* isolate, Local<String> source, Local<Value> name,
v8::ScriptCompiler::CompileOptions compile_options, v8::ScriptCompiler::CompileOptions compile_options,
SourceType source_type); SourceType source_type);
static bool ExecuteString(Isolate* isolate, Handle<String> source, static bool ExecuteString(Isolate* isolate, Local<String> source,
Handle<Value> name, bool print_result, Local<Value> name, bool print_result,
bool report_exceptions, bool report_exceptions,
SourceType source_type = SCRIPT); SourceType source_type = SCRIPT);
static const char* ToCString(const v8::String::Utf8Value& value); static const char* ToCString(const v8::String::Utf8Value& value);
static void ReportException(Isolate* isolate, TryCatch* try_catch); static void ReportException(Isolate* isolate, TryCatch* try_catch);
static Handle<String> ReadFile(Isolate* isolate, const char* name); static Local<String> ReadFile(Isolate* isolate, const char* name);
static Local<Context> CreateEvaluationContext(Isolate* isolate); static Local<Context> CreateEvaluationContext(Isolate* isolate);
static int RunMain(Isolate* isolate, int argc, char* argv[]); static int RunMain(Isolate* isolate, int argc, char* argv[]);
static int Main(int argc, char* argv[]); static int Main(int argc, char* argv[]);
...@@ -371,8 +371,8 @@ class Shell : public i::AllStatic { ...@@ -371,8 +371,8 @@ class Shell : public i::AllStatic {
#ifndef V8_SHARED #ifndef V8_SHARED
// TODO(binji): stupid implementation for now. Is there an easy way to hash an // TODO(binji): stupid implementation for now. Is there an easy way to hash an
// object for use in i::HashMap? By pointer? // object for use in i::HashMap? By pointer?
typedef i::List<Handle<Object>> ObjectList; typedef i::List<Local<Object>> ObjectList;
static bool SerializeValue(Isolate* isolate, Handle<Value> value, static bool SerializeValue(Isolate* isolate, Local<Value> value,
const ObjectList& to_transfer, const ObjectList& to_transfer,
ObjectList* seen_objects, ObjectList* seen_objects,
SerializationData* out_data); SerializationData* out_data);
...@@ -380,9 +380,8 @@ class Shell : public i::AllStatic { ...@@ -380,9 +380,8 @@ class Shell : public i::AllStatic {
const SerializationData& data, const SerializationData& data,
int* offset); int* offset);
static void CleanupWorkers(); static void CleanupWorkers();
static Handle<Array> GetCompletions(Isolate* isolate, static Local<Array> GetCompletions(Isolate* isolate, Local<String> text,
Handle<String> text, Local<String> full);
Handle<String> full);
static int* LookupCounter(const char* name); static int* LookupCounter(const char* name);
static void* CreateHistogram(const char* name, static void* CreateHistogram(const char* name,
int min, int min,
...@@ -392,9 +391,9 @@ class Shell : public i::AllStatic { ...@@ -392,9 +391,9 @@ class Shell : public i::AllStatic {
static void MapCounters(v8::Isolate* isolate, const char* name); static void MapCounters(v8::Isolate* isolate, const char* name);
static Local<Object> DebugMessageDetails(Isolate* isolate, static Local<Object> DebugMessageDetails(Isolate* isolate,
Handle<String> message); Local<String> message);
static Local<Value> DebugCommandToJSONRequest(Isolate* isolate, static Local<Value> DebugCommandToJSONRequest(Isolate* isolate,
Handle<String> command); Local<String> command);
static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args); static void PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args);
#endif // !V8_SHARED #endif // !V8_SHARED
...@@ -419,7 +418,7 @@ class Shell : public i::AllStatic { ...@@ -419,7 +418,7 @@ class Shell : public i::AllStatic {
static void Version(const v8::FunctionCallbackInfo<v8::Value>& args); static void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Read(const v8::FunctionCallbackInfo<v8::Value>& args); static void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args); static void ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
static Handle<String> ReadFromStdin(Isolate* isolate); static Local<String> ReadFromStdin(Isolate* isolate);
static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) { static void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate())); args.GetReturnValue().Set(ReadFromStdin(args.GetIsolate()));
} }
...@@ -464,17 +463,17 @@ class Shell : public i::AllStatic { ...@@ -464,17 +463,17 @@ class Shell : public i::AllStatic {
static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args); static void RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args);
static void AddOSMethods(v8::Isolate* isolate, static void AddOSMethods(v8::Isolate* isolate,
Handle<ObjectTemplate> os_template); Local<ObjectTemplate> os_template);
static const char* kPrompt; static const char* kPrompt;
static ShellOptions options; static ShellOptions options;
static ArrayBuffer::Allocator* array_buffer_allocator; static ArrayBuffer::Allocator* array_buffer_allocator;
private: private:
static Persistent<Context> evaluation_context_; static Global<Context> evaluation_context_;
static base::OnceType quit_once_; static base::OnceType quit_once_;
#ifndef V8_SHARED #ifndef V8_SHARED
static Persistent<Context> utility_context_; static Global<Context> utility_context_;
static CounterMap* counter_map_; static CounterMap* counter_map_;
// We statically allocate a set of local counters to be used if we // We statically allocate a set of local counters to be used if we
// don't want to store the stats in a memory-mapped file // don't want to store the stats in a memory-mapped file
...@@ -496,7 +495,7 @@ class Shell : public i::AllStatic { ...@@ -496,7 +495,7 @@ class Shell : public i::AllStatic {
static void InitializeDebugger(Isolate* isolate); static void InitializeDebugger(Isolate* isolate);
static void RunShell(Isolate* isolate); static void RunShell(Isolate* isolate);
static bool SetOptions(int argc, char* argv[]); static bool SetOptions(int argc, char* argv[]);
static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment