Skip to content

Commit 305cb64

Browse files
committed
Remove unnecessary package tweaks for crypto/rand.
We could remove our overlay entirely, but our implementation seems to be more advanced than the one of `js/wasm` in the standard library, so we keep it for now.
1 parent 7d56422 commit 305cb64

File tree

2 files changed

+2
-20
lines changed

2 files changed

+2
-20
lines changed

build/context.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,6 @@ func (sc simpleCtx) applyPostloadTweaks(pkg *build.Package) *build.Package {
253253
// GopherJS completely replaces sync.Pool implementation with a simpler one,
254254
// since it always executes in a single-threaded environment.
255255
pkg.GoFiles = exclude(pkg.GoFiles, "pool.go")
256-
case "crypto/rand":
257-
pkg.GoFiles = []string{"rand.go", "util.go"}
258256
case "syscall/js":
259257
// Reuse upstream tests to ensure conformance, but completely replace
260258
// implementation.

compiler/natives/src/crypto/rand/rand.go

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

12-
func init() {
13-
Reader = &rngReader{}
14-
}
15-
16-
type rngReader struct{}
12+
type reader struct{}
1713

18-
func (r *rngReader) Read(b []byte) (n int, err error) {
14+
func (r *reader) Read(b []byte) (n int, err error) {
1915
array := js.InternalObject(b).Get("$array")
2016
offset := js.InternalObject(b).Get("$offset").Int()
2117

@@ -48,15 +44,3 @@ func (r *rngReader) Read(b []byte) (n int, err error) {
4844

4945
return 0, errors.New("crypto/rand not available in this environment")
5046
}
51-
52-
func batched(f func([]byte) bool, readMax int) func([]byte) bool {
53-
return func(buf []byte) bool {
54-
for len(buf) > readMax {
55-
if !f(buf[:readMax]) {
56-
return false
57-
}
58-
buf = buf[readMax:]
59-
}
60-
return len(buf) == 0 || f(buf)
61-
}
62-
}

0 commit comments

Comments
 (0)