File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
IntegrationTests/TestSuites/Sources/PrimaryTests Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -331,6 +331,22 @@ ObjectRef_Lifetime: do {
331331 let ref2 = identity ( ref1) . object!
332332 try expectEqual ( ref1. prop_2, . number( 2 ) )
333333 try expectEqual ( ref2. prop_2, . number( 2 ) )
334+ identity. release ( )
335+ } catch {
336+ print ( error)
337+ }
338+
339+ func closureScope( ) -> ObjectIdentifier {
340+ let closure = JSClosure { _ in . undefined }
341+ let result = ObjectIdentifier ( closure)
342+ closure. release ( )
343+ return result
344+ }
345+
346+ Closure_Identifiers: do {
347+ let oid1 = closureScope ( )
348+ let oid2 = closureScope ( )
349+ try expectEqual ( oid1, oid2)
334350} catch {
335351 print ( error)
336352}
Original file line number Diff line number Diff line change @@ -67,6 +67,8 @@ public class JSClosure: JSFunctionRef {
6767
6868 private var hostFuncRef : JavaScriptHostFuncRef = 0
6969
70+ private var isReleased = false
71+
7072 public init ( _ body: @escaping ( [ JSValue ] ) -> JSValue ) {
7173 super. init ( id: 0 )
7274 let objectId = ObjectIdentifier ( self )
@@ -82,6 +84,16 @@ public class JSClosure: JSFunctionRef {
8284
8385 public func release( ) {
8486 Self . sharedFunctions [ hostFuncRef] = nil
87+ isReleased = true
88+ }
89+
90+ deinit {
91+ guard isReleased else {
92+ fatalError ( """
93+ release() must be called on closures manually before deallocating.
94+ This is caused by the lack of support for the `FinalizationRegistry` API in Safari.
95+ """ )
96+ }
8597 }
8698}
8799
You can’t perform that action at this time.
0 commit comments