Skip to content

Commit 5246a4c

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 98b1ad3 commit 5246a4c

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
@@ -898,15 +898,14 @@ function getCIDR(address, netmask, family) {
898898
}
899899

900900
const handleTypes = ['TCP', 'TTY', 'UDP', 'FILE', 'PIPE', 'UNKNOWN'];
901-
setOwnProperty(handleTypes, -1, null);
902901

903902
function guessHandleType(fd) {
904903
if (typeof fd !== 'number' || fd >> 0 !== fd || fd < 0) {
905904
throw new ERR_INVALID_FD(fd);
906905
}
907906

908907
const type = _guessHandleType(fd);
909-
return handleTypes[type];
908+
return handleTypes[type] || type;
910909
}
911910

912911
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(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)