Skip to content

Commit b891487

Browse files
committed
chore: simplify return type
Tested with `require('internal/test/binding').internalBinding('util').guessHandleType(2**31)` (not sure if there was a better way, but it works so)
1 parent e986407 commit b891487

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

lib/internal/util.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,15 +877,14 @@ function getCIDR(address, netmask, family) {
877877
}
878878

879879
const handleTypes = ['TCP', 'TTY', 'UDP', 'FILE', 'PIPE', 'UNKNOWN'];
880-
setOwnProperty(handleTypes, -1, null);
881880

882881
function guessHandleType(fd) {
883882
if (typeof fd !== 'number' || fd >> 0 !== fd || fd < 0) {
884883
throw new ERR_INVALID_FD(fd);
885884
}
886885

887886
const type = _guessHandleType(fd);
888-
return handleTypes[type];
887+
return handleTypes[type] || type;
889888
}
890889

891890
class WeakReference {

src/node_util.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,9 @@ static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
228228
int fd;
229229
if (!args[0]->Int32Value(env->context()).To(&fd)) return;
230230

231-
// If the provided file descriptor is not valid, we return `-1`, which in JS
232-
// land will be marked as null
231+
// If the provided file descriptor is not valid, we return null
233232
if (fd < 0) [[unlikely]] {
234-
args.GetReturnValue().Set(-1);
233+
args.GetReturnValue().Set(v8::Null(env->isolate()));
235234
return;
236235
}
237236

0 commit comments

Comments
 (0)