diff --git a/common/remote_object.go b/common/remote_object.go index 42c6fad39..3fff43a0c 100644 --- a/common/remote_object.go +++ b/common/remote_object.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "math" + "regexp" "strconv" "strings" @@ -15,6 +16,8 @@ import ( "github.com/dop251/goja" ) +var bigIntR = regexp.MustCompile("^[0-9]*n$") + type objectOverflowError struct{} // Error returns the description of the overflow error. @@ -168,6 +171,14 @@ func parseRemoteObject(obj *cdpruntime.RemoteObject) (any, error) { return parseRemoteObjectValue(obj.Type, obj.Subtype, string(obj.Value), obj.Preview) } + if bigIntR.Match([]byte(obj.UnserializableValue)) { + n, err := strconv.ParseInt(strings.ReplaceAll(obj.UnserializableValue.String(), "n", ""), 10, 64) + if err != nil { + return nil, BigIntParseError{err} + } + return n, nil + } + switch obj.UnserializableValue.String() { case "-0": // To handle +0 divided by negative number return math.Float64frombits(0 | (1 << 63)), nil diff --git a/tests/remote_obj_test.go b/tests/remote_obj_test.go index 418aad7a4..08b8021c0 100644 --- a/tests/remote_obj_test.go +++ b/tests/remote_obj_test.go @@ -156,14 +156,14 @@ func TestEvalRemoteObjectParse(t *testing.T) { { name: "undefined", eval: "undefined", want: goja.Undefined(), }, - // { - // // Commented out until fix applied - // name: "bigint", eval: `BigInt("2")`, want: "2n", - // }, - // { - // // Commented out until fix applied - // name: "unwrapped_bigint", eval: "3n", want: "3n", - // }, + { + // Commented out until fix applied + name: "bigint", eval: `BigInt("2")`, want: 2, + }, + { + // Commented out until fix applied + name: "unwrapped_bigint", eval: "3n", want: 3, + }, { name: "float", eval: "3.14", want: 3.14, },