mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-22 19:53:00 -05:00
* kill unwrapped_remote (#1490) * kill unwrapped_remote * linting * don't use callKwargs for python plugins * fix tests and improve types * Bringing PyScript.next PoC to the main project * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Madhur Tandon <20173739+madhur-tandon@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
import { fetchPaths } from "./_utils.js";
|
|
|
|
const type = "ruby";
|
|
|
|
// MISSING:
|
|
// * there is no VFS apparently or I couldn't reach any
|
|
// * I've no idea how to override the stderr and stdout
|
|
// * I've no idea how to import packages
|
|
|
|
// REQUIRES INTEGRATION TEST
|
|
/* c8 ignore start */
|
|
const worker = (method) =>
|
|
function (runtime, code, xworker) {
|
|
globalThis.xworker = xworker;
|
|
return this[method](
|
|
runtime,
|
|
`require "js";xworker=JS::eval("return xworker");${code}`,
|
|
);
|
|
};
|
|
|
|
export default {
|
|
experimental: true,
|
|
type: [type, "rb"],
|
|
module: (version = "2.0.0") =>
|
|
`https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@${version}/dist/browser.esm.js`,
|
|
async engine({ DefaultRubyVM }, config, url) {
|
|
const response = await fetch(
|
|
`${url.slice(0, url.lastIndexOf("/"))}/ruby.wasm`,
|
|
);
|
|
const module = await WebAssembly.compile(await response.arrayBuffer());
|
|
const { vm: runtime } = await DefaultRubyVM(module);
|
|
if (config.fetch) await fetchPaths(this, runtime, config.fetch);
|
|
return runtime;
|
|
},
|
|
run: (runtime, code) => runtime.eval(code),
|
|
runAsync: (runtime, code) => runtime.evalAsync(code),
|
|
runEvent(runtime, code, key) {
|
|
return this.run(
|
|
runtime,
|
|
`require "js";event=JS::eval("return __events.get(${key})");${code}`,
|
|
);
|
|
},
|
|
runWorker: worker("run"),
|
|
runWorkerAsync: worker("runAsync"),
|
|
writeFile: () => {
|
|
throw new Error(`writeFile is not supported in ${type}`);
|
|
},
|
|
};
|
|
/* c8 ignore stop */
|