signals: Fix bugs when multiple handlers are connected and disconnect is called
I ran into this bug when attempting to run GNOME Shell's signal tests locally against the latest GJS...
Essentially with the current updated code if you have multiple handlers connected, removing one of those handlers breaks the internal state of signals. This is due to several overlapping bugs in this code: ids?.splice(ids.indexOf(id, 1));
.
Currently this code "finds the first index of id
starting at index 1
and removes all items starting at the found index or at the end of the array if id
is not found (-1)".
- I'm guessing
ids?.splice( ids.indexOf( id, 1 ) );
was meant to beids?.splice( ids.indexOf( id ) , 1);
but this still holds a lurking bug, ifindexOf
returns-1
(not found) then it removes a random/unrelated id as-1
starts from the end of the array. - The check
!connectionsByName.size
isn't functional, though re-assigning every time probably isn't an issue
I added a test but we may need more coverage.
Edited by Evan Welsh