From 339b974c2316a5f9fbbe733f27682f6725c93dc0 Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Tue, 22 Oct 2024 17:39:06 +0600 Subject: [PATCH] fix breakByRaisingSigInt mistakenly called when run w/o debugger (#1029) Task/Issue URL: https://app.asana.com/0/414709148257752/1208592357309749/f --- Sources/Common/Debug.swift | 8 +++----- Sources/Navigation/Extensions/WKFrameInfoExtension.swift | 3 ++- .../Extensions/WKNavigationActionExtension.swift | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Common/Debug.swift b/Sources/Common/Debug.swift index 096397683..9a1884f20 100644 --- a/Sources/Common/Debug.swift +++ b/Sources/Common/Debug.swift @@ -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 { diff --git a/Sources/Navigation/Extensions/WKFrameInfoExtension.swift b/Sources/Navigation/Extensions/WKFrameInfoExtension.swift index b2badbff0..b5698c08b 100644 --- a/Sources/Navigation/Extensions/WKFrameInfoExtension.swift +++ b/Sources/Navigation/Extensions/WKFrameInfoExtension.swift @@ -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]") }() diff --git a/Sources/Navigation/Extensions/WKNavigationActionExtension.swift b/Sources/Navigation/Extensions/WKNavigationActionExtension.swift index 56b35eb94..31ffbce67 100644 --- a/Sources/Navigation/Extensions/WKNavigationActionExtension.swift +++ b/Sources/Navigation/Extensions/WKNavigationActionExtension.swift @@ -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]") }()