@@ -1987,16 +1987,22 @@ pub extern "C" fn js_object_values(obj: *const ObjectHeader) -> *mut ArrayHeader
19871987 None => j as u32 ,
19881988 }
19891989 } ;
1990- // #5046: skip keys a descriptor marks non-enumerable, like
1991- // `js_object_keys` does. Cheap any-descriptor probe first so
1992- // descriptor-free objects stay on the fast path.
1993- let has_descriptors =
1994- PROPERTY_DESCRIPTORS . with ( |m| m. borrow ( ) . keys ( ) . any ( |( ptr, _) | * ptr == obj as usize ) ) ;
1995-
1996- // Snapshot the enumerable key list before reading values, then read each
1990+ // Snapshot the own key list before reading values, then read each
19971991 // through the name-keyed `[[Get]]` so own accessors fire and getter side
19981992 // effects don't perturb the key set (mirrors `js_object_entries`).
1999- let mut snapshot_keys: Vec < f64 > = Vec :: with_capacity ( count) ;
1993+ //
1994+ // Two correctness requirements drive this shape:
1995+ // * GC safety — a getter fired by `js_object_get_field_by_name` can
1996+ // delete a future key and allocate/GC before we visit it. A key kept
1997+ // only as a NaN-boxed pointer inside this Rust-heap `Vec` is not a
1998+ // stack-visible GC root, so it could dangle. We snapshot the owned
1999+ // key *bytes* and rematerialize the string at read time instead.
2000+ // * EnumerableOwnProperties — enumerability is determined per key at
2001+ // read time, not cached up front: an earlier getter can create a
2002+ // descriptor or flip a future key's enumerability, so we defer the
2003+ // `descriptor_marks_non_enumerable` check to the read phase.
2004+ let mut snapshot_keys: Vec < Vec < u8 > > = Vec :: with_capacity ( count) ;
2005+ let mut key_buf = [ 0u8 ; crate :: value:: SHORT_STRING_MAX_LEN ] ;
20002006 for j in 0 ..count {
20012007 let i = pos ( j) ;
20022008 if keys. is_null ( ) || i >= crate :: array:: js_array_length ( keys) {
@@ -2006,25 +2012,23 @@ pub extern "C" fn js_object_values(obj: *const ObjectHeader) -> *mut ArrayHeader
20062012 if instance_private_key_hidden ( obj, key_val) {
20072013 continue ;
20082014 }
2009- if has_descriptors && descriptor_marks_non_enumerable ( obj , key_val ) {
2010- continue ;
2015+ if let Some ( bytes ) = crate :: string :: js_string_key_bytes ( key_val , & mut key_buf ) {
2016+ snapshot_keys . push ( bytes . to_vec ( ) ) ;
20112017 }
2012- snapshot_keys. push ( f64:: from_bits ( key_val. bits ( ) ) ) ;
20132018 }
2014- for key_f64 in snapshot_keys {
2019+ for key_bytes in snapshot_keys {
20152020 let key_str =
2016- crate :: value :: js_get_string_pointer_unified ( key_f64 ) as * const crate :: StringHeader ;
2021+ crate :: string :: js_string_from_bytes ( key_bytes . as_ptr ( ) , key_bytes . len ( ) as u32 ) ;
20172022 if key_str. is_null ( ) {
20182023 continue ;
20192024 }
20202025 // Re-check own + enumerable at read time (a prior getter may have
2021- // removed/hidden the key) — see `js_object_entries`.
2026+ // removed/hidden the key, or created a descriptor) — see
2027+ // `js_object_entries`.
20222028 if !super :: own_key_present ( obj as * mut ObjectHeader , key_str) {
20232029 continue ;
20242030 }
2025- if has_descriptors
2026- && descriptor_marks_non_enumerable ( obj, JSValue :: from_bits ( key_f64. to_bits ( ) ) )
2027- {
2031+ if descriptor_marks_non_enumerable ( obj, JSValue :: string_ptr ( key_str) ) {
20282032 continue ;
20292033 }
20302034 let value = js_object_get_field_by_name ( obj as * const ObjectHeader , key_str) ;
@@ -2157,20 +2161,22 @@ pub extern "C" fn js_object_entries(obj: *const ObjectHeader) -> *mut ArrayHeade
21572161 None => j as u32 ,
21582162 }
21592163 } ;
2160- // #5046: skip keys a descriptor marks non-enumerable, like
2161- // `js_object_keys` does. Cheap any-descriptor probe first so
2162- // descriptor-free objects stay on the fast path.
2163- let has_descriptors =
2164- PROPERTY_DESCRIPTORS . with ( |m| m. borrow ( ) . keys ( ) . any ( |( ptr, _) | * ptr == obj as usize ) ) ;
2165-
2166- // Spec (EnumerableOwnProperties): the own enumerable key list is
2167- // determined ONCE up front, then `[[Get]]` is invoked per key. A getter
2168- // that adds, removes, or hides a future key during enumeration must not
2169- // change the set of entries reported (test262 entries/getter-adding-key,
2164+ // Spec (EnumerableOwnProperties): the own key list is determined ONCE up
2165+ // front, then `[[Get]]` is invoked per key. A getter that adds, removes,
2166+ // or hides a future key during enumeration must not change the set of
2167+ // entries reported (test262 entries/getter-adding-key,
21702168 // getter-removing-future-key, getter-making-future-key-nonenumerable).
2171- // Snapshot the enumerable string keys (NaN-boxed) before reading any
2172- // value so getter side effects on `keys_array` can't perturb the loop.
2173- let mut snapshot_keys: Vec < f64 > = Vec :: with_capacity ( count) ;
2169+ //
2170+ // Snapshot the own key *bytes* (not NaN-boxed pointers): a getter fired
2171+ // by `js_object_get_field_by_name` can delete a future key and
2172+ // allocate/GC before we visit it, and a key kept only inside this
2173+ // Rust-heap `Vec` is not a stack-visible GC root — it could dangle.
2174+ // Owning the bytes and rematerializing the string at read time sidesteps
2175+ // that. Enumerability is likewise re-evaluated per key in the read phase
2176+ // (an earlier getter can create a descriptor or flip a future key's
2177+ // enumerability), so we deliberately do NOT filter it during the snapshot.
2178+ let mut snapshot_keys: Vec < Vec < u8 > > = Vec :: with_capacity ( count) ;
2179+ let mut key_buf = [ 0u8 ; crate :: value:: SHORT_STRING_MAX_LEN ] ;
21742180 for j in 0 ..count {
21752181 let i = pos ( j) ;
21762182 if keys. is_null ( ) || i >= crate :: array:: js_array_length ( keys) {
@@ -2180,15 +2186,14 @@ pub extern "C" fn js_object_entries(obj: *const ObjectHeader) -> *mut ArrayHeade
21802186 if instance_private_key_hidden ( obj, key_val) {
21812187 continue ;
21822188 }
2183- if has_descriptors && descriptor_marks_non_enumerable ( obj , key_val ) {
2184- continue ;
2189+ if let Some ( bytes ) = crate :: string :: js_string_key_bytes ( key_val , & mut key_buf ) {
2190+ snapshot_keys . push ( bytes . to_vec ( ) ) ;
21852191 }
2186- snapshot_keys. push ( f64:: from_bits ( key_val. bits ( ) ) ) ;
21872192 }
21882193
2189- for key_f64 in snapshot_keys {
2194+ for key_bytes in snapshot_keys {
21902195 let key_str =
2191- crate :: value :: js_get_string_pointer_unified ( key_f64 ) as * const crate :: StringHeader ;
2196+ crate :: string :: js_string_from_bytes ( key_bytes . as_ptr ( ) , key_bytes . len ( ) as u32 ) ;
21922197 if key_str. is_null ( ) {
21932198 continue ;
21942199 }
@@ -2201,14 +2206,15 @@ pub extern "C" fn js_object_entries(obj: *const ObjectHeader) -> *mut ArrayHeade
22012206 if !super :: own_key_present ( obj as * mut ObjectHeader , key_str) {
22022207 continue ;
22032208 }
2204- if has_descriptors
2205- && descriptor_marks_non_enumerable ( obj, JSValue :: from_bits ( key_f64. to_bits ( ) ) )
2206- {
2209+ if descriptor_marks_non_enumerable ( obj, JSValue :: string_ptr ( key_str) ) {
22072210 continue ;
22082211 }
22092212 // Create a pair array [key, value].
22102213 let pair = crate :: array:: js_array_alloc ( 2 ) ;
2211- crate :: array:: js_array_push_f64 ( pair, key_f64) ;
2214+ crate :: array:: js_array_push_f64 (
2215+ pair,
2216+ f64:: from_bits ( JSValue :: string_ptr ( key_str) . bits ( ) ) ,
2217+ ) ;
22122218
22132219 // Read the value through the name-keyed `[[Get]]`, which fires an
22142220 // own accessor's getter (the raw index-based field read returned the
0 commit comments