Skip to content

Commit

Permalink
Fix e2e test against 5.5 toolchain
Browse files Browse the repository at this point in the history
It accesses clock_res_get at __CFDateInitialize constructor
  • Loading branch information
kateinoigakukun committed Apr 6, 2022
1 parent b04ab42 commit 1dd22ce
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions Fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import { WASI } from "@wasmer/wasi";
import { WasmFs } from "@wasmer/wasmfs";

const wrapWASI = (wasiObject) => {
for (const key in wasiObject.wasiImport) {
const func = wasiObject.wasiImport[key]
wasiObject.wasiImport[key] = function() {
console.log(`[tracing] WASI.${key}`);
return Reflect.apply(func, undefined, arguments);
}
}
// PATCH: @wasmer-js/[email protected] forgets to call `refreshMemory` in `clock_res_get`,
// which writes its result to memory view. Without the refresh the memory view,
// it accesses a detached array buffer if the memory is grown by malloc.
// But they wasmer team discarded the 0.x codebase at all and replaced it with
// a new implementation written in Rust. The new version 1.x is really unstable
// and not production-ready as far as katei investigated in Apr 2022.
// So override the broken implementation of `clock_res_get` here instead of
// fixing the wasi polyfill.
// Reference: https://github.com/wasmerio/wasmer-js/blob/55fa8c17c56348c312a8bd23c69054b1aa633891/packages/wasi/src/index.ts#L557
const original_clock_res_get = wasiObject.wasiImport["clock_res_get"];
wasiObject.wasiImport["clock_res_get"] = (clockId, resolution) => {
wasiObject.refreshMemory();
return original_clock_res_get(clockId, resolution)
};
return wasiObject.wasiImport;
}

window.I64ImportTransformerTests = async (bytes) => {
const wasmFs = new WasmFs();
const wasi = new WASI({
Expand All @@ -12,7 +37,7 @@ window.I64ImportTransformerTests = async (bytes) => {
});

const importObject = {
wasi_snapshot_preview1: wasi.wasiImport,
wasi_snapshot_preview1: wrapWASI(wasi),
};

const module = await WebAssembly.compile(bytes);
Expand All @@ -31,7 +56,7 @@ window.StackOverflowSanitizerTests = async (bytes) => {
});

const importObject = {
wasi_snapshot_preview1: wasi.wasiImport,
wasi_snapshot_preview1: wrapWASI(wasi),
__stack_sanitizer: {
report_stack_overflow: () => {
throw new Error("CATCH_STACK_OVERFLOW");
Expand Down

0 comments on commit 1dd22ce

Please sign in to comment.