@@ -49,8 +49,7 @@ CHAR_TEST(16, IsUnicodeSurrogate, (ch & 0xF800) == 0xD800)
4949// If a UTF-16 surrogate is a low/trailing one.
5050CHAR_TEST (16 , IsUnicodeSurrogateTrail, (ch & 0x400 ) != 0 )
5151
52- static void GetOwnNonIndexProperties (
53- const FunctionCallbackInfo<Value>& args) {
52+ static void GetOwnNonIndexProperties (const FunctionCallbackInfo<Value>& args) {
5453 Environment* env = Environment::GetCurrent (args);
5554 Local<Context> context = env->context ();
5655
@@ -62,20 +61,20 @@ static void GetOwnNonIndexProperties(
6261 Local<Array> properties;
6362
6463 PropertyFilter filter =
65- static_cast <PropertyFilter>(args[1 ].As <Uint32>()->Value ());
66-
67- if (!object->GetPropertyNames (
68- context, KeyCollectionMode::kOwnOnly ,
69- filter,
70- IndexFilter::kSkipIndices )
71- .ToLocal (&properties)) {
64+ static_cast <PropertyFilter>(args[1 ].As <Uint32>()->Value ());
65+
66+ if (!object
67+ ->GetPropertyNames (context,
68+ KeyCollectionMode::kOwnOnly ,
69+ filter,
70+ IndexFilter::kSkipIndices )
71+ .ToLocal (&properties)) {
7272 return ;
7373 }
7474 args.GetReturnValue ().Set (properties);
7575}
7676
77- static void GetConstructorName (
78- const FunctionCallbackInfo<Value>& args) {
77+ static void GetConstructorName (const FunctionCallbackInfo<Value>& args) {
7978 CHECK (args[0 ]->IsObject ());
8079
8180 Local<Object> object = args[0 ].As <Object>();
@@ -84,8 +83,7 @@ static void GetConstructorName(
8483 args.GetReturnValue ().Set (name);
8584}
8685
87- static void GetExternalValue (
88- const FunctionCallbackInfo<Value>& args) {
86+ static void GetExternalValue (const FunctionCallbackInfo<Value>& args) {
8987 CHECK (args[0 ]->IsExternal ());
9088 Isolate* isolate = args.GetIsolate ();
9189 Local<External> external = args[0 ].As <External>();
@@ -98,15 +96,14 @@ static void GetExternalValue(
9896
9997static void GetPromiseDetails (const FunctionCallbackInfo<Value>& args) {
10098 // Return undefined if it's not a Promise.
101- if (!args[0 ]->IsPromise ())
102- return ;
99+ if (!args[0 ]->IsPromise ()) return ;
103100
104101 auto isolate = args.GetIsolate ();
105102
106103 Local<Promise> promise = args[0 ].As <Promise>();
107104
108105 int state = promise->State ();
109- Local<Value> values[2 ] = { Integer::New (isolate, state) };
106+ Local<Value> values[2 ] = {Integer::New (isolate, state)};
110107 size_t number_of_values = 1 ;
111108 if (state != Promise::PromiseState::kPending )
112109 values[number_of_values++] = promise->Result ();
@@ -116,19 +113,15 @@ static void GetPromiseDetails(const FunctionCallbackInfo<Value>& args) {
116113
117114static void GetProxyDetails (const FunctionCallbackInfo<Value>& args) {
118115 // Return undefined if it's not a proxy.
119- if (!args[0 ]->IsProxy ())
120- return ;
116+ if (!args[0 ]->IsProxy ()) return ;
121117
122118 Local<Proxy> proxy = args[0 ].As <Proxy>();
123119
124120 // TODO(BridgeAR): Remove the length check as soon as we prohibit access to
125121 // the util binding layer. It's accessed in the wild and `esm` would break in
126122 // case the check is removed.
127123 if (args.Length () == 1 || args[1 ]->IsTrue ()) {
128- Local<Value> ret[] = {
129- proxy->GetTarget (),
130- proxy->GetHandler ()
131- };
124+ Local<Value> ret[] = {proxy->GetTarget (), proxy->GetHandler ()};
132125
133126 args.GetReturnValue ().Set (
134127 Array::New (args.GetIsolate (), ret, arraysize (ret)));
@@ -164,22 +157,17 @@ static void GetCallerLocation(const FunctionCallbackInfo<Value>& args) {
164157}
165158
166159static void PreviewEntries (const FunctionCallbackInfo<Value>& args) {
167- if (!args[0 ]->IsObject ())
168- return ;
160+ if (!args[0 ]->IsObject ()) return ;
169161
170162 Environment* env = Environment::GetCurrent (args);
171163 bool is_key_value;
172164 Local<Array> entries;
173165 if (!args[0 ].As <Object>()->PreviewEntries (&is_key_value).ToLocal (&entries))
174166 return ;
175167 // Fast path for WeakMap and WeakSet.
176- if (args.Length () == 1 )
177- return args.GetReturnValue ().Set (entries);
168+ if (args.Length () == 1 ) return args.GetReturnValue ().Set (entries);
178169
179- Local<Value> ret[] = {
180- entries,
181- Boolean::New (env->isolate (), is_key_value)
182- };
170+ Local<Value> ret[] = {entries, Boolean::New (env->isolate (), is_key_value)};
183171 return args.GetReturnValue ().Set (
184172 Array::New (env->isolate (), ret, arraysize (ret)));
185173}
@@ -216,15 +204,25 @@ static uint32_t GetUVHandleTypeCode(const uv_handle_type type) {
216204 case UV_UNKNOWN_HANDLE:
217205 return 5 ;
218206 default :
219- ABORT ();
207+ // For an unhandled handle type, we want to return `UNKNOWN` instead of
208+ // `INVALID` since the type is "known" by UV, just not exposed further to
209+ // JS land
210+ return 5 ;
220211 }
221212}
222213
223214static void GuessHandleType (const FunctionCallbackInfo<Value>& args) {
224215 Environment* env = Environment::GetCurrent (args);
216+
225217 int fd;
226218 if (!args[0 ]->Int32Value (env->context ()).To (&fd)) return ;
227- CHECK_GE (fd, 0 );
219+
220+ // If the provided file descriptor is not valid, we return `-1`, which in JS
221+ // land will be marked as "INVALID"
222+ if (fd < 0 ) [[unlikely]] {
223+ args.GetReturnValue ().Set (-1 );
224+ return ;
225+ }
228226
229227 uv_handle_type t = uv_guess_handle (fd);
230228 args.GetReturnValue ().Set (GetUVHandleTypeCode (t));
0 commit comments