mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 08:02:44 +00:00 
			
		
		
		
	LibJS: Don't treat 2^32 - 1 as numeric PropertyName
10.4.2 Array Exotic Objects
    https://tc39.es/ecma262/#sec-array-exotic-objects
    A String property name P is an array index if and only if
    ToString(ToUint32(P)) equals P and ToUint32(P) is not the same value
    as 𝔽(2^32 - 1).
			
			
This commit is contained in:
		
							parent
							
								
									47bd25a2f1
								
							
						
					
					
						commit
						83f61748a5
					
				
					 2 changed files with 34 additions and 4 deletions
				
			
		|  | @ -0,0 +1,30 @@ | |||
| test("numeric properties", () => { | ||||
|     const i32Max = 2 ** 31 - 1; | ||||
|     const u32Max = 2 ** 32 - 1; | ||||
|     const o = { | ||||
|         [-1]: "foo", | ||||
|         0: "foo", | ||||
|         1: "foo", | ||||
|         [i32Max - 1]: "foo", | ||||
|         [i32Max]: "foo", | ||||
|         [i32Max + 1]: "foo", | ||||
|         [u32Max - 1]: "foo", | ||||
|         [u32Max]: "foo", | ||||
|         [u32Max + 1]: "foo", | ||||
|     }; | ||||
|     // Numeric properties come first in Object.getOwnPropertyNames()'s output,
 | ||||
|     // which means we can test what each is treated as internally.
 | ||||
|     expect(Object.getOwnPropertyNames(o)).toEqual([ | ||||
|         // Numeric properties
 | ||||
|         "0", | ||||
|         "1", | ||||
|         "2147483646", | ||||
|         "2147483647", | ||||
|         "2147483648", | ||||
|         "4294967294", | ||||
|         // Non-numeric properties
 | ||||
|         "-1", | ||||
|         "4294967295", // >= 2^32 - 1
 | ||||
|         "4294967296", // >= 2^32 - 1
 | ||||
|     ]); | ||||
| }); | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh