From e30ae1e6dc3a3c08053f479f70ac0550b7ed4b10 Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Fri, 14 Jul 2023 16:30:07 +0200 Subject: [PATCH 1/2] Add GopherJS wrapper/stub around ParseInt --- compiler/natives/src/strconv/atoi.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/natives/src/strconv/atoi.go b/compiler/natives/src/strconv/atoi.go index 63ea9b732..59a403f57 100644 --- a/compiler/natives/src/strconv/atoi.go +++ b/compiler/natives/src/strconv/atoi.go @@ -12,6 +12,11 @@ const ( minInt32 float64 = -1 << 31 ) +//gopherjs:keep-original +func ParseInt(s string, base, bitSize int) (i int64, err error) { + return _gopherjs_original_ParseInt(s, base, bitSize) +} + // Atoi returns the result of ParseInt(s, 10, 0) converted to type int. func Atoi(s string) (int, error) { const fnAtoi = "Atoi" From 6ec398e63b72aef2b2c739fee00bdf98cfa22b2c Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Mon, 17 Jul 2023 12:01:55 +0200 Subject: [PATCH 2/2] first/naive approach --- compiler/natives/src/strconv/atoi.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/natives/src/strconv/atoi.go b/compiler/natives/src/strconv/atoi.go index 59a403f57..ce8790478 100644 --- a/compiler/natives/src/strconv/atoi.go +++ b/compiler/natives/src/strconv/atoi.go @@ -14,6 +14,10 @@ const ( //gopherjs:keep-original func ParseInt(s string, base, bitSize int) (i int64, err error) { + if base == 10 && (bitSize == 0 || bitSize == 32) { + i, err := Atoi(s) + return int64(i), err + } return _gopherjs_original_ParseInt(s, base, bitSize) } @@ -44,7 +48,8 @@ func Atoi(s string) (int, error) { floatval := jsValue.Float() if floatval > maxInt32 { return int(maxInt32), rangeError(fnAtoi, s) - } else if floatval < minInt32 { + } + if floatval < minInt32 { return int(minInt32), rangeError(fnAtoi, s) } // Success!