mirror of https://github.com/status-im/op-geth.git
Merge pull request #2448 from fjl/jsre-bignum
jsre: print BigNumber objects with custom constructor as number
This commit is contained in:
commit
9d81f4fdd1
|
@ -227,12 +227,20 @@ func iterOwnKeys(vm *otto.Otto, obj *otto.Object, f func(string)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx ppctx) isBigNumber(v *otto.Object) bool {
|
func (ctx ppctx) isBigNumber(v *otto.Object) bool {
|
||||||
BigNumber, err := ctx.vm.Run("BigNumber.prototype")
|
// Handle numbers with custom constructor.
|
||||||
if err != nil {
|
if v, _ := v.Get("constructor"); v.Object() != nil {
|
||||||
panic(err)
|
if strings.HasPrefix(toString(v.Object()), "function BigNumber") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cp := constructorPrototype(v)
|
// Handle default constructor.
|
||||||
return cp != nil && cp.Value() == BigNumber
|
BigNumber, _ := ctx.vm.Object("BigNumber.prototype")
|
||||||
|
if BigNumber == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
bv, _ := BigNumber.Call("isPrototypeOf", v)
|
||||||
|
b, _ := bv.ToBoolean()
|
||||||
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func toString(obj *otto.Object) string {
|
func toString(obj *otto.Object) string {
|
||||||
|
|
Loading…
Reference in New Issue