From 7fa93ee7b50fb83c4df5c9032d367477afffa0d7 Mon Sep 17 00:00:00 2001
From: bjorn3 <17426603+bjorn3@users.noreply.github.com>
Date: Sat, 23 Dec 2023 15:34:57 +0100
Subject: [PATCH 01/19] Use Map instead of Object in Directory
This avoids issues when the wasm module uses names conflicting with
builtin javascript properties.
---
examples/rustc.html | 44 +++++++++++------------
src/fs_core.ts | 56 +++++++++++++++++------------
test/adapters/browser/run-test.html | 8 ++---
test/adapters/browser/run-wasi.mjs | 6 ++--
test/adapters/node/run-wasi.mjs | 5 +--
test/adapters/shared/walkFs.mjs | 6 ++--
6 files changed, 69 insertions(+), 56 deletions(-)
diff --git a/examples/rustc.html b/examples/rustc.html
index e760820..b6cfe1f 100644
--- a/examples/rustc.html
+++ b/examples/rustc.html
@@ -75,16 +75,16 @@
new XtermStdio(term),
new XtermStdio(term),
new XtermStdio(term),
- new PreopenDirectory("/tmp", {}),
- new PreopenDirectory("/sysroot", {
- "lib": new Directory({
- "rustlib": new Directory({
- "wasm32-wasi": new Directory({
- "lib": new Directory({}),
- }),
- "x86_64-unknown-linux-gnu": new Directory({
- "lib": new Directory(await (async function () {
- let dir = {};
+ new PreopenDirectory("/tmp", []),
+ new PreopenDirectory("/sysroot", [
+ ["lib", new Directory([
+ ["rustlib", new Directory([
+ ["wasm32-wasi", new Directory([
+ ["lib", new Directory([])],
+ ])],
+ ["x86_64-unknown-linux-gnu", new Directory([
+ ["lib", new Directory(await (async function () {
+ let dir = new Map();
for (let file of [
"libaddr2line-3368a2ecf632bfc6.rlib",
"libadler-16845f650eeea12c.rlib",
@@ -115,17 +115,17 @@
"libunicode_width-d55ce9c674fbd422.rlib",
"libunwind-8ca3e01a84805f9e.rlib"
]) {
- dir[file] = await load_external_file("/examples/wasm-rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/" + file);
+ dir.set(file, await load_external_file("/examples/wasm-rustc/lib/rustlib/x86_64-unknown-linux-gnu/lib/" + file));
}
return dir;
- })()),
- }),
- }),
- }),
- }),
- new PreopenDirectory("/", {
- "hello.rs": new File(new TextEncoder("utf-8").encode(`fn main() { println!("Hello World!"); }`)),
- }),
+ })())],
+ ])],
+ ])],
+ ])],
+ ]),
+ new PreopenDirectory("/", [
+ ["hello.rs", new File(new TextEncoder("utf-8").encode(`fn main() { println!("Hello World!"); }`))],
+ ]),
];
let w = new WASI(args, env, fds, { debug: true });
@@ -140,9 +140,9 @@
console.log(fds);
console.log(fds[5].dir);
- console.log(fds[5].dir.contents["hello.hello.2490b9cce2492134-cgu.0.rcgu.o"].data);
- document.querySelector("#downloads").innerHTML += "
Download object";
- document.querySelector("#downloads").innerHTML += "
Download allocator shim";
+ console.log(fds[5].dir.contents.get("hello.hello.2490b9cce2492134-cgu.0.rcgu.o").data);
+ document.querySelector("#downloads").innerHTML += "
Download object";
+ document.querySelector("#downloads").innerHTML += "
Download allocator shim";
})();