Various improvements

This commit is contained in:
Isaac
2025-02-28 00:34:28 +01:00
parent e5908c0bc8
commit 23ebf39221
9 changed files with 448 additions and 360 deletions

View File

@@ -86,9 +86,14 @@ private var ObjCKey_ContextReference: Int?
}
deinit {
self.cleanup()
}
func cleanup() {
for (_, timer) in self.timers {
timer.invalidate()
}
self.timers.removeAll()
}
func register(jsContext: JSContext) {
@@ -175,6 +180,7 @@ final class WebViewNativeJSContextImpl: HLSJSContext {
fileprivate final class Impl {
let queue: Queue
let context: JSContext
let timeoutPolyfill: TimeoutPolyfill
let handleScriptMessage: ([String: Any]) -> Void
init(queue: Queue, handleScriptMessage: @escaping ([String: Any]) -> Void) {
@@ -182,6 +188,8 @@ final class WebViewNativeJSContextImpl: HLSJSContext {
self.context = JSContext()
self.handleScriptMessage = handleScriptMessage
self.timeoutPolyfill = TimeoutPolyfill(queue: self.queue)
#if DEBUG
if #available(iOS 16.4, *) {
self.context.isInspectable = true
@@ -197,9 +205,8 @@ final class WebViewNativeJSContextImpl: HLSJSContext {
}
}
let timeoutPolyfill = TimeoutPolyfill(queue: self.queue)
self.context.setObject(timeoutPolyfill, forKeyedSubscript: "_timeoutPolyfill" as (NSCopying & NSObjectProtocol))
timeoutPolyfill.register(jsContext: self.context)
self.context.setObject(self.timeoutPolyfill, forKeyedSubscript: "_timeoutPolyfill" as (NSCopying & NSObjectProtocol))
self.timeoutPolyfill.register(jsContext: self.context)
self.context.setObject(JsCorePolyfills(queue: self.queue, context: Reference(context: self)), forKeyedSubscript: "_JsCorePolyfills" as (NSCopying & NSObjectProtocol))
@@ -219,6 +226,7 @@ final class WebViewNativeJSContextImpl: HLSJSContext {
}
deinit {
self.timeoutPolyfill.cleanup()
print("WebViewNativeJSContextImpl.deinit")
}