@@ -1620,6 +1620,13 @@ Notes on individual types:
16201620Primitive types (numbers, string, bool) are converted to the corresponding JavaScript primitives. These values
16211621are goroutine-safe and can be transferred between runtimes.
16221622
1623+ # *big.Int
1624+
1625+ A *big.Int value is converted to a BigInt value. Note, because BigInt is immutable, but *big.Int isn't, the value is
1626+ copied. Export()'ing this value returns a *big.Int which is also a copy.
1627+
1628+ If the pointer value is nil, the resulting BigInt is 0n.
1629+
16231630# Strings
16241631
16251632Because of the difference in internal string representation between ECMAScript (which uses UTF-16) and Go (which uses
@@ -1861,7 +1868,11 @@ func (r *Runtime) toValue(i interface{}, origValue reflect.Value) Value {
18611868 case float64 :
18621869 return floatToValue (i )
18631870 case * big.Int :
1864- return (* valueBigInt )(new (big.Int ).Set (i ))
1871+ v := new (big.Int )
1872+ if i != nil {
1873+ v .Set (i )
1874+ }
1875+ return (* valueBigInt )(v )
18651876 case map [string ]interface {}:
18661877 if i == nil {
18671878 return _null
@@ -2536,6 +2547,25 @@ func IsInfinity(v Value) bool {
25362547 return v == _positiveInf || v == _negativeInf
25372548}
25382549
2550+ func IsNumber (v Value ) bool {
2551+ switch v .(type ) {
2552+ case valueInt , valueFloat :
2553+ return true
2554+ default :
2555+ return false
2556+ }
2557+ }
2558+
2559+ func IsBigInt (v Value ) bool {
2560+ _ , ok := v .(* valueBigInt )
2561+ return ok
2562+ }
2563+
2564+ func IsString (v Value ) bool {
2565+ _ , ok := v .(String )
2566+ return ok
2567+ }
2568+
25392569// Undefined returns JS undefined value. Note if global 'undefined' property is changed this still returns the original value.
25402570func Undefined () Value {
25412571 return _undefined
0 commit comments