Skip to content

Commit

Permalink
fix(macos): fix SEGV when calling WebView::evaluate_script on relea…
Browse files Browse the repository at this point in the history
…se build (#1152)

* fix(macos): fix SEGV when calling `WebView::evaluate_javascript` on release build

Signed-off-by: rhysd <[email protected]>

* remove unnecessary empty completion handler

Signed-off-by: rhysd <[email protected]>

* fix method name in change file and clarify when the bug was added

---------

Signed-off-by: rhysd <[email protected]>
  • Loading branch information
rhysd authored Jan 24, 2024
1 parent 52c861b commit 7234b2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-eval-crash.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 8 additions & 5 deletions src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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];
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 7234b2b

Please sign in to comment.