From fc58c88ab5f856a302996effed074de1ff0e11b6 Mon Sep 17 00:00:00 2001 From: Marcus Ramse Date: Tue, 3 Dec 2024 20:12:03 +0000 Subject: [PATCH] web: safely handle immutable globals (#779) --- runtimes/web/src/netplay/index.ts | 4 ++-- runtimes/web/src/state.ts | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/runtimes/web/src/netplay/index.ts b/runtimes/web/src/netplay/index.ts index bf7b45bb..a619bdd6 100644 --- a/runtimes/web/src/netplay/index.ts +++ b/runtimes/web/src/netplay/index.ts @@ -252,10 +252,10 @@ export class Netplay { const localPeerId = await this.peerMgr.localPeerId; const loc = window.location; - if (loc.protocol == "file:" + if (!DEV_NETPLAY && (loc.protocol == "file:" || loc.hostname == "localhost" || loc.hostname == "127.0.0.1" - || loc.hostname == "wasm4.org") { + || loc.hostname == "wasm4.org")) { return `https://wasm4.org/netplay/#${localPeerId}`; } const url = new URL(loc.href); diff --git a/runtimes/web/src/state.ts b/runtimes/web/src/state.ts index 91bfd96d..656ee1b9 100644 --- a/runtimes/web/src/state.ts +++ b/runtimes/web/src/state.ts @@ -38,7 +38,10 @@ export class State { for (const exName in runtime.wasm!.exports) { const exInst = runtime.wasm!.exports[exName] if (exInst instanceof WebAssembly.Global && exName in this.globals) { - exInst.value = this.globals[exName]; + try { + // this will fail for immutable globals that have been exported, but is safe + exInst.value = this.globals[exName]; + } catch {} } }