-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14894d2
commit c68cb30
Showing
12 changed files
with
534 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
source: crates/cli-support/tests/tests.rs | ||
expression: output.js() | ||
--- | ||
let wasm; | ||
export function __wbg_set_wasm(val) { | ||
wasm = val; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
source: crates/cli-support/tests/tests.rs | ||
expression: output.js() | ||
--- | ||
const imports = { | ||
__wbindgen_placeholder__: { | ||
}, | ||
|
||
}; | ||
|
||
const wasm_url = new URL('add_bg.wasm', import.meta.url); | ||
let wasmCode = ''; | ||
switch (wasm_url.protocol) { | ||
case 'file:': | ||
wasmCode = await Deno.readFile(wasm_url); | ||
break | ||
case 'https:': | ||
case 'http:': | ||
wasmCode = await (await fetch(wasm_url)).arrayBuffer(); | ||
break | ||
default: | ||
throw new Error(`Unsupported protocol: ${wasm_url.protocol}`); | ||
} | ||
|
||
const wasmInstance = (await WebAssembly.instantiate(wasmCode, imports)).instance; | ||
const wasm = wasmInstance.exports; | ||
export const __wasm = wasm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
source: crates/cli-support/tests/tests.rs | ||
expression: output.js() | ||
--- | ||
let imports = {}; | ||
let wasm; | ||
|
||
const path = require('path').join(__dirname, 'add_bg.wasm'); | ||
const bytes = require('fs').readFileSync(path); | ||
|
||
const wasmModule = new WebAssembly.Module(bytes); | ||
const wasmInstance = new WebAssembly.Instance(wasmModule, imports); | ||
wasm = wasmInstance.exports; | ||
module.exports.__wasm = wasm; |
8 changes: 8 additions & 0 deletions
8
crates/cli-support/tests/snapshots/tests__node_module_bg.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
source: crates/cli-support/tests/tests.rs | ||
expression: output.js() | ||
--- | ||
let wasm; | ||
export function __wbg_set_wasm(val) { | ||
wasm = val; | ||
} |
20 changes: 20 additions & 0 deletions
20
crates/cli-support/tests/snapshots/tests__node_module_js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
source: crates/cli-support/tests/tests.rs | ||
expression: output.start().unwrap() | ||
--- | ||
let imports = {}; | ||
|
||
import * as path from 'node:path'; | ||
import * as fs from 'node:fs'; | ||
import * as process from 'node:process'; | ||
|
||
let file = path.dirname(new URL(import.meta.url).pathname); | ||
if (process.platform === 'win32') { | ||
file = file.substring(1); | ||
} | ||
const bytes = fs.readFileSync(path.join(file, 'add_bg.wasm')); | ||
|
||
const wasmModule = new WebAssembly.Module(bytes); | ||
const wasmInstance = new WebAssembly.Instance(wasmModule, imports); | ||
const wasm = wasmInstance.exports; | ||
export const __wasm = wasm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
source: crates/cli-support/tests/tests.rs | ||
expression: output.js() | ||
--- | ||
let imports = {}; | ||
let wasm; | ||
|
||
const path = require('path').join(__dirname, 'add_bg.wasm'); | ||
const bytes = require('fs').readFileSync(path); | ||
|
||
const wasmModule = new WebAssembly.Module(bytes); | ||
const wasmInstance = new WebAssembly.Instance(wasmModule, imports); | ||
wasm = wasmInstance.exports; | ||
module.exports.__wasm = wasm; |
8 changes: 8 additions & 0 deletions
8
crates/cli-support/tests/snapshots/tests__nodejs_module_js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
source: crates/cli-support/tests/tests.rs | ||
expression: output.js() | ||
--- | ||
let wasm; | ||
export function __wbg_set_wasm(val) { | ||
wasm = val; | ||
} |
20 changes: 20 additions & 0 deletions
20
crates/cli-support/tests/snapshots/tests__nodejs_module_start.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
source: crates/cli-support/tests/tests.rs | ||
expression: output.start().unwrap() | ||
--- | ||
let imports = {}; | ||
|
||
import * as path from 'node:path'; | ||
import * as fs from 'node:fs'; | ||
import * as process from 'node:process'; | ||
|
||
let file = path.dirname(new URL(import.meta.url).pathname); | ||
if (process.platform === 'win32') { | ||
file = file.substring(1); | ||
} | ||
const bytes = fs.readFileSync(path.join(file, 'add_bg.wasm')); | ||
|
||
const wasmModule = new WebAssembly.Module(bytes); | ||
const wasmInstance = new WebAssembly.Instance(wasmModule, imports); | ||
const wasm = wasmInstance.exports; | ||
export const __wasm = wasm; |
111 changes: 111 additions & 0 deletions
111
crates/cli-support/tests/snapshots/tests__nomodule_js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
--- | ||
source: crates/cli-support/tests/tests.rs | ||
expression: output.js() | ||
--- | ||
let wasm_bindgen; | ||
(function() { | ||
const __exports = {}; | ||
let script_src; | ||
if (typeof document !== 'undefined' && document.currentScript !== null) { | ||
script_src = new URL(document.currentScript.src, location.href).toString(); | ||
} | ||
let wasm = undefined; | ||
async function __wbg_load(module, imports) { | ||
if (typeof Response === 'function' && module instanceof Response) { | ||
if (typeof WebAssembly.instantiateStreaming === 'function') { | ||
try { | ||
return await WebAssembly.instantiateStreaming(module, imports); | ||
|
||
} catch (e) { | ||
if (module.headers.get('Content-Type') != 'application/wasm') { | ||
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); | ||
|
||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
const bytes = await module.arrayBuffer(); | ||
return await WebAssembly.instantiate(bytes, imports); | ||
|
||
} else { | ||
const instance = await WebAssembly.instantiate(module, imports); | ||
|
||
if (instance instanceof WebAssembly.Instance) { | ||
return { instance, module }; | ||
|
||
} else { | ||
return instance; | ||
} | ||
} | ||
} | ||
|
||
function __wbg_get_imports() { | ||
const imports = {}; | ||
imports.wbg = {}; | ||
|
||
return imports; | ||
} | ||
|
||
function __wbg_init_memory(imports, memory) { | ||
|
||
} | ||
|
||
function __wbg_finalize_init(instance, module) { | ||
wasm = instance.exports; | ||
__wbg_init.__wbindgen_wasm_module = module; | ||
|
||
|
||
|
||
return wasm; | ||
} | ||
|
||
function initSync(module) { | ||
if (wasm !== undefined) return wasm; | ||
|
||
|
||
if (typeof module !== 'undefined' && Object.getPrototypeOf(module) === Object.prototype) | ||
({module} = module) | ||
else | ||
console.warn('using deprecated parameters for `initSync()`; pass a single object instead') | ||
|
||
const imports = __wbg_get_imports(); | ||
|
||
__wbg_init_memory(imports); | ||
|
||
if (!(module instanceof WebAssembly.Module)) { | ||
module = new WebAssembly.Module(module); | ||
} | ||
|
||
const instance = new WebAssembly.Instance(module, imports); | ||
|
||
return __wbg_finalize_init(instance, module); | ||
} | ||
|
||
async function __wbg_init(module_or_path) { | ||
if (wasm !== undefined) return wasm; | ||
|
||
|
||
if (typeof module_or_path !== 'undefined' && Object.getPrototypeOf(module_or_path) === Object.prototype) | ||
({module_or_path} = module_or_path) | ||
else | ||
console.warn('using deprecated parameters for the initialization function; pass a single object instead') | ||
|
||
|
||
const imports = __wbg_get_imports(); | ||
|
||
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) { | ||
module_or_path = fetch(module_or_path); | ||
} | ||
|
||
__wbg_init_memory(imports); | ||
|
||
const { instance, module } = await __wbg_load(await module_or_path, imports); | ||
|
||
return __wbg_finalize_init(instance, module); | ||
} | ||
|
||
wasm_bindgen = Object.assign(__wbg_init, { initSync }, __exports); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
source: crates/cli-support/tests/tests.rs | ||
expression: output.js() | ||
--- | ||
let wasm; | ||
|
||
async function __wbg_load(module, imports) { | ||
if (typeof Response === 'function' && module instanceof Response) { | ||
if (typeof WebAssembly.instantiateStreaming === 'function') { | ||
try { | ||
return await WebAssembly.instantiateStreaming(module, imports); | ||
|
||
} catch (e) { | ||
if (module.headers.get('Content-Type') != 'application/wasm') { | ||
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); | ||
|
||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
const bytes = await module.arrayBuffer(); | ||
return await WebAssembly.instantiate(bytes, imports); | ||
|
||
} else { | ||
const instance = await WebAssembly.instantiate(module, imports); | ||
|
||
if (instance instanceof WebAssembly.Instance) { | ||
return { instance, module }; | ||
|
||
} else { | ||
return instance; | ||
} | ||
} | ||
} | ||
|
||
function __wbg_get_imports() { | ||
const imports = {}; | ||
imports.wbg = {}; | ||
|
||
return imports; | ||
} | ||
|
||
function __wbg_init_memory(imports, memory) { | ||
|
||
} | ||
|
||
function __wbg_finalize_init(instance, module) { | ||
wasm = instance.exports; | ||
__wbg_init.__wbindgen_wasm_module = module; | ||
|
||
|
||
|
||
return wasm; | ||
} | ||
|
||
function initSync(module) { | ||
if (wasm !== undefined) return wasm; | ||
|
||
|
||
if (typeof module !== 'undefined' && Object.getPrototypeOf(module) === Object.prototype) | ||
({module} = module) | ||
else | ||
console.warn('using deprecated parameters for `initSync()`; pass a single object instead') | ||
|
||
const imports = __wbg_get_imports(); | ||
|
||
__wbg_init_memory(imports); | ||
|
||
if (!(module instanceof WebAssembly.Module)) { | ||
module = new WebAssembly.Module(module); | ||
} | ||
|
||
const instance = new WebAssembly.Instance(module, imports); | ||
|
||
return __wbg_finalize_init(instance, module); | ||
} | ||
|
||
async function __wbg_init(module_or_path) { | ||
if (wasm !== undefined) return wasm; | ||
|
||
|
||
if (typeof module_or_path !== 'undefined' && Object.getPrototypeOf(module_or_path) === Object.prototype) | ||
({module_or_path} = module_or_path) | ||
else | ||
console.warn('using deprecated parameters for the initialization function; pass a single object instead') | ||
|
||
|
||
const imports = __wbg_get_imports(); | ||
|
||
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) { | ||
module_or_path = fetch(module_or_path); | ||
} | ||
|
||
__wbg_init_memory(imports); | ||
|
||
const { instance, module } = await __wbg_load(await module_or_path, imports); | ||
|
||
return __wbg_finalize_init(instance, module); | ||
} | ||
|
||
export { initSync }; | ||
export default __wbg_init; |
Oops, something went wrong.