mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-01 18:01:06 +00:00
Merge pull request #1384 from rustwasm/cloudflare-workers
feat(js): add check to no_modules gen js for cloudflare workers
This commit is contained in:
commit
1a7b3d56bd
@ -860,13 +860,7 @@ impl<'a> Context<'a> {
|
|||||||
function init(module_or_path, maybe_memory) {{
|
function init(module_or_path, maybe_memory) {{
|
||||||
let result;
|
let result;
|
||||||
const imports = {{ './{module}': __exports }};
|
const imports = {{ './{module}': __exports }};
|
||||||
if (module_or_path instanceof WebAssembly.Module) {{
|
if (module_or_path instanceof URL || typeof module_or_path === 'string' || module_or_path instanceof Request) {{
|
||||||
{init_memory1}
|
|
||||||
result = WebAssembly.instantiate(module_or_path, imports)
|
|
||||||
.then(instance => {{
|
|
||||||
return {{ instance, module: module_or_path }};
|
|
||||||
}});
|
|
||||||
}} else {{
|
|
||||||
{init_memory2}
|
{init_memory2}
|
||||||
const response = fetch(module_or_path);
|
const response = fetch(module_or_path);
|
||||||
if (typeof WebAssembly.instantiateStreaming === 'function') {{
|
if (typeof WebAssembly.instantiateStreaming === 'function') {{
|
||||||
@ -886,6 +880,12 @@ impl<'a> Context<'a> {
|
|||||||
.then(r => r.arrayBuffer())
|
.then(r => r.arrayBuffer())
|
||||||
.then(bytes => WebAssembly.instantiate(bytes, imports));
|
.then(bytes => WebAssembly.instantiate(bytes, imports));
|
||||||
}}
|
}}
|
||||||
|
}} else {{
|
||||||
|
{init_memory1}
|
||||||
|
result = WebAssembly.instantiate(module_or_path, imports)
|
||||||
|
.then(instance => {{
|
||||||
|
return {{ instance, module: module_or_path }};
|
||||||
|
}});
|
||||||
}}
|
}}
|
||||||
return result.then(({{instance, module}}) => {{
|
return result.then(({{instance, module}}) => {{
|
||||||
wasm = instance.exports;
|
wasm = instance.exports;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user