@@ -4,6 +4,70 @@ import JavaScriptEventLoop
4
4
import JavaScriptKit
5
5
6
6
/* variadic generics please */
7
+ @propertyWrapper public final class ClosureAttribute0 < ReturnType>
8
+ where ReturnType: JSValueCompatible
9
+ {
10
+ @usableFromInline let jsObject : JSObject
11
+ @usableFromInline let name : JSString
12
+
13
+ public init ( jsObject: JSObject , name: JSString ) {
14
+ self . jsObject = jsObject
15
+ self . name = name
16
+ }
17
+
18
+ @inlinable public var wrappedValue : ( ) -> ReturnType {
19
+ get { ClosureAttribute0 [ name, in: jsObject] }
20
+ set { ClosureAttribute0 [ name, in: jsObject] = newValue }
21
+ }
22
+
23
+ @inlinable public static subscript( name: JSString , in jsObject: JSObject ) -> ( ) -> ReturnType {
24
+ get {
25
+ let function = jsObject [ name] . function!
26
+ return { function ( ) . fromJSValue ( ) ! }
27
+ }
28
+ set {
29
+ jsObject [ name] = JSClosure { _ in
30
+ newValue ( ) . jsValue
31
+ } . jsValue
32
+ }
33
+ }
34
+ }
35
+
36
+ @propertyWrapper public final class ClosureAttribute0Optional < ReturnType>
37
+ where ReturnType: JSValueCompatible
38
+ {
39
+ @usableFromInline let jsObject : JSObject
40
+ @usableFromInline let name : JSString
41
+
42
+ public init ( jsObject: JSObject , name: JSString ) {
43
+ self . jsObject = jsObject
44
+ self . name = name
45
+ }
46
+
47
+ @inlinable public var wrappedValue : ( ( ) -> ReturnType ) ? {
48
+ get { ClosureAttribute0Optional [ name, in: jsObject] }
49
+ set { ClosureAttribute0Optional [ name, in: jsObject] = newValue }
50
+ }
51
+
52
+ @inlinable public static subscript( name: JSString , in jsObject: JSObject ) -> ( ( ) -> ReturnType ) ? {
53
+ get {
54
+ guard let function = jsObject [ name] . function else {
55
+ return nil
56
+ }
57
+ return { function ( ) . fromJSValue ( ) ! }
58
+ }
59
+ set {
60
+ if let newValue = newValue {
61
+ jsObject [ name] = JSClosure { _ in
62
+ newValue ( ) . jsValue
63
+ } . jsValue
64
+ } else {
65
+ jsObject [ name] = . null
66
+ }
67
+ }
68
+ }
69
+ }
70
+
7
71
@propertyWrapper public final class ClosureAttribute0OptionalVoid {
8
72
@usableFromInline let jsObject : JSObject
9
73
@usableFromInline let name : JSString
@@ -196,6 +260,70 @@ import JavaScriptKit
196
260
}
197
261
}
198
262
263
+ @propertyWrapper public final class ClosureAttribute2 < A0, A1, ReturnType>
264
+ where A0: JSValueCompatible , A1: JSValueCompatible , ReturnType: JSValueCompatible
265
+ {
266
+ @usableFromInline let jsObject : JSObject
267
+ @usableFromInline let name : JSString
268
+
269
+ public init ( jsObject: JSObject , name: JSString ) {
270
+ self . jsObject = jsObject
271
+ self . name = name
272
+ }
273
+
274
+ @inlinable public var wrappedValue : ( A0 , A1 ) -> ReturnType {
275
+ get { ClosureAttribute2 [ name, in: jsObject] }
276
+ set { ClosureAttribute2 [ name, in: jsObject] = newValue }
277
+ }
278
+
279
+ @inlinable public static subscript( name: JSString , in jsObject: JSObject ) -> ( A0 , A1 ) -> ReturnType {
280
+ get {
281
+ let function = jsObject [ name] . function!
282
+ return { function ( $0. jsValue, $1. jsValue) . fromJSValue ( ) ! }
283
+ }
284
+ set {
285
+ jsObject [ name] = JSClosure {
286
+ newValue ( $0 [ 0 ] . fromJSValue ( ) !, $0 [ 1 ] . fromJSValue ( ) !) . jsValue
287
+ } . jsValue
288
+ }
289
+ }
290
+ }
291
+
292
+ @propertyWrapper public final class ClosureAttribute2Optional < A0, A1, ReturnType>
293
+ where A0: JSValueCompatible , A1: JSValueCompatible , ReturnType: JSValueCompatible
294
+ {
295
+ @usableFromInline let jsObject : JSObject
296
+ @usableFromInline let name : JSString
297
+
298
+ public init ( jsObject: JSObject , name: JSString ) {
299
+ self . jsObject = jsObject
300
+ self . name = name
301
+ }
302
+
303
+ @inlinable public var wrappedValue : ( ( A0 , A1 ) -> ReturnType ) ? {
304
+ get { ClosureAttribute2Optional [ name, in: jsObject] }
305
+ set { ClosureAttribute2Optional [ name, in: jsObject] = newValue }
306
+ }
307
+
308
+ @inlinable public static subscript( name: JSString , in jsObject: JSObject ) -> ( ( A0 , A1 ) -> ReturnType ) ? {
309
+ get {
310
+ guard let function = jsObject [ name] . function else {
311
+ return nil
312
+ }
313
+ return { function ( $0. jsValue, $1. jsValue) . fromJSValue ( ) ! }
314
+ }
315
+ set {
316
+ if let newValue = newValue {
317
+ jsObject [ name] = JSClosure {
318
+ newValue ( $0 [ 0 ] . fromJSValue ( ) !, $0 [ 1 ] . fromJSValue ( ) !) . jsValue
319
+ } . jsValue
320
+ } else {
321
+ jsObject [ name] = . null
322
+ }
323
+ }
324
+ }
325
+ }
326
+
199
327
@propertyWrapper public final class ClosureAttribute2OptionalVoid < A0, A1>
200
328
where A0: JSValueCompatible , A1: JSValueCompatible
201
329
{
0 commit comments