Skip to content

Commit 446447a

Browse files
committed
compiler/natives/src/strings: Skip optional pointer manipulation.
It's being done upstream to trick the escape analysis and prevent allocations. We can't rely on it here. Fixes: === RUN TestBuilder --- FAIL: TestBuilder (0.01s) TypeError: Cannot create property '$proxies' on number '0'
1 parent 4bff1ed commit 446447a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

compiler/natives/src/strings/strings.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,13 @@ func (b *Builder) String() string {
5555
// and there are benchmarks available (see https://github.com/golang/go/issues/18990#issuecomment-352068533).
5656
return string(b.buf)
5757
}
58+
59+
func (b *Builder) copyCheck() {
60+
if b.addr == nil {
61+
// Upstream copyCheck uses noescape, which performs unsafe.Pointer manipulation.
62+
// We can't do that, so skip it. See https://github.com/golang/go/commit/484586c81a0196e42ac52f651bc56017ca454280.
63+
b.addr = b
64+
} else if b.addr != b {
65+
panic("strings: illegal use of non-zero Builder copied by value")
66+
}
67+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build js
2+
3+
package strings_test
4+
5+
import "testing"
6+
7+
func TestBuilderAllocs(t *testing.T) {
8+
t.Skip("runtime.ReadMemStats, testing.AllocsPerRun not supported in GopherJS")
9+
}

0 commit comments

Comments
 (0)