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

Unified Diff: src/d8-posix.cc

Issue 83333002: Remove usage of deprecated APIs from d8 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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-windows.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 81c15ae742e0c29744dbeb665485c21836e3859b..dc60d0cc749d8a8766bbfc4450e1b1f4b45b7e9c 100644
--- a/src/d8-posix.cc
+++ b/src/d8-posix.cc
@@ -188,12 +188,12 @@ class ExecArgs {
ExecArgs() {
exec_args_[0] = NULL;
}
- bool Init(Handle<Value> arg0, Handle<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";
- ThrowException(String::New(message));
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
int len = prog.length() + 3;
@@ -208,7 +208,7 @@ class ExecArgs {
exec_args_[i] = NULL; // Consistent state for destructor.
const char* message =
"os.system(): String conversion of argument failed.";
- ThrowException(String::New(message));
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
int len = utf8_arg.length() + 1;
@@ -245,8 +245,8 @@ static bool GetTimeouts(const v8::FunctionCallbackInfo<v8::Value>& args,
if (args[3]->IsNumber()) {
*total_timeout = args[3]->Int32Value();
} else {
- args.GetIsolate()->ThrowException(
- String::New("system: Argument 4 must be a number"));
+ args.GetIsolate()->ThrowException(String::NewFromUtf8(
+ args.GetIsolate(), "system: Argument 4 must be a number"));
return false;
}
}
@@ -254,8 +254,8 @@ static bool GetTimeouts(const v8::FunctionCallbackInfo<v8::Value>& args,
if (args[2]->IsNumber()) {
*read_timeout = args[2]->Int32Value();
} else {
- args.GetIsolate()->ThrowException(
- String::New("system: Argument 3 must be a number"));
+ args.GetIsolate()->ThrowException(String::NewFromUtf8(
+ args.GetIsolate(), "system: Argument 3 must be a number"));
return false;
}
}
@@ -293,14 +293,14 @@ static void ExecSubprocess(int* exec_error_fds,
// Runs in the parent process. Checks that the child was able to exec (closing
// the file desriptor), or reports an error if it failed.
-static bool ChildLaunchedOK(int* exec_error_fds) {
+static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) {
int bytes_read;
int err;
do {
bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err));
} while (bytes_read == -1 && errno == EINTR);
if (bytes_read != 0) {
- ThrowException(String::New(strerror(err)));
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(err)));
return false;
}
return true;
@@ -309,7 +309,8 @@ static bool ChildLaunchedOK(int* exec_error_fds) {
// Accumulates the output from the child in a string handle. Returns true if it
// succeeded or false if an exception was thrown.
-static Handle<Value> GetStdout(int child_fd,
+static Handle<Value> GetStdout(Isolate* isolate,
+ int child_fd,
struct timeval& start_time,
int read_timeout,
int total_timeout) {
@@ -320,7 +321,8 @@ static Handle<Value> GetStdout(int child_fd,
char buffer[kStdoutReadBufferSize];
if (fcntl(child_fd, F_SETFL, O_NONBLOCK) != 0) {
- return ThrowException(String::New(strerror(errno)));
+ return isolate->ThrowException(
+ String::NewFromUtf8(isolate, strerror(errno)));
}
int bytes_read;
@@ -335,7 +337,8 @@ static Handle<Value> GetStdout(int child_fd,
total_timeout,
start_time) ||
(TimeIsOut(start_time, total_timeout))) {
- return ThrowException(String::New("Timed out waiting for output"));
+ return isolate->ThrowException(
+ String::NewFromUtf8(isolate, "Timed out waiting for output"));
}
continue;
} else if (errno == EINTR) {
@@ -348,7 +351,8 @@ static Handle<Value> GetStdout(int child_fd,
int length = bytes_read == 0 ?
bytes_read + fullness :
LengthWithoutIncompleteUtf8(buffer, bytes_read + fullness);
- Handle<String> addition = String::New(buffer, length);
+ 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);
@@ -377,7 +381,8 @@ static Handle<Value> GetStdout(int child_fd,
// Get exit status of child.
-static bool WaitForChild(int pid,
+static bool WaitForChild(Isolate* isolate,
+ int pid,
ZombieProtector& child_waiter,
struct timeval& start_time,
int read_timeout,
@@ -394,7 +399,8 @@ static bool WaitForChild(int pid,
if (useconds < 1000000) useconds <<= 1;
if ((read_timeout != -1 && useconds / 1000 > read_timeout) ||
(TimeIsOut(start_time, total_timeout))) {
- ThrowException(String::New("Timed out waiting for process to terminate"));
+ isolate->ThrowException(String::NewFromUtf8(
+ isolate, "Timed out waiting for process to terminate"));
kill(pid, SIGINT);
return false;
}
@@ -405,7 +411,7 @@ static bool WaitForChild(int pid,
sizeof(message),
"Child killed by signal %d",
child_info.si_status);
- ThrowException(String::New(message));
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
if (child_info.si_code == CLD_EXITED && child_info.si_status != 0) {
@@ -414,7 +420,7 @@ static bool WaitForChild(int pid,
sizeof(message),
"Child exited with status %d",
child_info.si_status);
- ThrowException(String::New(message));
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
@@ -429,7 +435,7 @@ static bool WaitForChild(int pid,
sizeof(message),
"Child killed by signal %d",
WTERMSIG(child_status));
- ThrowException(String::New(message));
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
if (WEXITSTATUS(child_status) != 0) {
@@ -439,7 +445,7 @@ static bool WaitForChild(int pid,
sizeof(message),
"Child exited with status %d",
exit_status);
- ThrowException(String::New(message));
+ isolate->ThrowException(String::NewFromUtf8(isolate, message));
return false;
}
@@ -458,8 +464,8 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
Handle<Array> command_args;
if (args.Length() > 1) {
if (!args[1]->IsArray()) {
- args.GetIsolate()->ThrowException(
- String::New("system: Argument 2 must be an array"));
+ args.GetIsolate()->ThrowException(String::NewFromUtf8(
+ args.GetIsolate(), "system: Argument 2 must be an array"));
return;
}
command_args = Handle<Array>::Cast(args[1]);
@@ -467,13 +473,13 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
command_args = Array::New(0);
}
if (command_args->Length() > ExecArgs::kMaxArgs) {
- args.GetIsolate()->ThrowException(
- String::New("Too many arguments to system()"));
+ args.GetIsolate()->ThrowException(String::NewFromUtf8(
+ args.GetIsolate(), "Too many arguments to system()"));
return;
}
if (args.Length() < 1) {
- args.GetIsolate()->ThrowException(
- String::New("Too few arguments to system()"));
+ args.GetIsolate()->ThrowException(String::NewFromUtf8(
+ args.GetIsolate(), "Too few arguments to system()"));
return;
}
@@ -481,7 +487,7 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
gettimeofday(&start_time, NULL);
ExecArgs exec_args;
- if (!exec_args.Init(args[0], command_args)) {
+ if (!exec_args.Init(args.GetIsolate(), args[0], command_args)) {
return;
}
int exec_error_fds[2];
@@ -489,12 +495,12 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (pipe(exec_error_fds) != 0) {
args.GetIsolate()->ThrowException(
- String::New("pipe syscall failed."));
+ String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed."));
return;
}
if (pipe(stdout_fds) != 0) {
args.GetIsolate()->ThrowException(
- String::New("pipe syscall failed."));
+ String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed."));
return;
}
@@ -511,9 +517,10 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
OpenFDCloser error_read_closer(exec_error_fds[kReadFD]);
OpenFDCloser stdout_read_closer(stdout_fds[kReadFD]);
- if (!ChildLaunchedOK(exec_error_fds)) return;
+ if (!ChildLaunchedOK(args.GetIsolate(), exec_error_fds)) return;
- Handle<Value> accumulator = GetStdout(stdout_fds[kReadFD],
+ Handle<Value> accumulator = GetStdout(args.GetIsolate(),
+ stdout_fds[kReadFD],
start_time,
read_timeout,
total_timeout);
@@ -523,7 +530,8 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
return;
}
- if (!WaitForChild(pid,
+ if (!WaitForChild(args.GetIsolate(),
+ pid,
child_waiter,
start_time,
read_timeout,
@@ -538,17 +546,20 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Shell::ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) {
const char* message = "chdir() takes one argument";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ 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::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
if (chdir(*directory) != 0) {
- args.GetIsolate()->ThrowException(String::New(strerror(errno)));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), strerror(errno)));
return;
}
}
@@ -557,7 +568,8 @@ void Shell::ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) {
const char* message = "umask() takes one argument";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
if (args[0]->IsNumber()) {
@@ -567,50 +579,51 @@ void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) {
return;
} else {
const char* message = "umask() argument must be numeric";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
}
-static bool CheckItsADirectory(char* directory) {
+static bool CheckItsADirectory(Isolate* isolate, char* directory) {
struct stat stat_buf;
int stat_result = stat(directory, &stat_buf);
if (stat_result != 0) {
- ThrowException(String::New(strerror(errno)));
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
return false;
}
if ((stat_buf.st_mode & S_IFDIR) != 0) return true;
- ThrowException(String::New(strerror(EEXIST)));
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(EEXIST)));
return false;
}
// Returns true for success. Creates intermediate directories as needed. No
// error if the directory exists already.
-static bool mkdirp(char* directory, mode_t mask) {
+static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) {
int result = mkdir(directory, mask);
if (result == 0) return true;
if (errno == EEXIST) {
- return CheckItsADirectory(directory);
+ return CheckItsADirectory(isolate, directory);
} else if (errno == ENOENT) { // Intermediate path element is missing.
char* last_slash = strrchr(directory, '/');
if (last_slash == NULL) {
- ThrowException(String::New(strerror(errno)));
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
return false;
}
*last_slash = 0;
- if (!mkdirp(directory, mask)) return false;
+ if (!mkdirp(isolate, directory, mask)) return false;
*last_slash = '/';
result = mkdir(directory, mask);
if (result == 0) return true;
if (errno == EEXIST) {
- return CheckItsADirectory(directory);
+ return CheckItsADirectory(isolate, directory);
}
- ThrowException(String::New(strerror(errno)));
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
return false;
} else {
- ThrowException(String::New(strerror(errno)));
+ isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
return false;
}
}
@@ -623,34 +636,39 @@ void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
mask = args[1]->Int32Value();
} else {
const char* message = "mkdirp() second argument must be numeric";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
} else if (args.Length() != 1) {
const char* message = "mkdirp() takes one or two arguments";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ 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::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
- mkdirp(*directory, mask);
+ mkdirp(args.GetIsolate(), *directory, mask);
}
void Shell::RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) {
const char* message = "rmdir() takes one or two arguments";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ 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::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
rmdir(*directory);
@@ -660,7 +678,8 @@ void Shell::RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 2) {
const char* message = "setenv() takes two arguments";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
String::Utf8Value var(args[0]);
@@ -668,13 +687,15 @@ void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (*var == NULL) {
const char* message =
"os.setenv(): String conversion of variable name failed.";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
if (*value == NULL) {
const char* message =
"os.setenv(): String conversion of variable contents failed.";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
setenv(*var, *value, 1);
@@ -684,29 +705,37 @@ void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) {
const char* message = "unsetenv() takes one argument";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
String::Utf8Value var(args[0]);
if (*var == NULL) {
const char* message =
"os.setenv(): String conversion of variable name failed.";
- args.GetIsolate()->ThrowException(String::New(message));
+ args.GetIsolate()->ThrowException(
+ String::NewFromUtf8(args.GetIsolate(), message));
return;
}
unsetenv(*var);
}
-void Shell::AddOSMethods(Handle<ObjectTemplate> os_templ) {
- os_templ->Set(String::New("system"), FunctionTemplate::New(System));
- os_templ->Set(String::New("chdir"), FunctionTemplate::New(ChangeDirectory));
- os_templ->Set(String::New("setenv"), FunctionTemplate::New(SetEnvironment));
- os_templ->Set(String::New("unsetenv"),
+void Shell::AddOSMethods(Isolate* isolate, Handle<ObjectTemplate> os_templ) {
+ os_templ->Set(String::NewFromUtf8(isolate, "system"),
+ FunctionTemplate::New(System));
+ os_templ->Set(String::NewFromUtf8(isolate, "chdir"),
+ FunctionTemplate::New(ChangeDirectory));
+ os_templ->Set(String::NewFromUtf8(isolate, "setenv"),
+ FunctionTemplate::New(SetEnvironment));
+ os_templ->Set(String::NewFromUtf8(isolate, "unsetenv"),
FunctionTemplate::New(UnsetEnvironment));
- os_templ->Set(String::New("umask"), FunctionTemplate::New(SetUMask));
- os_templ->Set(String::New("mkdirp"), FunctionTemplate::New(MakeDirectory));
- os_templ->Set(String::New("rmdir"), FunctionTemplate::New(RemoveDirectory));
+ os_templ->Set(String::NewFromUtf8(isolate, "umask"),
+ FunctionTemplate::New(SetUMask));
+ os_templ->Set(String::NewFromUtf8(isolate, "mkdirp"),
+ FunctionTemplate::New(MakeDirectory));
+ os_templ->Set(String::NewFromUtf8(isolate, "rmdir"),
+ FunctionTemplate::New(RemoveDirectory));
}
} // namespace v8
« no previous file with comments | « src/d8-debug.cc ('k') | src/d8-windows.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698