Skip to content

Commit

Permalink
web: safely handle immutable globals (aduros#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
JerwuQu committed Dec 3, 2024
1 parent 7e92c5e commit fc58c88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions runtimes/web/src/netplay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion runtimes/web/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
}

Expand Down

0 comments on commit fc58c88

Please sign in to comment.