Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Resolved conflicts by taking GitHub versions for: - .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml Kept deploy.sh updated to: - Pull from GitHub (primary source) - Push to Gitea (push-mirror) - Build from site/ directory (GitHub structure) Co-Authored-By: Paperclip <noreply@paperclip.ing>
40 lines
1.7 KiB
JavaScript
40 lines
1.7 KiB
JavaScript
import { wrapInstanceExports } from "./wasi/util.mjs";
|
|
import { _WebAssembly } from "./webassembly.mjs";
|
|
function checkWebAssemblyFunction() {
|
|
const WebAssemblyFunction = _WebAssembly.Function;
|
|
if (typeof WebAssemblyFunction !== 'function') {
|
|
throw new Error('WebAssembly.Function is not supported in this environment.' +
|
|
' If you are using V8 based browser like Chrome, try to specify' +
|
|
' --js-flags="--wasm-staging --experimental-wasm-stack-switching"');
|
|
}
|
|
return WebAssemblyFunction;
|
|
}
|
|
/** @public */
|
|
export function wrapAsyncImport(f, parameterType, returnType) {
|
|
const WebAssemblyFunction = checkWebAssemblyFunction();
|
|
if (typeof f !== 'function') {
|
|
throw new TypeError('Function required');
|
|
}
|
|
const parameters = parameterType.slice(0);
|
|
parameters.unshift('externref');
|
|
return new WebAssemblyFunction({ parameters, results: returnType }, f, { suspending: 'first' });
|
|
}
|
|
/** @public */
|
|
export function wrapAsyncExport(f) {
|
|
const WebAssemblyFunction = checkWebAssemblyFunction();
|
|
if (typeof f !== 'function') {
|
|
throw new TypeError('Function required');
|
|
}
|
|
return new WebAssemblyFunction({ parameters: [...WebAssemblyFunction.type(f).parameters.slice(1)], results: ['externref'] }, f, { promising: 'first' });
|
|
}
|
|
/** @public */
|
|
export function wrapExports(exports, needWrap) {
|
|
return wrapInstanceExports(exports, (exportValue, name) => {
|
|
let ignore = typeof exportValue !== 'function';
|
|
if (Array.isArray(needWrap)) {
|
|
ignore = ignore || (needWrap.indexOf(name) === -1);
|
|
}
|
|
return ignore ? exportValue : wrapAsyncExport(exportValue);
|
|
});
|
|
}
|