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 {
331
331
let ref2 = identity ( ref1) . object!
332
332
try expectEqual ( ref1. prop_2, . number( 2 ) )
333
333
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)
334
350
} catch {
335
351
print ( error)
336
352
}
Original file line number Diff line number Diff line change @@ -67,6 +67,8 @@ public class JSClosure: JSFunctionRef {
67
67
68
68
private var hostFuncRef : JavaScriptHostFuncRef = 0
69
69
70
+ private var isReleased = false
71
+
70
72
public init ( _ body: @escaping ( [ JSValue ] ) -> JSValue ) {
71
73
super. init ( id: 0 )
72
74
let objectId = ObjectIdentifier ( self )
@@ -82,6 +84,16 @@ public class JSClosure: JSFunctionRef {
82
84
83
85
public func release( ) {
84
86
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
+ }
85
97
}
86
98
}
87
99
You can’t perform that action at this time.
0 commit comments