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

Unified Diff: src/d8-posix.cc

Issue 57005: Add os.chdir and os.setenv to d8. Move system() to os.system(). (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 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.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
===================================================================
--- src/d8-posix.cc (revision 1633)
+++ src/d8-posix.cc (working copy)
@@ -184,9 +184,18 @@
// scope.
class ExecArgs {
public:
- ExecArgs(Handle<Value> arg0, Handle<Array> command_args) {
+ ExecArgs() {
+ exec_args_[0] = NULL;
+ }
+ bool Init(Handle<Value> arg0, Handle<Array> command_args) {
String::Utf8Value prog(arg0);
- int len = prog.length() + 1;
+ if (*prog == NULL) {
+ const char* message =
+ "os.system(): String conversion of program name failed";
+ ThrowException(String::New(message));
+ return false;
+ }
+ int len = prog.length() + 3;
char* c_arg = new char[len];
snprintf(c_arg, len, "%s", *prog);
exec_args_[0] = c_arg;
@@ -194,12 +203,20 @@
for (unsigned j = 0; j < command_args->Length(); i++, j++) {
Handle<Value> arg(command_args->Get(Integer::New(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.";
+ ThrowException(String::New(message));
+ return false;
+ }
int len = utf8_arg.length() + 1;
char* c_arg = new char[len];
snprintf(c_arg, len, "%s", *utf8_arg);
exec_args_[i] = c_arg;
}
exec_args_[i] = NULL;
+ return true;
}
~ExecArgs() {
for (unsigned i = 0; i < kMaxArgs; i++) {
@@ -454,7 +471,10 @@
struct timeval start_time;
gettimeofday(&start_time, NULL);
- ExecArgs exec_args(args[0], command_args);
+ ExecArgs exec_args;
+ if (!exec_args.Init(args[0], command_args)) {
+ return v8::Undefined();
+ }
int exec_error_fds[2];
int stdout_fds[2];
@@ -501,4 +521,21 @@
}
+Handle<Value> Shell::ChangeDirectory(const Arguments& args) {
+ if (args.Length() != 1) {
+ const char* message = "chdir() takes one argument";
+ return ThrowException(String::New(message));
+ }
+ String::Utf8Value directory(args[0]);
+ if (*directory == NULL) {
+ const char* message = "os.chdir(): String conversion of argument failed.";
+ return ThrowException(String::New(message));
+ }
+ if (chdir(*directory) != 0) {
+ return ThrowException(String::New(strerror(errno)));
+ }
+ return v8::Undefined();
+}
+
+
} // namespace v8
« no previous file with comments | « src/d8.cc ('k') | src/d8-windows.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698