mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-11 08:36:16 +00:00
Catch emulation errors
This commit is contained in:
@@ -80,6 +80,7 @@ export class Emulator {
|
||||
/*new URL('./emulator-worker.js', import.meta.url)*/ "./emulator-worker.js",
|
||||
);
|
||||
|
||||
this.worker.onerror = this._onError.bind(this);
|
||||
this.worker.onmessage = this._onMessage.bind(this);
|
||||
}
|
||||
|
||||
@@ -152,6 +153,20 @@ export class Emulator {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
logError(message: string) {
|
||||
this.logHandler([`<span class="terminal-red">${message}</span>`]);
|
||||
}
|
||||
|
||||
_onError(ev: ErrorEvent) {
|
||||
try {
|
||||
this.worker.terminate();
|
||||
} catch (e) {}
|
||||
|
||||
this.logError(`Emulator encountered fatal error: ${ev.message}`);
|
||||
this._setState(EmulationState.Failed);
|
||||
this.terminateResolve(-1);
|
||||
}
|
||||
|
||||
_onMessage(event: MessageEvent) {
|
||||
if (event.data.message == "log") {
|
||||
this.logHandler(event.data.data);
|
||||
|
||||
Reference in New Issue
Block a user