Skip to content

Commit c7683d9

Browse files
committed
compiler/natives/src/net: Implement missing private helpers.
This change makes net package compile, and allows crypto/x509 tests to pass. Fixes: $ gopherjs test --short crypto/x509 --- FAIL: TestMatchIP (0.00s) Error: runtime error: native function not implemented: net.bytesEqual
1 parent dd65c22 commit c7683d9

File tree

1 file changed

+28
-4
lines changed
  • compiler/natives/src/net

1 file changed

+28
-4
lines changed

compiler/natives/src/net/net.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import (
99
"github.com/gopherjs/gopherjs/js"
1010
)
1111

12-
func byteIndex(s string, c byte) int {
13-
return js.InternalObject(s).Call("indexOf", js.Global.Get("String").Call("fromCharCode", c)).Int()
14-
}
15-
1612
func Listen(net, laddr string) (Listener, error) {
1713
panic(errors.New("network access is not supported by GopherJS"))
1814
}
@@ -39,3 +35,31 @@ func probeWindowsIPStack() (supportsVistaIP bool) {
3935
func maxListenerBacklog() int {
4036
return syscall.SOMAXCONN
4137
}
38+
39+
// Copy of strings.IndexByte.
40+
func byteIndex(s string, c byte) int {
41+
return js.InternalObject(s).Call("indexOf", js.Global.Get("String").Call("fromCharCode", c)).Int()
42+
}
43+
44+
// Copy of bytes.Equal.
45+
func bytesEqual(x, y []byte) bool {
46+
if len(x) != len(y) {
47+
return false
48+
}
49+
for i, b := range x {
50+
if b != y[i] {
51+
return false
52+
}
53+
}
54+
return true
55+
}
56+
57+
// Copy of bytes.IndexByte.
58+
func bytesIndexByte(s []byte, c byte) int {
59+
for i, b := range s {
60+
if b == c {
61+
return i
62+
}
63+
}
64+
return -1
65+
}

0 commit comments

Comments
 (0)