From 18a19dcbd701f944a066b3e455464849820bf2f6 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Sat, 12 Dec 2020 14:10:31 +0200 Subject: fix(cpu): event system issue `updateClockEvent()` and `clearClockEvent()` would sometimes mess up the list of events. This could cause unexpected behavior when you have multiple timers running. Also added regression tests for these methods. --- src/cpu/cpu.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cpu/cpu.ts') diff --git a/src/cpu/cpu.ts b/src/cpu/cpu.ts index fb98786..e7a2544 100644 --- a/src/cpu/cpu.ts +++ b/src/cpu/cpu.ts @@ -186,7 +186,7 @@ export class CPU implements ICPU { } updateClockEvent(callback: AVRClockEventCallback, cycles: number) { - const entry = this.clockEvents.find((item) => (item.callback = callback)); + const entry = this.clockEvents.find((item) => item.callback === callback); if (entry) { entry.cycles = this.cycles + Math.max(1, cycles); this.updateClockEvents(); @@ -196,7 +196,7 @@ export class CPU implements ICPU { } clearClockEvent(callback: AVRClockEventCallback) { - const index = this.clockEvents.findIndex((item) => (item.callback = callback)); + const index = this.clockEvents.findIndex((item) => item.callback === callback); if (index >= 0) { this.clockEvents.splice(index, 1); this.updateClockEvents(); -- cgit v1.2.3