Skip to content

Commit c7ac3b9

Browse files
committed
Avoid BigInt until we need it
1 parent 6ae7a94 commit c7ac3b9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ public static LocalValue ConvertFrom(object? value)
9393
}
9494
}
9595

96-
private static readonly BigInteger MaxDouble = new BigInteger(double.MaxValue);
97-
private static readonly BigInteger MinDouble = new BigInteger(double.MinValue);
98-
9996
public static LocalValue ConvertFrom(JsonNode? node)
10097
{
10198
if (node is null)
@@ -121,14 +118,16 @@ public static LocalValue ConvertFrom(JsonNode? node)
121118
{
122119
var numberString = node.ToString();
123120

124-
var bigNumber = BigInteger.Parse(numberString);
121+
var numberAsDouble = double.Parse(numberString);
125122

126-
if (bigNumber > MaxDouble || bigNumber < MinDouble)
123+
if (double.IsInfinity(numberAsDouble))
127124
{
125+
// Numbers outside of Int64's range will successfully parse, but become +- Infinity
126+
// We can retain the value using a BigInt
128127
return new BigIntLocalValue(numberString);
129128
}
130129

131-
return new NumberLocalValue(double.Parse(numberString));
130+
return new NumberLocalValue(numberAsDouble);
132131
}
133132

134133
case System.Text.Json.JsonValueKind.Array:

0 commit comments

Comments
 (0)