feat(wasm): use zig-js's exact JS interop ABI
Ghostty's wasm code talks to JavaScript through the zig-js library (mitchellh/zig-js, pinned in build.zig.zon). The first port invented its own import ABI because the dependency wasn't available; now: - ghostty-os/src/wasm/js.rs is a Rust port of zig-js's Zig side (Ref, Value, Object get/set/call/new, global, runtime, string) using its "zig-js" import module, function names and NaN-boxed value refs. - web_canvas face and the atlas debug canvas make the same JS calls as Ghostty's Zig code. - zig-js's unmodified JS host (+ LICENSE) is vendored under crates/ghostty-wasm/js/zig-js and drives the node test. Test Plan: - cargo test -p ghostty-wasm (node >= 24; asserts zig-js imports and no leaked host values)
This commit is contained in:
1 parent
28f55ff2dd
commit
a07b224869
16 files changed
+1532
-479
No files matched your search
@@ -1,14 +1,32 @@
|
||||
//! Builds the wasm module and runs `tests/node_test.js` against it with
|
||||
//! node, using stub JS imports (a fake canvas measuring API). Skipped when
|
||||
//! node, with zig-js's own JS host and a fake `document`/canvas. Skipped when
|
||||
//! node or the `wasm32-unknown-unknown` target is not available.
|
||||
|
||||
use std::{path::PathBuf, process::Command};
|
||||
|
||||
#[test]
|
||||
fn wasm_module_runs_under_node() {
|
||||
if Command::new("node").arg("--version").output().is_err() {
|
||||
// zig-js's host is TypeScript; node must be able to strip types (>= 23.6).
|
||||
let Some(major) = Command::new("node")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|o| {
|
||||
String::from_utf8_lossy(&o.stdout)
|
||||
.trim()
|
||||
.trim_start_matches('v')
|
||||
.split('.')
|
||||
.next()?
|
||||
.parse::<u32>()
|
||||
.ok()
|
||||
})
|
||||
else {
|
||||
eprintln!("skipping: node not found");
|
||||
return;
|
||||
};
|
||||
if major < 24 {
|
||||
eprintln!("skipping: node {major} cannot load the zig-js TypeScript host");
|
||||
return;
|
||||
}
|
||||
|
||||
let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
|
||||
Reference in new issue
Block a user