mirror of
https://github.com/robertkrimen/otto
synced 2025-10-05 19:19:10 +08:00
support Number.isNaN
This commit is contained in:
parent
9fa7c0c0f8
commit
37f8e9a246
|
@ -88,6 +88,13 @@ func builtinNumber_toPrecision(call FunctionCall) Value {
|
|||
return toValue_string(strconv.FormatFloat(call.This.float64(), 'g', int(precision), 64))
|
||||
}
|
||||
|
||||
func builtinNumber_isNaN(call FunctionCall) Value {
|
||||
if len(call.ArgumentList) < 1 {
|
||||
return toValue_bool(false)
|
||||
}
|
||||
return toValue_bool(call.Argument(0).IsNaN())
|
||||
}
|
||||
|
||||
func builtinNumber_toLocaleString(call FunctionCall) Value {
|
||||
return builtinNumber_toString(call)
|
||||
}
|
||||
|
|
|
@ -134,3 +134,14 @@ func TestGlobal_unescape(t *testing.T) {
|
|||
`, "abc,==,abc=%+32,世界")
|
||||
})
|
||||
}
|
||||
|
||||
func TestNumber_isNaN(t *testing.T) {
|
||||
tt(t, func() {
|
||||
test, _ := test()
|
||||
test(`Number.isNaN(1)`, false)
|
||||
test(`Number.isNaN(null)`, false)
|
||||
test(`Number.isNaN()`, false)
|
||||
test(`Number.isNaN(Number.NaN)`, true)
|
||||
test(`Number.isNaN(0+undefined)`, true)
|
||||
})
|
||||
}
|
||||
|
|
31
inline.go
31
inline.go
|
@ -2627,6 +2627,29 @@ func _newContext(runtime *_runtime) {
|
|||
call: builtinNumber_toLocaleString,
|
||||
},
|
||||
}
|
||||
isNaN_function := &_object{
|
||||
runtime: runtime,
|
||||
class: "Function",
|
||||
objectClass: _classObject,
|
||||
prototype: runtime.global.FunctionPrototype,
|
||||
extensible: true,
|
||||
property: map[string]_property{
|
||||
"length": _property{
|
||||
mode: 0,
|
||||
value: Value{
|
||||
kind: valueNumber,
|
||||
value: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
propertyOrder: []string{
|
||||
"length",
|
||||
},
|
||||
value: _nativeFunctionObject{
|
||||
name: "isNaN",
|
||||
call: builtinNumber_isNaN,
|
||||
},
|
||||
}
|
||||
runtime.global.NumberPrototype = &_object{
|
||||
runtime: runtime,
|
||||
class: "Number",
|
||||
|
@ -2713,6 +2736,13 @@ func _newContext(runtime *_runtime) {
|
|||
value: runtime.global.NumberPrototype,
|
||||
},
|
||||
},
|
||||
"isNaN": _property{
|
||||
mode: 0101,
|
||||
value: Value{
|
||||
kind: valueObject,
|
||||
value: isNaN_function,
|
||||
},
|
||||
},
|
||||
"MAX_VALUE": _property{
|
||||
mode: 0,
|
||||
value: Value{
|
||||
|
@ -2752,6 +2782,7 @@ func _newContext(runtime *_runtime) {
|
|||
propertyOrder: []string{
|
||||
"length",
|
||||
"prototype",
|
||||
"isNaN",
|
||||
"MAX_VALUE",
|
||||
"MIN_VALUE",
|
||||
"NaN",
|
||||
|
|
Loading…
Reference in New Issue
Block a user