@@ -228,26 +228,40 @@ pub fn add_entries_from_iterable_weak_map_constructor<'a>(
228228 unreachable ! ( )
229229 } ;
230230 let slice = entry. as_slice ( & array_heap) ;
231- let key = canonicalize_keyed_collection_key ( numbers, slice[ 0 ] . unwrap ( ) ) ;
232- let key_hash = hasher ( key) ;
233- let value = slice[ 1 ] . unwrap ( ) ;
234- let next_index = keys. len ( ) as u32 ;
235- let entry = map_data. entry (
236- key_hash,
237- |hash_equal_index| keys[ * hash_equal_index as usize ] . unwrap ( ) == key,
238- |index_to_hash| hasher ( keys[ * index_to_hash as usize ] . unwrap ( ) ) ,
239- ) ;
240- match entry {
241- hashbrown:: hash_table:: Entry :: Occupied ( occupied) => {
242- // We have duplicates in the array. Latter
243- // ones overwrite earlier ones.
244- let index = * occupied. get ( ) ;
245- values[ index as usize ] = Some ( value) ;
246- }
247- hashbrown:: hash_table:: Entry :: Vacant ( vacant) => {
248- vacant. insert ( next_index) ;
249- keys. push ( Some ( key) ) ;
250- values. push ( Some ( value) ) ;
231+ if let Some ( value) = slice[ 0 ] {
232+ if value. is_object ( ) || value. is_symbol ( ) {
233+ let key = canonicalize_keyed_collection_key ( numbers, value) ;
234+ let key_hash = hasher ( key) ;
235+ let value = slice[ 1 ] . unwrap ( ) ;
236+ let next_index = keys. len ( ) as u32 ;
237+ let entry = map_data. entry (
238+ key_hash,
239+ |hash_equal_index| {
240+ keys[ * hash_equal_index as usize ] . unwrap ( ) == key
241+ } ,
242+ |index_to_hash| {
243+ hasher ( keys[ * index_to_hash as usize ] . unwrap ( ) )
244+ } ,
245+ ) ;
246+ match entry {
247+ hashbrown:: hash_table:: Entry :: Occupied ( occupied) => {
248+ // We have duplicates in the array. Latter
249+ // ones overwrite earlier ones.
250+ let index = * occupied. get ( ) ;
251+ values[ index as usize ] = Some ( value) ;
252+ }
253+ hashbrown:: hash_table:: Entry :: Vacant ( vacant) => {
254+ vacant. insert ( next_index) ;
255+ keys. push ( Some ( key) ) ;
256+ values. push ( Some ( value) ) ;
257+ }
258+ }
259+ } else {
260+ return Err ( agent. throw_exception_with_static_message (
261+ ExceptionType :: TypeError ,
262+ "WeakMap key must be an Object or Symbol" ,
263+ gc. nogc ( ) ,
264+ ) ) ;
251265 }
252266 }
253267 }
0 commit comments