diff --git a/cloudflare/cache/client.go b/cloudflare/cache/client.go index fb3b9b5..a370732 100644 --- a/cloudflare/cache/client.go +++ b/cloudflare/cache/client.go @@ -6,7 +6,7 @@ import ( "github.com/syumai/workers/internal/jsutil" ) -var cache = jsutil.Global.Get("caches") +var cache = js.Global().Get("caches") // Cache type Cache struct { diff --git a/cloudflare/cron/cron.go b/cloudflare/cron/cron.go index a3cd47b..fb97360 100644 --- a/cloudflare/cron/cron.go +++ b/cloudflare/cron/cron.go @@ -37,7 +37,7 @@ var scheduledTask Task // ScheduleTask sets the Task to be executed func ScheduleTask(task Task) { scheduledTask = task - jsutil.Global.Call("ready") + js.Global().Call("ready") select {} } @@ -78,5 +78,5 @@ func init() { return jsutil.NewPromise(cb) }) - jsutil.Global.Set("runScheduler", runSchedulerCallback) + js.Global().Set("runScheduler", runSchedulerCallback) } diff --git a/cloudflare/fetch/client.go b/cloudflare/fetch/client.go index 6040fab..851758e 100644 --- a/cloudflare/fetch/client.go +++ b/cloudflare/fetch/client.go @@ -3,8 +3,6 @@ package fetch import ( "net/http" "syscall/js" - - "github.com/syumai/workers/internal/jsutil" ) // Client is an HTTP client. @@ -44,7 +42,7 @@ func WithBinding(bind js.Value) ClientOption { // NewClient returns new Client func NewClient(opts ...ClientOption) *Client { c := &Client{ - namespace: jsutil.Global, + namespace: js.Global(), } c.applyOptions(opts) diff --git a/cloudflare/kv.go b/cloudflare/kv.go index 9cb6665..f5c830e 100644 --- a/cloudflare/kv.go +++ b/cloudflare/kv.go @@ -7,7 +7,6 @@ import ( "syscall/js" "github.com/syumai/workers/cloudflare/internal/cfruntimecontext" - "github.com/syumai/workers/internal/jsutil" ) @@ -67,7 +66,7 @@ func (kv *KVNamespace) GetReader(key string, opts *KVNamespaceGetOptions) (io.Re if err != nil { return nil, err } - jsutil.Global.Get("console").Call("log", v) + js.Global().Get("console").Call("log", v) return jsutil.ConvertStreamReaderToReader(v.Call("getReader")), nil } diff --git a/handler.go b/handler.go index 4fc296e..313ba47 100644 --- a/handler.go +++ b/handler.go @@ -40,7 +40,7 @@ func init() { }) return jsutil.NewPromise(cb) }) - jsutil.Global.Set("handleRequest", handleRequestCallback) + js.Global().Set("handleRequest", handleRequestCallback) } // handleRequest accepts a Request object and returns Response object. @@ -78,6 +78,6 @@ func Serve(handler http.Handler) { handler = http.DefaultServeMux } httpHandler = handler - jsutil.Global.Call("ready") + js.Global().Call("ready") select {} } diff --git a/internal/jsutil/jsutil.go b/internal/jsutil/jsutil.go index ef315b3..0e2f331 100644 --- a/internal/jsutil/jsutil.go +++ b/internal/jsutil/jsutil.go @@ -7,17 +7,16 @@ import ( ) var ( - Global = js.Global() - ObjectClass = Global.Get("Object") - PromiseClass = Global.Get("Promise") - RequestClass = Global.Get("Request") - ResponseClass = Global.Get("Response") - HeadersClass = Global.Get("Headers") - ArrayClass = Global.Get("Array") - Uint8ArrayClass = Global.Get("Uint8Array") - ErrorClass = Global.Get("Error") - ReadableStreamClass = Global.Get("ReadableStream") - DateClass = Global.Get("Date") + ObjectClass = js.Global().Get("Object") + PromiseClass = js.Global().Get("Promise") + RequestClass = js.Global().Get("Request") + ResponseClass = js.Global().Get("Response") + HeadersClass = js.Global().Get("Headers") + ArrayClass = js.Global().Get("Array") + Uint8ArrayClass = js.Global().Get("Uint8Array") + ErrorClass = js.Global().Get("Error") + ReadableStreamClass = js.Global().Get("ReadableStream") + DateClass = js.Global().Get("Date") Null = js.ValueOf(nil) )