Browse Source

Added process.chdir()

v0.7.4-release
Brandon Beacher 15 years ago
committed by Ryan Dahl
parent
commit
47fcf785ac
  1. 19
      src/node.cc
  2. 9
      test/mjsunit/test-chdir.js

19
src/node.cc

@ -231,6 +231,24 @@ Handle<Value> ExecuteString(v8::Handle<v8::String> source,
return scope.Close(result); 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) { static Handle<Value> Cwd(const Arguments& args) {
HandleScope scope; HandleScope scope;
@ -607,6 +625,7 @@ static Local<Object> Load(int argc, char *argv[]) {
// define various internal methods // define various internal methods
NODE_SET_METHOD(process, "compile", Compile); NODE_SET_METHOD(process, "compile", Compile);
NODE_SET_METHOD(process, "reallyExit", Exit); NODE_SET_METHOD(process, "reallyExit", Exit);
NODE_SET_METHOD(process, "chdir", Chdir);
NODE_SET_METHOD(process, "cwd", Cwd); NODE_SET_METHOD(process, "cwd", Cwd);
NODE_SET_METHOD(process, "dlopen", DLOpen); NODE_SET_METHOD(process, "dlopen", DLOpen);
NODE_SET_METHOD(process, "kill", Kill); NODE_SET_METHOD(process, "kill", Kill);

9
test/mjsunit/test-chdir.js

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