11#![ allow( clippy:: collapsible_if, clippy:: collapsible_match, dead_code) ]
22
3- use gc_arena:: Mutation as MutationContext ;
4- use gc_arena:: collect:: Trace ;
5- use gc_arena:: lock:: RefLock as GcCell ;
6- use gc_arena:: { Collect , Gc } ;
7- use num_bigint:: BigInt ;
8- use std:: sync:: { Arc , Mutex } ;
9-
3+ use crate :: core:: { Collect , Gc , GcCell , GcPtr , GcTrace , GcWeak , MutationContext } ;
104use crate :: unicode:: utf16_to_utf8;
115use crate :: {
126 JSError ,
137 core:: { DestructuringElement , PropertyKey , Statement , is_error} ,
148 raise_type_error,
159} ;
16-
17- pub type GcPtr < ' gc , T > = Gc < ' gc , GcCell < T > > ;
10+ use num_bigint :: BigInt ;
11+ use std :: sync :: { Arc , Mutex } ;
1812
1913#[ derive( Clone , Collect ) ]
2014#[ collect( no_drop) ]
@@ -31,13 +25,13 @@ pub struct JSSet<'gc> {
3125#[ derive( Clone , Collect ) ]
3226#[ collect( no_drop) ]
3327pub struct JSWeakMap < ' gc > {
34- pub entries : Vec < ( gc_arena :: GcWeak < ' gc , GcCell < JSObjectData < ' gc > > > , Value < ' gc > ) > ,
28+ pub entries : Vec < ( GcWeak < ' gc , GcCell < JSObjectData < ' gc > > > , Value < ' gc > ) > ,
3529}
3630
3731#[ derive( Clone , Collect ) ]
3832#[ collect( no_drop) ]
3933pub struct JSWeakSet < ' gc > {
40- pub values : Vec < gc_arena :: GcWeak < ' gc , GcCell < JSObjectData < ' gc > > > > ,
34+ pub values : Vec < GcWeak < ' gc , GcCell < JSObjectData < ' gc > > > > ,
4135}
4236
4337#[ derive( Clone , Collect ) ]
@@ -108,7 +102,7 @@ pub enum GeneratorState<'gc> {
108102}
109103
110104pub type JSObjectDataPtr < ' gc > = GcPtr < ' gc , JSObjectData < ' gc > > ;
111- pub type JSObjectDataWeakPtr < ' gc > = gc_arena :: Gc < ' gc , GcCell < JSObjectData < ' gc > > > ;
105+ pub type JSObjectDataWeakPtr < ' gc > = Gc < ' gc , GcCell < JSObjectData < ' gc > > > ;
112106
113107#[ inline]
114108pub fn new_js_object_data < ' gc > ( mc : & MutationContext < ' gc > ) -> JSObjectDataPtr < ' gc > {
@@ -126,8 +120,8 @@ pub struct JSObjectData<'gc> {
126120 pub is_function_scope : bool ,
127121}
128122
129- unsafe impl < ' gc > gc_arena :: Collect < ' gc > for JSObjectData < ' gc > {
130- fn trace < T : gc_arena :: collect :: Trace < ' gc > > ( & self , cc : & mut T ) {
123+ unsafe impl < ' gc > Collect < ' gc > for JSObjectData < ' gc > {
124+ fn trace < T : GcTrace < ' gc > > ( & self , cc : & mut T ) {
131125 for ( k, v) in & self . properties {
132126 k. trace ( cc) ;
133127 ( * v. borrow ( ) ) . trace ( cc) ;
@@ -387,7 +381,7 @@ impl From<&String> for Value<'_> {
387381}
388382
389383unsafe impl < ' gc > Collect < ' gc > for Value < ' gc > {
390- fn trace < T : Trace < ' gc > > ( & self , cc : & mut T ) {
384+ fn trace < T : GcTrace < ' gc > > ( & self , cc : & mut T ) {
391385 match self {
392386 Value :: Object ( obj) => obj. trace ( cc) ,
393387 Value :: Closure ( cl) => cl. trace ( cc) ,
@@ -582,6 +576,25 @@ pub fn env_set<'gc>(mc: &MutationContext<'gc>, env: &JSObjectDataPtr<'gc>, key:
582576 Ok ( ( ) )
583577}
584578
579+ // Helper: Check whether the given object has an own property corresponding to a
580+ // given JS `Value` (as passed to hasOwnProperty / propertyIsEnumerable). This
581+ // centralizes conversion from various `Value` variants (String/Number/Boolean/
582+ // Undefined/Symbol/other) to a `PropertyKey` and calls `get_own_property`.
583+ // Returns true if an own property exists.
584+ pub fn has_own_property_value < ' gc > ( obj : & JSObjectDataPtr < ' gc > , key_val : & Value < ' gc > ) -> bool {
585+ match key_val {
586+ Value :: String ( s) => get_own_property ( obj, & utf16_to_utf8 ( s) . into ( ) ) . is_some ( ) ,
587+ Value :: Number ( n) => get_own_property ( obj, & n. to_string ( ) . into ( ) ) . is_some ( ) ,
588+ Value :: Boolean ( b) => get_own_property ( obj, & b. to_string ( ) . into ( ) ) . is_some ( ) ,
589+ Value :: Undefined => get_own_property ( obj, & "undefined" . into ( ) ) . is_some ( ) ,
590+ Value :: Symbol ( sd) => {
591+ let sym_key = PropertyKey :: Symbol ( sd. clone ( ) ) ;
592+ get_own_property ( obj, & sym_key) . is_some ( )
593+ }
594+ other => get_own_property ( obj, & value_to_string ( other) . into ( ) ) . is_some ( ) ,
595+ }
596+ }
597+
585598pub fn env_set_recursive < ' gc > ( mc : & MutationContext < ' gc > , env : & JSObjectDataPtr < ' gc > , key : & str , val : Value < ' gc > ) -> Result < ( ) , JSError > {
586599 let mut current = * env;
587600 loop {
0 commit comments