Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: safely handle immutable globals #779 #780

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading