Summary
perry compile --target web produces a WASM module that imports rt.date_get_day whenever Date.prototype.getDay() is reachable in the program. But wasm_runtime.js doesn't define date_get_day — only date_get_date, date_get_hours, date_get_minutes, etc. Instantiation fails:
LinkError: WebAssembly.instantiate(): Import #127 "rt" "date_get_day": function import requires a callable
Environment
- Perry: 0.5.1006
- Target: web (
--target web)
- macOS 26.4 (Darwin 25.4.0)
- Reproduced compiling
@honeide/editor (https://github.com/HoneIDE/editor); Date.prototype.getDay() is reached transitively through the editor's diff engine date stamps.
Repro
Any TS program that calls Date.prototype.getDay() and compiles cleanly today on macOS/iOS will fail to instantiate on web. Minimal:
// entry.ts
const d = new Date();
console.log(d.getDay());
perry compile entry.ts --target web --output out.html
open out.html
# DevTools console:
# Boot error: LinkError: WebAssembly.instantiate(): Import #N "rt" "date_get_day": function import requires a callable
Root cause
crates/perry-codegen-wasm/src/wasm_runtime.js defines (around line 884):
date_get_full_year: (h) => { const d = getHandle(h); return d instanceof Date ? d.getFullYear() : 0; },
date_get_month: (h) => { const d = getHandle(h); return d instanceof Date ? d.getMonth() : 0; },
date_get_date: (h) => { const d = getHandle(h); return d instanceof Date ? d.getDate() : 0; },
date_get_hours: (h) => { const d = getHandle(h); return d instanceof Date ? d.getHours() : 0; },
date_get_minutes: (h) => { const d = getHandle(h); return d instanceof Date ? d.getMinutes() : 0; },
date_get_seconds: (h) => { const d = getHandle(h); return d instanceof Date ? d.getSeconds() : 0; },
date_get_milliseconds: (h) => { const d = getHandle(h); return d instanceof Date ? d.getMilliseconds() : 0; },
No date_get_day, no UTC variants (date_get_utc_day, date_get_utc_hours, ...), no date_get_timezone_offset. The JS-target runtime at crates/perry-codegen-js/src/web_runtime.js (line 1918+) has the same gap. So any time codegen emits an rt.date_get_day import, link fails.
Suggested fix
Add the missing entries to both wasm_runtime.js and web_runtime.js:
date_get_day: (h) => { const d = getHandle(h); return d instanceof Date ? d.getDay() : 0; },
date_get_utc_full_year: (h) => { const d = getHandle(h); return d instanceof Date ? d.getUTCFullYear() : 0; },
date_get_utc_month: (h) => { const d = getHandle(h); return d instanceof Date ? d.getUTCMonth() : 0; },
date_get_utc_date: (h) => { const d = getHandle(h); return d instanceof Date ? d.getUTCDate() : 0; },
date_get_utc_day: (h) => { const d = getHandle(h); return d instanceof Date ? d.getUTCDay() : 0; },
date_get_utc_hours: (h) => { const d = getHandle(h); return d instanceof Date ? d.getUTCHours() : 0; },
date_get_utc_minutes: (h) => { const d = getHandle(h); return d instanceof Date ? d.getUTCMinutes() : 0; },
date_get_utc_seconds: (h) => { const d = getHandle(h); return d instanceof Date ? d.getUTCSeconds() : 0; },
date_get_utc_milliseconds: (h) => { const d = getHandle(h); return d instanceof Date ? d.getUTCMilliseconds() : 0; },
date_get_timezone_offset: (h) => { const d = getHandle(h); return d instanceof Date ? d.getTimezoneOffset() : 0; },
Worth also auditing the full Date.prototype surface against codegen import emit to make sure no other methods are similarly orphaned (setX, toLocaleString, etc.).
Workaround
Hook WebAssembly.instantiate from the host page to inject the missing rt.* entries before the module is instantiated. See https://github.com/HoneIDE/editor/blob/main/examples/web/build.ts for a concrete example.
Summary
perry compile --target webproduces a WASM module that importsrt.date_get_daywheneverDate.prototype.getDay()is reachable in the program. Butwasm_runtime.jsdoesn't definedate_get_day— onlydate_get_date,date_get_hours,date_get_minutes, etc. Instantiation fails:Environment
--target web)@honeide/editor(https://github.com/HoneIDE/editor);Date.prototype.getDay()is reached transitively through the editor's diff engine date stamps.Repro
Any TS program that calls
Date.prototype.getDay()and compiles cleanly today on macOS/iOS will fail to instantiate on web. Minimal:Root cause
crates/perry-codegen-wasm/src/wasm_runtime.jsdefines (around line 884):No
date_get_day, no UTC variants (date_get_utc_day,date_get_utc_hours, ...), nodate_get_timezone_offset. The JS-target runtime atcrates/perry-codegen-js/src/web_runtime.js(line 1918+) has the same gap. So any time codegen emits anrt.date_get_dayimport, link fails.Suggested fix
Add the missing entries to both
wasm_runtime.jsandweb_runtime.js:Worth also auditing the full
Date.prototypesurface against codegen import emit to make sure no other methods are similarly orphaned (setX,toLocaleString, etc.).Workaround
Hook
WebAssembly.instantiatefrom the host page to inject the missingrt.*entries before the module is instantiated. See https://github.com/HoneIDE/editor/blob/main/examples/web/build.ts for a concrete example.