From 7234b2b99a8efc59484c96b767f3be8b52127816 Mon Sep 17 00:00:00 2001 From: Linda_pp Date: Wed, 24 Jan 2024 22:07:38 +0900 Subject: [PATCH] fix(macos): fix SEGV when calling `WebView::evaluate_script` on release build (#1152) * fix(macos): fix SEGV when calling `WebView::evaluate_javascript` on release build Signed-off-by: rhysd * remove unnecessary empty completion handler Signed-off-by: rhysd * fix method name in change file and clarify when the bug was added --------- Signed-off-by: rhysd --- .changes/fix-eval-crash.md | 5 +++++ src/wkwebview/mod.rs | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changes/fix-eval-crash.md diff --git a/.changes/fix-eval-crash.md b/.changes/fix-eval-crash.md new file mode 100644 index 000000000..55eda3a2d --- /dev/null +++ b/.changes/fix-eval-crash.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +On macOS, fix a release build crashes with SEGV when calling `WebView::evaluate_script`. This crash bug was introduced at v0.35.2. diff --git a/src/wkwebview/mod.rs b/src/wkwebview/mod.rs index 8301cbd83..0607e2b72 100644 --- a/src/wkwebview/mod.rs +++ b/src/wkwebview/mod.rs @@ -956,7 +956,7 @@ r#"Object.defineProperty(window, 'ipc', { let span = Mutex::new(Some(tracing::debug_span!("wry::eval").entered())); // we need to check if the callback exists outside the handler otherwise it's a segfault - if let Some(callback) = &callback { + if let Some(callback) = callback { let handler = block::ConcreteBlock::new(move |val: id, _err: id| { #[cfg(feature = "tracing")] span.lock().unwrap().take(); @@ -972,15 +972,18 @@ r#"Object.defineProperty(window, 'ipc', { } callback(result); - }); + }).copy(); let _: () = msg_send![self.webview, evaluateJavaScript:NSString::new(js) completionHandler:handler]; } else { + #[cfg(feature = "tracing")] let handler = block::ConcreteBlock::new(move |_val: id, _err: id| { - #[cfg(feature = "tracing")] span.lock().unwrap().take(); - }); + }) + .copy(); + #[cfg(not(feature = "tracing"))] + let handler = null::<*const c_void>(); let _: () = msg_send![self.webview, evaluateJavaScript:NSString::new(js) completionHandler:handler]; @@ -1020,7 +1023,7 @@ r#"Object.defineProperty(window, 'ipc', { let store: id = msg_send![config, websiteDataStore]; let all_data_types: id = msg_send![class!(WKWebsiteDataStore), allWebsiteDataTypes]; let date: id = msg_send![class!(NSDate), dateWithTimeIntervalSince1970: 0.0]; - let handler = block::ConcreteBlock::new(|| {}); + let handler = null::<*const c_void>(); let _: () = msg_send![store, removeDataOfTypes:all_data_types modifiedSince:date completionHandler:handler]; } Ok(())