diff options
| author | Richard Musiol <mail@richard-musiol.de> | 2019-10-26 21:01:32 +0200 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2019-11-04 22:50:43 +0000 |
| commit | 54e6ba6724dfde355070238f9abc16362cac2e3d (patch) | |
| tree | 545a12103881cfa87f536865a8cf0bfd9e85b731 /src/net/http | |
| parent | 063d0f11e535edf61d1e0b4ba16cfeae0f312bcf (diff) | |
| download | go-54e6ba6724dfde355070238f9abc16362cac2e3d.tar.xz | |
syscall/js: garbage collect references to JavaScript values
The js.Value struct now contains a pointer, so a finalizer can
determine if the value is not referenced by Go any more.
Unfortunately this breaks Go's == operator with js.Value. This change
adds a new Equal method to check for the equality of two Values.
This is a breaking change. The == operator is now disallowed to
not silently break code.
Additionally the helper methods IsUndefined, IsNull and IsNaN got added.
Fixes #35111
Change-Id: I58a50ca18f477bf51a259c668a8ba15bfa76c955
Reviewed-on: https://go-review.googlesource.com/c/go/+/203600
Run-TryBot: Richard Musiol <neelance@gmail.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http')
| -rw-r--r-- | src/net/http/roundtrip_js.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/net/http/roundtrip_js.go b/src/net/http/roundtrip_js.go index 6331351a83..4dd99651a7 100644 --- a/src/net/http/roundtrip_js.go +++ b/src/net/http/roundtrip_js.go @@ -41,7 +41,7 @@ const jsFetchCreds = "js.fetch:credentials" // Reference: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters const jsFetchRedirect = "js.fetch:redirect" -var useFakeNetwork = js.Global().Get("fetch") == js.Undefined() +var useFakeNetwork = js.Global().Get("fetch").IsUndefined() // RoundTrip implements the RoundTripper interface using the WHATWG Fetch API. func (t *Transport) RoundTrip(req *Request) (*Response, error) { @@ -50,7 +50,7 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) { } ac := js.Global().Get("AbortController") - if ac != js.Undefined() { + if !ac.IsUndefined() { // Some browsers that support WASM don't necessarily support // the AbortController. See // https://developer.mozilla.org/en-US/docs/Web/API/AbortController#Browser_compatibility. @@ -74,7 +74,7 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) { opt.Set("redirect", h) req.Header.Del(jsFetchRedirect) } - if ac != js.Undefined() { + if !ac.IsUndefined() { opt.Set("signal", ac.Get("signal")) } headers := js.Global().Get("Headers").New() @@ -132,7 +132,7 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) { var body io.ReadCloser // The body is undefined when the browser does not support streaming response bodies (Firefox), // and null in certain error cases, i.e. when the request is blocked because of CORS settings. - if b != js.Undefined() && b != js.Null() { + if !b.IsUndefined() && !b.IsNull() { body = &streamReader{stream: b.Call("getReader")} } else { // Fall back to using ArrayBuffer @@ -168,7 +168,7 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) { respPromise.Call("then", success, failure) select { case <-req.Context().Done(): - if ac != js.Undefined() { + if !ac.IsUndefined() { // Abort the Fetch request ac.Call("abort") } |
