Skip to content

Commit

Permalink
Merge pull request #780 from JerwuQu/779_global-write-bug
Browse files Browse the repository at this point in the history
 web: safely handle immutable globals #779
  • Loading branch information
aduros authored Dec 5, 2024
2 parents 7e92c5e + fc58c88 commit 4aec246
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 4aec246

Please sign in to comment.