From 8317257159f633bb8e64f4ad53303e3fcfca32de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=20=E5=A5=88=E6=9C=88?= <43605695+akinazuki@users.noreply.github.com> Date: Sun, 1 Mar 2026 15:01:40 +0900 Subject: [PATCH] fix: use Call instead of Get+Invoke for fetch to preserve this binding Using namespace.Get("fetch").Invoke(...) detaches the method from its object, causing "Illegal invocation: function called with incorrect `this` reference" when used with Cloudflare Service Bindings. Replace with namespace.Call("fetch", ...), which is equivalent to namespace.fetch(...) in JavaScript and preserves the correct `this` reference. This aligns with the existing pattern used in dostub.go. --- cloudflare/fetch/bind.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cloudflare/fetch/bind.go b/cloudflare/fetch/bind.go index 286c8b6d..5009b80f 100644 --- a/cloudflare/fetch/bind.go +++ b/cloudflare/fetch/bind.go @@ -15,8 +15,7 @@ func fetch(namespace js.Value, req *http.Request, init *RequestInit) (*http.Resp if namespace.IsUndefined() { return nil, errors.New("fetch function not found") } - fetchFunc := namespace.Get("fetch") - promise := fetchFunc.Invoke( + promise := namespace.Call("fetch", // The Request object to fetch. // Docs: https://developers.cloudflare.com/workers/runtime-apis/request jshttp.ToJSRequest(req),