R: fix illegal invocation error

This commit is contained in:
aki-0421 2024-01-23 12:53:32 +09:00
parent 83be8bc604
commit 86f9f1cf26
No known key found for this signature in database
GPG Key ID: 64A8CF6D437D166A

View File

@ -15,7 +15,8 @@ func fetch(namespace js.Value, req *http.Request, init *RequestInit) (*http.Resp
if namespace.IsUndefined() {
return nil, errors.New("fetch function not found")
}
promise := namespace.Call("fetch",
fetchObj := namespace.Get("fetch")
promise := fetchObj.Invoke(
// The Request object to fetch.
// Docs: https://developers.cloudflare.com/workers/runtime-apis/request
jshttp.ToJSRequest(req),
@ -23,9 +24,11 @@ func fetch(namespace js.Value, req *http.Request, init *RequestInit) (*http.Resp
// Docs: https://developers.cloudflare.com/workers/runtime-apis/request#requestinit
init.ToJS(),
)
jsRes, err := jsutil.AwaitPromise(promise)
if err != nil {
return nil, err
}
return jshttp.ToResponse(jsRes)
}