5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 03:01:45 +08:00

fix: failsafe JavaScript event emitter notifyListeners (#3695)

* fix: failsafe JavaScript event emitter `notifyListeners`

* chore: update change log
This commit is contained in:
Mohamed Feddad 2024-08-21 01:00:54 +04:00 committed by GitHub
parent 868931fe72
commit 4b6a8e17c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 10 deletions

View File

@ -90,17 +90,17 @@ function notifyListeners(eventData) {
// Get the event name
let eventName = eventData.name;
// Check if we have any listeners for this event
if (eventListeners[eventName]) {
// Keep a list of listener indexes to destroy
const newEventListenerList = eventListeners[eventName]?.slice() || [];
// Keep a list of listener indexes to destroy
const newEventListenerList = eventListeners[eventName].slice();
// Check if we have any listeners for this event
if (newEventListenerList.length) {
// Iterate listeners
for (let count = eventListeners[eventName].length - 1; count >= 0; count -= 1) {
for (let count = newEventListenerList.length - 1; count >= 0; count -= 1) {
// Get next listener
const listener = eventListeners[eventName][count];
const listener = newEventListenerList[count];
let data = eventData.data;

View File

@ -83,10 +83,10 @@
}
function notifyListeners(eventData) {
let eventName = eventData.name;
if (eventListeners[eventName]) {
const newEventListenerList = eventListeners[eventName].slice();
for (let count = eventListeners[eventName].length - 1; count >= 0; count -= 1) {
const listener = eventListeners[eventName][count];
const newEventListenerList = eventListeners[eventName]?.slice() || [];
if (newEventListenerList.length) {
for (let count = newEventListenerList.length - 1; count >= 0; count -= 1) {
const listener = newEventListenerList[count];
let data = eventData.data;
const destroy = listener.Callback(data);
if (destroy) {

View File

@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
+ Modified `ZoomFactor` and `IsZoomControlEnabled` options to be Windows-only options in PR[#3644](https://github.com/wailsapp/wails/pull/3644) by @levinit
- Added nil check for Drag-n-Drop on Windows. Fixed by in [PR](https://github.com/wailsapp/wails/pull/3597) by @leaanthony based on the suggestion by @Alpa-1 in [#3596](https://github.com/wailsapp/wails/issues/3596).
- Fixed typos in various .mdx files. [PR #3628](https://github.com/wailsapp/wails/pull/3628) by [@deining](https://github.com/deining)
- Fixed `notifyListeners()` race condition when terminated mid-emission [PR](https://github.com/wailsapp/wails/pull/3695) by [@mrf345](https://github.com/mrf345)
## v2.9.1 - 2024-06-18