Skip to content

Commit

Permalink
Extend default fiber stack size tentatively
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed May 21, 2023
1 parent fb12843 commit 394841d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
10 changes: 9 additions & 1 deletion packages/npm-packages/ruby-wasm-wasi/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ export const DefaultRubyVM = async (
}> => {
await init();

const wasi = new WASI({});
const wasi = new WASI({
env: {
// FIXME(katei): setjmp consumes a LOT of stack now, so we extend
// default Fiber stack size as well as main stack size allocated
// by wasm-ld's --stack-size. The ideal solution is to reduce
// stack consumption in setjmp.
"RUBY_FIBER_MACHINE_STACK_SIZE": "16777216"
}
});
const vm = new RubyVM();

const imports = wasi.getImports(rubyModule) as WebAssembly.Imports;
Expand Down
10 changes: 9 additions & 1 deletion packages/npm-packages/ruby-wasm-wasi/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { WASI } from "wasi";
import { RubyVM } from "./index";

export const DefaultRubyVM = async (rubyModule: WebAssembly.Module) => {
const wasi = new WASI();
const wasi = new WASI({
env: {
// FIXME(katei): setjmp consumes a LOT of stack now, so we extend
// default Fiber stack size as well as main stack size allocated
// by wasm-ld's --stack-size. The ideal solution is to reduce
// stack consumption in setjmp.
"RUBY_FIBER_MACHINE_STACK_SIZE": "16777216"
}
});
const vm = new RubyVM();
const imports = {
wasi_snapshot_preview1: wasi.wasiImport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,31 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
setupProxy(context);
})

const resolveBinding = async (page: Page, name: string) => {
let checkResolved;
const resolvedValue = new Promise((resolve) => {
checkResolved = resolve;
})
await page.exposeBinding(name, async (source, v) => {
checkResolved(v);
});
return async () => await resolvedValue
}

test.describe('data-eval="async"', () => {
test("JS::Object#await returns value", async ({ page, context }) => {
let checkResolved;
const resolvedValue = new Promise((resolve) => {
checkResolved = resolve;
})
await page.exposeBinding('checkResolved', async (source, v) => {
checkResolved(v);
});
test("JS::Object#await returns value", async ({ page }) => {
const resolve = await resolveBinding(page, "checkResolved");
await page.setContent(`
<script src="https://cdn.jsdelivr.net/npm/ruby-head-wasm-wasi@latest/dist/browser.script.iife.js"></script>
<script type="text/ruby" data-eval="async">
require "js"
JS.global.checkResolved JS.global[:Promise].resolve(42).await
</script>
`)
expect(await resolvedValue).toBe(42);
expect(await resolve()).toBe(42);
})

test("JS::Object#await throws error on default attr", async ({ page, context }) => {
test("JS::Object#await throws error on default attr", async ({ page }) => {
await page.setContent(`
<script src="https://cdn.jsdelivr.net/npm/ruby-head-wasm-wasi@latest/dist/browser.script.iife.js"></script>
<script type="text/ruby">
Expand All @@ -40,5 +45,17 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
const error = await page.waitForEvent("pageerror")
expect(error.message).toMatch(/please ensure that you specify `data-eval="async"`/)
})

test("default stack size is enough to require 'json'", async ({ page }) => {
const resolve = await resolveBinding(page, "checkResolved");
await page.setContent(`
<script src="https://cdn.jsdelivr.net/npm/ruby-head-wasm-wasi@latest/dist/browser.script.iife.js"></script>
<script type="text/ruby" data-eval="async">
require 'json'
JS.global.checkResolved "ok"
</script>
`)
expect(await resolve()).toBe("ok");
})
})
}

0 comments on commit 394841d

Please sign in to comment.