@ -17,7 +17,8 @@ use crate::{
builtins ::{ string ::is_trimmable_whitespace , BuiltIn , JsArgs } ,
context ::StandardObjects ,
object ::{
internal_methods ::get_prototype_from_constructor , ConstructorBuilder , JsObject , ObjectData ,
internal_methods ::get_prototype_from_constructor , ConstructorBuilder , FunctionBuilder ,
JsObject , ObjectData ,
} ,
property ::Attribute ,
value ::{ AbstractRelation , IntegerOrInfinity , JsValue } ,
@ -49,6 +50,18 @@ impl BuiltIn for Number {
fn init ( context : & mut Context ) -> JsValue {
let _timer = Profiler ::global ( ) . start_event ( Self ::NAME , "init" ) ;
let parse_int = FunctionBuilder ::native ( context , Self ::parse_int )
. name ( "parseInt" )
. length ( 2 )
. constructor ( false )
. build ( ) ;
let parse_float = FunctionBuilder ::native ( context , Self ::parse_float )
. name ( "parseFloat" )
. length ( 1 )
. constructor ( false )
. build ( ) ;
let attribute = Attribute ::READONLY | Attribute ::NON_ENUMERABLE | Attribute ::PERMANENT ;
let number_object = ConstructorBuilder ::with_standard_object (
context ,
@ -65,20 +78,39 @@ impl BuiltIn for Number {
. static_property ( "NEGATIVE_INFINITY" , f64 ::NEG_INFINITY , attribute )
. static_property ( "POSITIVE_INFINITY" , f64 ::INFINITY , attribute )
. static_property ( "NaN" , f64 ::NAN , attribute )
. static_property (
"parseInt" ,
parse_int . clone ( ) ,
Attribute ::WRITABLE | Attribute ::NON_ENUMERABLE | Attribute ::CONFIGURABLE ,
)
. static_property (
"parseFloat" ,
parse_float . clone ( ) ,
Attribute ::WRITABLE | Attribute ::NON_ENUMERABLE | Attribute ::CONFIGURABLE ,
)
. static_method ( Self ::number_is_finite , "isFinite" , 1 )
. static_method ( Self ::number_is_nan , "isNaN" , 1 )
. static_method ( Self ::is_safe_integer , "isSafeInteger" , 1 )
. static_method ( Self ::number_is_integer , "isInteger" , 1 )
. method ( Self ::to_exponential , "toExponential" , 1 )
. method ( Self ::to_fixed , "toFixed" , 1 )
. method ( Self ::to_locale_string , "toLocaleString" , 0 )
. method ( Self ::to_precision , "toPrecision" , 1 )
. method ( Self ::to_string , "toString" , 1 )
. method ( Self ::value_of , "valueOf" , 0 )
. static_method ( Self ::number_is_finite , "isFinite" , 1 )
. static_method ( Self ::number_is_nan , "isNaN" , 1 )
. static_method ( Self ::is_safe_integer , "isSafeInteger" , 1 )
. static_method ( Self ::number_is_integer , "isInteger" , 1 )
. build ( ) ;
context . register_global_builtin_function ( "parseInt" , 2 , Self ::parse_int ) ;
context . register_global_builtin_function ( "parseFloat" , 1 , Self ::parse_float ) ;
context . register_global_property (
"parseInt" ,
parse_int ,
Attribute ::WRITABLE | Attribute ::NON_ENUMERABLE | Attribute ::CONFIGURABLE ,
) ;
context . register_global_property (
"parseFloat" ,
parse_float ,
Attribute ::WRITABLE | Attribute ::NON_ENUMERABLE | Attribute ::CONFIGURABLE ,
) ;
context . register_global_builtin_function ( "isFinite" , 1 , Self ::global_is_finite ) ;
context . register_global_builtin_function ( "isNaN" , 1 , Self ::global_is_nan ) ;