Skip to content

Commit

Permalink
fix breakByRaisingSigInt mistakenly called when run w/o debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx committed Oct 22, 2024
1 parent 9f62aac commit d4c0ed6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 3 additions & 5 deletions Sources/Common/Debug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ public func breakByRaisingSigInt(_ description: String, file: StaticString = #fi
#if DEBUG

// get symbol from stack trace for a caller of a calling method
public func callingSymbol() -> String {
public func callingSymbol(after lastSymbolName: String? = nil) -> String {
let stackTrace = Thread.callStackSymbols
// find `callingSymbol` itself or dispatch_once_callout
var callingSymbolIdx = stackTrace.firstIndex(where: { $0.contains("_dispatch_once_callout") })
?? stackTrace.firstIndex(where: { $0.contains("callingSymbol") })!
// procedure calling `callingSymbol`
callingSymbolIdx += 1
var callingSymbolIdx = lastSymbolName.flatMap { lastSymbolName in stackTrace.lastIndex(where: { $0.contains(lastSymbolName) }) }
?? stackTrace.firstIndex(where: { $0.contains("callingSymbol") })! + 1 // procedure calling `callingSymbol`

var symbolName: String
repeat {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Navigation/Extensions/WKFrameInfoExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public extension WKFrameInfo {
method_exchangeImplementations(originalRequestMethod, swizzledRequestMethod)

// ignore `request` selector calls from `safeRequest` itself
ignoredRequestUsageSymbols.insert(callingSymbol())
let callingSymbol = callingSymbol(after: "addSafetyCheckForSafeRequestUsageOnce")
ignoredRequestUsageSymbols.insert(callingSymbol)
// ignore `-[WKFrameInfo description]`
ignoredRequestUsageSymbols.insert("-[WKFrameInfo description]")
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ extension WKNavigationAction: WebViewNavigationAction {
let swizzledSourceFrameMethod = class_getInstanceMethod(WKNavigationAction.self, #selector(WKNavigationAction.swizzledSourceFrame))!
method_exchangeImplementations(originalSourceFrameMethod, swizzledSourceFrameMethod)

let callingSymbol = callingSymbol(after: "addSafetyCheckForSafeSourceFrameUsageOnce")
// ignore `sourceFrame` selector calls from `safeSourceFrame` itself
ignoredSourceFrameUsageSymbols.insert(callingSymbol())
ignoredSourceFrameUsageSymbols.insert(callingSymbol)
// ignore `-[WKNavigationAction description]`
ignoredSourceFrameUsageSymbols.insert("-[WKNavigationAction description]")
}()
Expand Down

0 comments on commit d4c0ed6

Please sign in to comment.