Skip to content

Commit

Permalink
core: throw TypeError if chdir() args are wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
caitp committed Jan 9, 2015
1 parent b8891d6 commit f8666bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1499,8 +1499,7 @@ static void Chdir(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

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

node::Utf8Value path(args.GetIsolate(), args[0]);
Expand Down
5 changes: 5 additions & 0 deletions test/sequential/test-chdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ assert(process.cwd() == dir);
process.chdir('..');
assert(process.cwd() == path.resolve(common.fixturesDir));
fs.rmdirSync(dir);

assert.throws(function() { process.chdir({}); }, TypeError, 'Bad argument.');
assert.throws(function() { process.chdir(); }, TypeError, 'Bad argument.');
assert.throws(function() { process.chdir("x", "y"); }, TypeError, 'Bad argument.');

0 comments on commit f8666bf

Please sign in to comment.