@@ -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,11 @@ 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 {
131+ asBits_ : f. to_bits ( ) ,
132+ } ;
133+ assert ! ( val. is_double( ) ) ;
134+ val
121135}
122136
123137#[ inline( always) ]
@@ -174,8 +188,7 @@ pub fn ObjectOrNullValue(o: *mut JSObject) -> JSVal {
174188#[ inline( always) ]
175189pub fn PrivateValue ( o : * const c_void ) -> JSVal {
176190 let ptrBits = o as usize as u64 ;
177- #[ cfg( target_pointer_width = "64" ) ]
178- assert_eq ! ( ptrBits & 0xFFFF000000000000 , 0 ) ;
191+ assert ! ( IsValidUserModePointer ( ptrBits) ) ;
179192 JSVal { asBits_ : ptrBits }
180193}
181194
@@ -222,11 +235,18 @@ impl JSVal {
222235 self . toTag ( ) == ValueTag :: INT32 as u64
223236 }
224237
238+ #[ cfg( target_pointer_width = "64" ) ]
225239 #[ inline( always) ]
226240 pub fn is_double ( & self ) -> bool {
227241 self . asBits ( ) <= ValueShiftedTag :: MAX_DOUBLE as u64
228242 }
229243
244+ #[ cfg( target_pointer_width = "32" ) ]
245+ #[ inline( always) ]
246+ pub fn is_double ( & self ) -> bool {
247+ ( self . asBits ( ) >> JSVAL_TAG_SHIFT ) as u32 <= JSVAL_TAG_CLEAR
248+ }
249+
230250 #[ cfg( target_pointer_width = "64" ) ]
231251 #[ inline( always) ]
232252 pub fn is_number ( & self ) -> bool {
@@ -401,11 +421,14 @@ impl JSVal {
401421 self . payload ( ) != 0
402422 }
403423
424+ #[ inline( always) ]
425+ pub fn is_private ( & self ) -> bool {
426+ self . is_double ( ) && IsValidUserModePointer ( self . asBits ( ) )
427+ }
428+
404429 #[ inline( always) ]
405430 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 ) ;
431+ assert ! ( self . is_private( ) ) ;
409432 self . asBits ( ) as usize as * const c_void
410433 }
411434
0 commit comments