Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions 16 IntegrationTests/TestSuites/Sources/PrimaryTests/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,22 @@ ObjectRef_Lifetime: do {
let ref2 = identity(ref1).object!
try expectEqual(ref1.prop_2, .number(2))
try expectEqual(ref2.prop_2, .number(2))
identity.release()
} catch {
print(error)
}

func closureScope() -> ObjectIdentifier {
let closure = JSClosure { _ in .undefined }
let result = ObjectIdentifier(closure)
closure.release()
return result
}

Closure_Identifiers: do {
let oid1 = closureScope()
let oid2 = closureScope()
try expectEqual(oid1, oid2)
} catch {
print(error)
}
12 changes: 12 additions & 0 deletions 12 Sources/JavaScriptKit/JSFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class JSClosure: JSFunctionRef {

private var hostFuncRef: JavaScriptHostFuncRef = 0

private var isReleased = false

public init(_ body: @escaping ([JSValue]) -> JSValue) {
super.init(id: 0)
let objectId = ObjectIdentifier(self)
Expand All @@ -83,6 +85,16 @@ public class JSClosure: JSFunctionRef {

public func release() {
Self.sharedFunctions[hostFuncRef] = nil
isReleased = true
}

deinit {
guard isReleased else {
fatalError("""
release() must be called on closures manually before deallocating.
This is caused by the lack of support for the `FinalizationRegistry` API in Safari.
""")
}
}
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.