Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Unified Diff: src/d8-posix.cc

Issue 1240993003: Revert of Make d8 stop using to-be-deprecated APIs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/d8-debug.cc ('k') | src/d8-readline.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8-posix.cc
diff --git a/src/d8-posix.cc b/src/d8-posix.cc
index 36d83b53cff62b84950cf649854be15e2a140225..3bca14f530c58d08c08c77cdafec8af943ce9c0d 100644
--- a/src/d8-posix.cc
+++ b/src/d8-posix.cc
@@ -170,14 +170,12 @@
ExecArgs() {
exec_args_[0] = NULL;
}
- bool Init(Isolate* isolate, Local<Value> arg0, Local<Array> command_args) {
+ bool Init(Isolate* isolate, Handle<Value> arg0, Handle<Array> command_args) {
String::Utf8Value prog(arg0);
if (*prog == NULL) {
const char* message =
"os.system(): String conversion of program name failed";
- isolate->ThrowException(
- String::NewFromUtf8(isolate, message, NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
int len = prog.length() + 3;
@@ -186,17 +184,13 @@
exec_args_[0] = c_arg;
int i = 1;
for (unsigned j = 0; j < command_args->Length(); i++, j++) {
- Local<Value> arg(
- command_args->Get(isolate->GetCurrentContext(),
- Integer::New(isolate, j)).ToLocalChecked());
+ Handle<Value> arg(command_args->Get(Integer::New(isolate, j)));
String::Utf8Value utf8_arg(arg);
if (*utf8_arg == NULL) {
exec_args_[i] = NULL; // Consistent state for destructor.
const char* message =
"os.system(): String conversion of argument failed.";
- isolate->ThrowException(
- String::NewFromUtf8(isolate, message, NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
int len = utf8_arg.length() + 1;
@@ -231,27 +225,19 @@
int* total_timeout) {
if (args.Length() > 3) {
if (args[3]->IsNumber()) {
- *total_timeout = args[3]
- ->Int32Value(args.GetIsolate()->GetCurrentContext())
- .FromJust();
+ *total_timeout = args[3]->Int32Value();
} else {
- args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(),
- "system: Argument 4 must be a number",
- NewStringType::kNormal).ToLocalChecked());
+ args.GetIsolate()->ThrowException(String::NewFromUtf8(
+ args.GetIsolate(), "system: Argument 4 must be a number"));
return false;
}
}
if (args.Length() > 2) {
if (args[2]->IsNumber()) {
- *read_timeout = args[2]
- ->Int32Value(args.GetIsolate()->GetCurrentContext())
- .FromJust();
+ *read_timeout = args[2]->Int32Value();
} else {
- args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(),
- "system: Argument 3 must be a number",
- NewStringType::kNormal).ToLocalChecked());
+ args.GetIsolate()->ThrowException(String::NewFromUtf8(
+ args.GetIsolate(), "system: Argument 3 must be a number"));
return false;
}
}
@@ -296,9 +282,7 @@
bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err));
} while (bytes_read == -1 && errno == EINTR);
if (bytes_read != 0) {
- isolate->ThrowException(
- String::NewFromUtf8(isolate, strerror(err), NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(err)));
return false;
}
return true;
@@ -307,10 +291,12 @@
// Accumulates the output from the child in a string handle. Returns true if it
// succeeded or false if an exception was thrown.
-static Local<Value> GetStdout(Isolate* isolate, int child_fd,
- const struct timeval& start_time,
- int read_timeout, int total_timeout) {
- Local<String> accumulator = String::Empty(isolate);
+static Handle<Value> GetStdout(Isolate* isolate,
+ int child_fd,
+ const struct timeval& start_time,
+ int read_timeout,
+ int total_timeout) {
+ Handle<String> accumulator = String::Empty(isolate);
int fullness = 0;
static const int kStdoutReadBufferSize = 4096;
@@ -318,8 +304,7 @@
if (fcntl(child_fd, F_SETFL, O_NONBLOCK) != 0) {
return isolate->ThrowException(
- String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(isolate, strerror(errno)));
}
int bytes_read;
@@ -334,8 +319,7 @@
start_time) ||
(TimeIsOut(start_time, total_timeout))) {
return isolate->ThrowException(
- String::NewFromUtf8(isolate, "Timed out waiting for output",
- NewStringType::kNormal).ToLocalChecked());
+ String::NewFromUtf8(isolate, "Timed out waiting for output"));
}
continue;
} else if (errno == EINTR) {
@@ -348,9 +332,8 @@
int length = bytes_read == 0 ?
bytes_read + fullness :
LengthWithoutIncompleteUtf8(buffer, bytes_read + fullness);
- Local<String> addition =
- String::NewFromUtf8(isolate, buffer, NewStringType::kNormal, length)
- .ToLocalChecked();
+ Handle<String> addition =
+ String::NewFromUtf8(isolate, buffer, String::kNormalString, length);
accumulator = String::Concat(accumulator, addition);
fullness = bytes_read + fullness - length;
memcpy(buffer, buffer + length, fullness);
@@ -397,10 +380,8 @@
if (useconds < 1000000) useconds <<= 1;
if ((read_timeout != -1 && useconds / 1000 > read_timeout) ||
(TimeIsOut(start_time, total_timeout))) {
- isolate->ThrowException(
- String::NewFromUtf8(isolate,
- "Timed out waiting for process to terminate",
- NewStringType::kNormal).ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(
+ isolate, "Timed out waiting for process to terminate"));
kill(pid, SIGINT);
return false;
}
@@ -411,9 +392,7 @@
sizeof(message),
"Child killed by signal %d",
child_info.si_status);
- isolate->ThrowException(
- String::NewFromUtf8(isolate, message, NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
if (child_info.si_code == CLD_EXITED && child_info.si_status != 0) {
@@ -422,9 +401,7 @@
sizeof(message),
"Child exited with status %d",
child_info.si_status);
- isolate->ThrowException(
- String::NewFromUtf8(isolate, message, NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
@@ -439,9 +416,7 @@
sizeof(message),
"Child killed by signal %d",
WTERMSIG(child_status));
- isolate->ThrowException(
- String::NewFromUtf8(isolate, message, NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
if (WEXITSTATUS(child_status) != 0) {
@@ -451,9 +426,7 @@
sizeof(message),
"Child exited with status %d",
exit_status);
- isolate->ThrowException(
- String::NewFromUtf8(isolate, message, NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
@@ -469,29 +442,25 @@
int read_timeout = -1;
int total_timeout = -1;
if (!GetTimeouts(args, &read_timeout, &total_timeout)) return;
- Local<Array> command_args;
+ Handle<Array> command_args;
if (args.Length() > 1) {
if (!args[1]->IsArray()) {
- args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(),
- "system: Argument 2 must be an array",
- NewStringType::kNormal).ToLocalChecked());
+ args.GetIsolate()->ThrowException(String::NewFromUtf8(
+ args.GetIsolate(), "system: Argument 2 must be an array"));
return;
}
- command_args = Local<Array>::Cast(args[1]);
+ command_args = Handle<Array>::Cast(args[1]);
} else {
command_args = Array::New(args.GetIsolate(), 0);
}
if (command_args->Length() > ExecArgs::kMaxArgs) {
- args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), "Too many arguments to system()",
- NewStringType::kNormal).ToLocalChecked());
+ args.GetIsolate()->ThrowException(String::NewFromUtf8(
+ args.GetIsolate(), "Too many arguments to system()"));
return;
}
if (args.Length() < 1) {
- args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), "Too few arguments to system()",
- NewStringType::kNormal).ToLocalChecked());
+ args.GetIsolate()->ThrowException(String::NewFromUtf8(
+ args.GetIsolate(), "Too few arguments to system()"));
return;
}
@@ -507,14 +476,12 @@
if (pipe(exec_error_fds) != 0) {
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.",
- NewStringType::kNormal).ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed."));
return;
}
if (pipe(stdout_fds) != 0) {
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.",
- NewStringType::kNormal).ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed."));
return;
}
@@ -533,8 +500,11 @@
if (!ChildLaunchedOK(args.GetIsolate(), exec_error_fds)) return;
- Local<Value> accumulator = GetStdout(args.GetIsolate(), stdout_fds[kReadFD],
- start_time, read_timeout, total_timeout);
+ Handle<Value> accumulator = GetStdout(args.GetIsolate(),
+ stdout_fds[kReadFD],
+ start_time,
+ read_timeout,
+ total_timeout);
if (accumulator->IsUndefined()) {
kill(pid, SIGINT); // On timeout, kill the subprocess.
args.GetReturnValue().Set(accumulator);
@@ -558,22 +528,19 @@
if (args.Length() != 1) {
const char* message = "chdir() takes one argument";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
String::Utf8Value directory(args[0]);
if (*directory == NULL) {
const char* message = "os.chdir(): String conversion of argument failed.";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
if (chdir(*directory) != 0) {
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), strerror(errno),
- NewStringType::kNormal).ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), strerror(errno)));
return;
}
}
@@ -583,8 +550,7 @@
if (args.Length() != 1) {
const char* message = "umask() takes one argument";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
if (args[0]->IsNumber()) {
@@ -592,16 +558,14 @@
// PNaCL has no support for umask.
int previous = 0;
#else
- int previous = umask(
- args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust());
+ int previous = umask(args[0]->Int32Value());
#endif
args.GetReturnValue().Set(previous);
return;
} else {
const char* message = "umask() argument must be numeric";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
}
@@ -611,15 +575,11 @@
struct stat stat_buf;
int stat_result = stat(directory, &stat_buf);
if (stat_result != 0) {
- isolate->ThrowException(
- String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
return false;
}
if ((stat_buf.st_mode & S_IFDIR) != 0) return true;
- isolate->ThrowException(
- String::NewFromUtf8(isolate, strerror(EEXIST), NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(EEXIST)));
return false;
}
@@ -634,9 +594,7 @@
} else if (errno == ENOENT) { // Intermediate path element is missing.
char* last_slash = strrchr(directory, '/');
if (last_slash == NULL) {
- isolate->ThrowException(
- String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
return false;
}
*last_slash = 0;
@@ -647,14 +605,10 @@
if (errno == EEXIST) {
return CheckItsADirectory(isolate, directory);
}
- isolate->ThrowException(
- String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
return false;
} else {
- isolate->ThrowException(
- String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
- .ToLocalChecked());
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
return false;
}
}
@@ -664,29 +618,24 @@
mode_t mask = 0777;
if (args.Length() == 2) {
if (args[1]->IsNumber()) {
- mask = args[1]
- ->Int32Value(args.GetIsolate()->GetCurrentContext())
- .FromJust();
+ mask = args[1]->Int32Value();
} else {
const char* message = "mkdirp() second argument must be numeric";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message,
- NewStringType::kNormal).ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
} else if (args.Length() != 1) {
const char* message = "mkdirp() takes one or two arguments";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
String::Utf8Value directory(args[0]);
if (*directory == NULL) {
const char* message = "os.mkdirp(): String conversion of argument failed.";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
mkdirp(args.GetIsolate(), *directory, mask);
@@ -697,16 +646,14 @@
if (args.Length() != 1) {
const char* message = "rmdir() takes one or two arguments";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
String::Utf8Value directory(args[0]);
if (*directory == NULL) {
const char* message = "os.rmdir(): String conversion of argument failed.";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
rmdir(*directory);
@@ -717,8 +664,7 @@
if (args.Length() != 2) {
const char* message = "setenv() takes two arguments";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
String::Utf8Value var(args[0]);
@@ -727,16 +673,14 @@
const char* message =
"os.setenv(): String conversion of variable name failed.";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
if (*value == NULL) {
const char* message =
"os.setenv(): String conversion of variable contents failed.";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
setenv(*var, *value, 1);
@@ -747,8 +691,7 @@
if (args.Length() != 1) {
const char* message = "unsetenv() takes one argument";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
String::Utf8Value var(args[0]);
@@ -756,35 +699,27 @@
const char* message =
"os.setenv(): String conversion of variable name failed.";
args.GetIsolate()->ThrowException(
- String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
- .ToLocalChecked());
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
unsetenv(*var);
}
-void Shell::AddOSMethods(Isolate* isolate, Local<ObjectTemplate> os_templ) {
- os_templ->Set(String::NewFromUtf8(isolate, "system", NewStringType::kNormal)
- .ToLocalChecked(),
+void Shell::AddOSMethods(Isolate* isolate, Handle<ObjectTemplate> os_templ) {
+ os_templ->Set(String::NewFromUtf8(isolate, "system"),
FunctionTemplate::New(isolate, System));
- os_templ->Set(String::NewFromUtf8(isolate, "chdir", NewStringType::kNormal)
- .ToLocalChecked(),
+ os_templ->Set(String::NewFromUtf8(isolate, "chdir"),
FunctionTemplate::New(isolate, ChangeDirectory));
- os_templ->Set(String::NewFromUtf8(isolate, "setenv", NewStringType::kNormal)
- .ToLocalChecked(),
+ os_templ->Set(String::NewFromUtf8(isolate, "setenv"),
FunctionTemplate::New(isolate, SetEnvironment));
- os_templ->Set(String::NewFromUtf8(isolate, "unsetenv", NewStringType::kNormal)
- .ToLocalChecked(),
+ os_templ->Set(String::NewFromUtf8(isolate, "unsetenv"),
FunctionTemplate::New(isolate, UnsetEnvironment));
- os_templ->Set(String::NewFromUtf8(isolate, "umask", NewStringType::kNormal)
- .ToLocalChecked(),
+ os_templ->Set(String::NewFromUtf8(isolate, "umask"),
FunctionTemplate::New(isolate, SetUMask));
- os_templ->Set(String::NewFromUtf8(isolate, "mkdirp", NewStringType::kNormal)
- .ToLocalChecked(),
+ os_templ->Set(String::NewFromUtf8(isolate, "mkdirp"),
FunctionTemplate::New(isolate, MakeDirectory));
- os_templ->Set(String::NewFromUtf8(isolate, "rmdir", NewStringType::kNormal)
- .ToLocalChecked(),
+ os_templ->Set(String::NewFromUtf8(isolate, "rmdir"),
FunctionTemplate::New(isolate, RemoveDirectory));
}
« no previous file with comments | « src/d8-debug.cc ('k') | src/d8-readline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698