Skip to content

Commit 9b338f9

Browse files
committed
Check hasOwnProperty after conversion to string
I thought I could be clever and micro-optimize this a bit, but `has_own_property` really does require a string argument, so we have to do the conversion first.
1 parent f6b1c4f commit 9b338f9

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

crates/neon-runtime/src/napi/object.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub unsafe extern "C" fn get_own_property_names(out: &mut Local, env: Env, objec
3232
}
3333

3434
let raw_names = raw_names.assume_init();
35-
let mut fixed_names = fixed_names.assume_init();
35+
let fixed_names = fixed_names.assume_init();
3636

3737
*out = fixed_names;
3838

@@ -47,17 +47,6 @@ pub unsafe extern "C" fn get_own_property_names(out: &mut Local, env: Env, objec
4747
continue;
4848
}
4949

50-
let mut is_own_property = false;
51-
// May return a non-OK status if `key` is not a string or a Symbol, but here it is always
52-
// a string.
53-
if napi::napi_has_own_property(env, object, property_name, &mut is_own_property as *mut _) != napi::napi_status::napi_ok {
54-
return false;
55-
}
56-
57-
if !is_own_property {
58-
continue;
59-
}
60-
6150
// Before https://github.com/nodejs/node/pull/27524, `napi_get_property_names` would return
6251
// numbers for numeric indices instead of strings.
6352
// Make sure we always return strings.
@@ -72,6 +61,17 @@ pub unsafe extern "C" fn get_own_property_names(out: &mut Local, env: Env, objec
7261
property_name
7362
};
7463

64+
let mut is_own_property = false;
65+
// May return a non-OK status if `key` is not a string or a Symbol, but here it is always
66+
// a string.
67+
if napi::napi_has_own_property(env, object, property_name, &mut is_own_property as *mut _) != napi::napi_status::napi_ok {
68+
return false;
69+
}
70+
71+
if !is_own_property {
72+
continue;
73+
}
74+
7575
let mut dummy = false;
7676
// If we can't convert assign to this array, something went wrong.
7777
if !set_index(&mut dummy, env, fixed_names, fixed_len, property_name) {

test/napi/lib/hello.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ describe('hello', function() {
2525
0: 1,
2626
a: 1,
2727
whatever: true
28-
})
28+
});
2929
});
3030
});

0 commit comments

Comments
 (0)