Skip to content
Snippets Groups Projects
Commit 3d9bd652 authored by Clifford T. Matthews's avatar Clifford T. Matthews
Browse files

Uses dyn Fn instead of dyn FnMut so the callbacks are reentrant

There is a bug in Firefox that can cause a panic when dyn FnMut closures
are used.  https://bugzilla.mozilla.org/show_bug.cgi?id=758004
For my software, simply changing the dyn FnMut to dyn Fn seems to work.
Once this branch is on GitHub, I'll build a version of my software that
I can deploy to where it can get tested by more people.  If it still
works, I'll write up a better explanation and contact scratchyone.
parent 4477c06f
No related branches found
No related tags found
No related merge requests found
...@@ -261,7 +261,7 @@ impl EventClient { ...@@ -261,7 +261,7 @@ impl EventClient {
if let Some(f) = &*on_error_ref.borrow() { if let Some(f) = &*on_error_ref.borrow() {
f.as_ref()(e); f.as_ref()(e);
} }
}) as Box<dyn FnMut(ErrorEvent)>); }) as Box<dyn Fn(ErrorEvent)>);
ws.set_onerror(Some(onerror_callback.as_ref().unchecked_ref())); ws.set_onerror(Some(onerror_callback.as_ref().unchecked_ref()));
onerror_callback.forget(); onerror_callback.forget();
...@@ -274,7 +274,7 @@ impl EventClient { ...@@ -274,7 +274,7 @@ impl EventClient {
if let Some(f) = &*on_close_ref.borrow() { if let Some(f) = &*on_close_ref.borrow() {
f.as_ref()(); f.as_ref()();
} }
}) as Box<dyn FnMut()>); }) as Box<dyn Fn()>);
ws.set_onclose(Some(onclose_callback.as_ref().unchecked_ref())); ws.set_onclose(Some(onclose_callback.as_ref().unchecked_ref()));
onclose_callback.forget(); onclose_callback.forget();
...@@ -306,7 +306,7 @@ impl EventClient { ...@@ -306,7 +306,7 @@ impl EventClient {
if let Some(f) = &*on_connection_ref.borrow() { if let Some(f) = &*on_connection_ref.borrow() {
f.as_ref()(&*client_ref.clone().borrow()); f.as_ref()(&*client_ref.clone().borrow());
} }
}) as Box<dyn FnMut(JsValue)>); }) as Box<dyn Fn(JsValue)>);
connection connection
.borrow_mut() .borrow_mut()
.set_onopen(Some(onopen_callback.as_ref().unchecked_ref())); .set_onopen(Some(onopen_callback.as_ref().unchecked_ref()));
...@@ -338,7 +338,7 @@ impl EventClient { ...@@ -338,7 +338,7 @@ impl EventClient {
f.as_ref()(&*cbfref.clone().borrow(), Message::Binary(array)); f.as_ref()(&*cbfref.clone().borrow(), Message::Binary(array));
} }
}) })
as Box<dyn FnMut(web_sys::ProgressEvent)>); as Box<dyn Fn(web_sys::ProgressEvent)>);
fr.set_onloadend(Some(onloadend_cb.as_ref().unchecked_ref())); fr.set_onloadend(Some(onloadend_cb.as_ref().unchecked_ref()));
fr.read_as_array_buffer(&blob).expect("blob not readable"); fr.read_as_array_buffer(&blob).expect("blob not readable");
onloadend_cb.forget(); onloadend_cb.forget();
...@@ -350,7 +350,7 @@ impl EventClient { ...@@ -350,7 +350,7 @@ impl EventClient {
// Got unknown data // Got unknown data
panic!("Unknown data: {:#?}", e.data()); panic!("Unknown data: {:#?}", e.data());
} }
}) as Box<dyn FnMut(MessageEvent)>); }) as Box<dyn Fn(MessageEvent)>);
// set message event handler on WebSocket // set message event handler on WebSocket
connection connection
.borrow() .borrow()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment