Skip to content

Commit be2404e

Browse files
caitpbnoordhuis
authored andcommitted
core: throw TypeError if chdir() args are wrong
PR-URL: #274 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent b8891d6 commit be2404e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/node.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,7 @@ static void Chdir(const FunctionCallbackInfo<Value>& args) {
14991499
Environment* env = Environment::GetCurrent(args);
15001500

15011501
if (args.Length() != 1 || !args[0]->IsString()) {
1502-
// FIXME(bnoordhuis) ThrowTypeError?
1503-
return env->ThrowError("Bad argument.");
1502+
return env->ThrowTypeError("Bad argument.");
15041503
}
15051504

15061505
node::Utf8Value path(args.GetIsolate(), args[0]);

test/sequential/test-chdir.js

+4
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ assert(process.cwd() == dir);
3838
process.chdir('..');
3939
assert(process.cwd() == path.resolve(common.fixturesDir));
4040
fs.rmdirSync(dir);
41+
42+
assert.throws(function() { process.chdir({}); }, TypeError, 'Bad argument.');
43+
assert.throws(function() { process.chdir(); }, TypeError, 'Bad argument.');
44+
assert.throws(function() { process.chdir("x", "y"); }, TypeError, 'Bad argument.');

0 commit comments

Comments
 (0)