From 21d93ddbbb6dc78ff97632a8bc77c0a3b8186c41 Mon Sep 17 00:00:00 2001 From: Nicolas Lepage <19571875+nlepage@users.noreply.github.com> Date: Sun, 14 Jun 2020 15:34:58 +0200 Subject: [PATCH] :recycle: --- index.js | 4 ++-- sw.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 03b9362..5b378b6 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ window.wasmhttp = { - register: async (wasm, { scope, base = '', swUrl = 'sw.js', argv = [] } = {}) => { + register: async (wasm, { scope, base = '', swUrl = 'sw.js', args = [] } = {}) => { const options = {} if (scope) options.scope = scope //FIXME register once (beware of changing scope ?) @@ -9,7 +9,7 @@ window.wasmhttp = { type: 'wasmhttp.register', wasm, base, - argv, + args, }) } } diff --git a/sw.js b/sw.js index 2c8aa3e..9e3891e 100644 --- a/sw.js +++ b/sw.js @@ -1,13 +1,13 @@ importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.14.3/misc/wasm/wasm_exec.js') // FIXME use an options object with { env, argv } -const startWasm = async (wasm, WASMHTTP_HANDLER_ID, WASMHTTP_PATH, argv) => { +const startWasm = async (wasm, WASMHTTP_HANDLER_ID, WASMHTTP_PATH, args) => { const go = new Go() go.env = { WASMHTTP_HANDLER_ID, WASMHTTP_PATH, } - go.argv = argv + go.argv = [wasm, ...args] const { instance } = await WebAssembly.instantiateStreaming(fetch(wasm), go.importObject) return go.run(instance) } @@ -52,7 +52,7 @@ addEventListener('message', async ({ data }) => { if (data.type !== 'wasmhttp.register') return - const { wasm, base, argv } = data + const { wasm, base, args } = data let path = new URL(registration.scope).pathname if (base && base !== '') path = `${trimEnd(path, '/')}/${trimStart(base, '/')}` @@ -63,7 +63,7 @@ addEventListener('message', async ({ data }) => { const handlerId = `${nextHandlerId++}` const handler = new Promise(resolve => handlerResolvers[handlerId] = resolve) - startWasm(wasm, handlerId, path, argv) + startWasm(wasm, handlerId, path, args) running.add(key) // FIXME try catch