Added process.chdir()

This commit is contained in:
Brandon Beacher
2009-11-03 13:13:38 -05:00
committed by Ryan Dahl
parent 726865af7b
commit 47fcf785ac
2 changed files with 28 additions and 0 deletions

View File

@@ -231,6 +231,24 @@ Handle<Value> ExecuteString(v8::Handle<v8::String> source,
return scope.Close(result);
}
static Handle<Value> Chdir(const Arguments& args) {
HandleScope scope;
if (args.Length() != 1 || !args[0]->IsString()) {
return ThrowException(Exception::Error(String::New("Bad argument.")));
}
String::Utf8Value path(args[0]->ToString());
int r = chdir(*path);
if (r != 0) {
return ThrowException(Exception::Error(String::New(strerror(errno))));
}
return Undefined();
}
static Handle<Value> Cwd(const Arguments& args) {
HandleScope scope;
@@ -607,6 +625,7 @@ static Local<Object> Load(int argc, char *argv[]) {
// define various internal methods
NODE_SET_METHOD(process, "compile", Compile);
NODE_SET_METHOD(process, "reallyExit", Exit);
NODE_SET_METHOD(process, "chdir", Chdir);
NODE_SET_METHOD(process, "cwd", Cwd);
NODE_SET_METHOD(process, "dlopen", DLOpen);
NODE_SET_METHOD(process, "kill", Kill);

View File

@@ -0,0 +1,9 @@
process.mixin(require("./common"));
var dirname = path.dirname(__filename);
assertTrue(process.cwd() !== dirname);
process.chdir(dirname);
assertTrue(process.cwd() === dirname);