good morning!!!!

Skip to content
Snippets Groups Projects
Commit 9d81f4fd authored by Felix Lange's avatar Felix Lange
Browse files

Merge pull request #2448 from fjl/jsre-bignum

jsre: print BigNumber objects with custom constructor as number
parents f460b021 4e85be07
No related branches found
No related tags found
No related merge requests found
......@@ -227,12 +227,20 @@ func iterOwnKeys(vm *otto.Otto, obj *otto.Object, f func(string)) {
}
func (ctx ppctx) isBigNumber(v *otto.Object) bool {
BigNumber, err := ctx.vm.Run("BigNumber.prototype")
if err != nil {
panic(err)
// Handle numbers with custom constructor.
if v, _ := v.Get("constructor"); v.Object() != nil {
if strings.HasPrefix(toString(v.Object()), "function BigNumber") {
return true
}
}
// Handle default constructor.
BigNumber, _ := ctx.vm.Object("BigNumber.prototype")
if BigNumber == nil {
return false
}
cp := constructorPrototype(v)
return cp != nil && cp.Value() == BigNumber
bv, _ := BigNumber.Call("isPrototypeOf", v)
b, _ := bv.ToBoolean()
return b
}
func toString(obj *otto.Object) string {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment