mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
Added process.chdir()
This commit is contained in:
committed by
Ryan Dahl
parent
726865af7b
commit
47fcf785ac
19
src/node.cc
19
src/node.cc
@@ -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);
|
||||
|
||||
9
test/mjsunit/test-chdir.js
Normal file
9
test/mjsunit/test-chdir.js
Normal 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);
|
||||
Reference in New Issue
Block a user