@@ -98,6 +98,18 @@ fn AssertGCPointerAlignment(bits: u64) {
9898#[ inline( always) ]  
9999fn  AssertGCPointerAlignment ( bits :  u64 )  { } 
100100
101+ #[ cfg( target_pointer_width = "64" ) ]  
102+ #[ inline( always) ]  
103+ fn  IsValidUserModePointer ( bits :  u64 )  -> bool  { 
104+     bits &  0xFFFF_0000_0000_0000  == 0 
105+ } 
106+ 
107+ #[ cfg( target_pointer_width = "32" ) ]  
108+ #[ inline( always) ]  
109+ fn  IsValidUserModePointer ( _:  u64 )  -> bool  { 
110+     true 
111+ } 
112+ 
101113#[ inline( always) ]  
102114pub  fn  Int32Value ( i :  i32 )  -> JSVal  { 
103115    BuildJSVal ( ValueTag :: INT32 ,  i as  u32  as  u64 ) 
@@ -115,9 +127,9 @@ pub fn NullValue() -> JSVal {
115127
116128#[ inline( always) ]  
117129pub  fn  DoubleValue ( f :  f64 )  -> JSVal  { 
118-     let  bits :   u64  =  f. to_bits ( ) ; 
119-     assert ! ( bits <=  ValueShiftedTag :: MAX_DOUBLE   as   u64 ) ; 
120-     JSVal   {   asBits_ :  bits  } 
130+     let  val =  JSVal   {   asBits_ :   f. to_bits ( )   } ; 
131+     assert ! ( val . is_double ( ) ) ; 
132+     val 
121133} 
122134
123135#[ inline( always) ]  
@@ -174,8 +186,7 @@ pub fn ObjectOrNullValue(o: *mut JSObject) -> JSVal {
174186#[ inline( always) ]  
175187pub  fn  PrivateValue ( o :  * const  c_void )  -> JSVal  { 
176188    let  ptrBits = o as  usize  as  u64 ; 
177-     #[ cfg( target_pointer_width = "64" ) ]  
178-     assert_eq ! ( ptrBits &  0xFFFF000000000000 ,  0 ) ; 
189+     assert ! ( IsValidUserModePointer ( ptrBits) ) ; 
179190    JSVal  {  asBits_ :  ptrBits } 
180191} 
181192
@@ -222,11 +233,18 @@ impl JSVal {
222233        self . toTag ( )  == ValueTag :: INT32  as  u64 
223234    } 
224235
236+     #[ cfg( target_pointer_width = "64" ) ]  
225237    #[ inline( always) ]  
226238    pub  fn  is_double ( & self )  -> bool  { 
227239        self . asBits ( )  <= ValueShiftedTag :: MAX_DOUBLE  as  u64 
228240    } 
229241
242+     #[ cfg( target_pointer_width = "32" ) ]  
243+     #[ inline( always) ]  
244+     pub  fn  is_double ( & self )  -> bool  { 
245+         ( self . asBits ( )  >> JSVAL_TAG_SHIFT )  as  u32  <= JSVAL_TAG_CLEAR 
246+     } 
247+ 
230248    #[ cfg( target_pointer_width = "64" ) ]  
231249    #[ inline( always) ]  
232250    pub  fn  is_number ( & self )  -> bool  { 
@@ -401,11 +419,14 @@ impl JSVal {
401419        self . payload ( )  != 0 
402420    } 
403421
422+     #[ inline( always) ]  
423+     pub  fn  is_private ( & self )  -> bool  { 
424+         self . is_double ( )  && IsValidUserModePointer ( self . asBits ( ) ) 
425+     } 
426+ 
404427    #[ inline( always) ]  
405428    pub  fn  to_private ( & self )  -> * const  c_void  { 
406-         assert ! ( self . is_double( ) ) ; 
407-         #[ cfg( target_pointer_width = "64" ) ]  
408-         assert_eq ! ( self . asBits( )  &  0xFFFF000000000000 ,  0 ) ; 
429+         assert ! ( self . is_private( ) ) ; 
409430        self . asBits ( )  as  usize  as  * const  c_void 
410431    } 
411432
0 commit comments