Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/uv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ void ErrName(const FunctionCallbackInfo<Value>& args) {
"DEP0119").IsNothing())
return;
}
int err;
if (!args[0]->Int32Value(env->context()).To(&err)) return;
CHECK_LT(err, 0);
if (args[0]->IsNullOrUndefined()) {
return args.GetReturnValue().SetUndefined();
}
const int err = args[0].As<v8::Int32>()->Value();
const char* name = uv_err_name(err);
args.GetReturnValue().Set(OneByteString(env->isolate(), name));
}
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-uv-errno.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,21 @@ function runTest(fn) {
`Received ${err}`
});
});

}

function errNameTest(fn) {
// uv.errname should not cause crash with invalid args
[0, 1, 2, NaN, {}, false].forEach((err) => {
assert.match(fn(err), /Unknown system error/);
});

// uv.errname should return undefined with null or undefined args
[null, undefined].forEach((err) => {
assert.strictEqual(fn(err), undefined);
});
}

runTest(_errnoException);
runTest(getSystemErrorName);
errNameTest(uv.errname);