mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:02:45 +00:00 
			
		
		
		
	LibJS: Implement parseInt()
Here's a reasonably faithful implementation of ECMAScript 2021 18.2.5. Some corner cases are not covered, I've left them as FIXME's in the included unit test. Also I had to tweak JS::Value::to_i32() to always convert infinity to zero, which is in accordance with ToInt32 AFAICT.
This commit is contained in:
		
							parent
							
								
									4ae0de9a37
								
							
						
					
					
						commit
						e6dadd9e5b
					
				
					 5 changed files with 125 additions and 3 deletions
				
			
		|  | @ -356,10 +356,8 @@ i32 Value::to_i32(GlobalObject& global_object) const | |||
|     auto number = to_number(global_object); | ||||
|     if (global_object.vm().exception()) | ||||
|         return 0; | ||||
|     if (number.is_nan()) | ||||
|     if (number.is_nan() || number.is_infinity()) | ||||
|         return 0; | ||||
|     // FIXME: What about infinity though - that's UB...
 | ||||
|     // Maybe NumericLimits<i32>::max() for +Infinity and NumericLimits<i32>::min() for -Infinity?
 | ||||
|     return number.as_i32(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling