Skip to content

Commit

Permalink
valueBigInt ToInteger throw TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroyk committed Aug 22, 2024
1 parent c1f3657 commit 5d79cc7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion builtin_bigint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type valueBigInt big.Int

func (v *valueBigInt) ToInteger() int64 {
return (*big.Int)(v).Int64()
panic(typeError("Cannot convert a BigInt value to a number"))
}

func (v *valueBigInt) toString() String {
Expand Down
8 changes: 4 additions & 4 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,11 +839,11 @@ func (r *Runtime) builtin_Number(call FunctionCall) Value {
case *Object:
primValue := t.toPrimitiveNumber()
if bigint, ok := primValue.(*valueBigInt); ok {
return intToValue(bigint.ToInteger())
return intToValue((*big.Int)(bigint).Int64())
}
return primValue.ToNumber()
case *valueBigInt:
return intToValue(t.ToInteger())
return intToValue((*big.Int)(t).Int64())
default:
return t.ToNumber()
}
Expand All @@ -859,12 +859,12 @@ func (r *Runtime) builtin_newNumber(args []Value, proto *Object) *Object {
case *Object:
primValue := t.toPrimitiveNumber()
if bigint, ok := primValue.(*valueBigInt); ok {
v = intToValue(bigint.ToInteger())
v = intToValue((*big.Int)(bigint).Int64())
} else {
v = primValue.ToNumber()
}
case *valueBigInt:
v = intToValue(t.ToInteger())
v = intToValue((*big.Int)(t).Int64())
default:
v = t.ToNumber()
}
Expand Down

0 comments on commit 5d79cc7

Please sign in to comment.