File tree Expand file tree Collapse file tree 3 files changed +29
-9
lines changed Expand file tree Collapse file tree 3 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -35,11 +35,17 @@ extension Double: ConstructibleFromJSValue {}
35
35
extension Float : ConstructibleFromJSValue { }
36
36
37
37
extension SignedInteger where Self: ConstructibleFromJSValue {
38
- public init ( _ bigInt: JSBigInt ) {
38
+ public init ( _ bigInt: JSBigIntExtended ) {
39
39
self . init ( bigInt. int64Value)
40
40
}
41
41
public static func construct( from value: JSValue ) -> Self ? {
42
- value. bigInt. map ( Self . init) ?? value. number. map ( Self . init)
42
+ if let number = value. number {
43
+ return Self ( number)
44
+ }
45
+ if let bigInt = value. bigInt as? JSBigIntExtended {
46
+ return Self ( bigInt)
47
+ }
48
+ return nil
43
49
}
44
50
}
45
51
extension Int : ConstructibleFromJSValue { }
@@ -49,11 +55,17 @@ extension Int32: ConstructibleFromJSValue {}
49
55
extension Int64 : ConstructibleFromJSValue { }
50
56
51
57
extension UnsignedInteger where Self: ConstructibleFromJSValue {
52
- public init ( _ bigInt: JSBigInt ) {
58
+ public init ( _ bigInt: JSBigIntExtended ) {
53
59
self . init ( bigInt. uInt64Value)
54
60
}
55
61
public static func construct( from value: JSValue ) -> Self ? {
56
- value. bigInt. map ( Self . init) ?? value. number. map ( Self . init)
62
+ if let number = value. number {
63
+ return Self ( number)
64
+ }
65
+ if let bigInt = value. bigInt as? JSBigIntExtended {
66
+ return Self ( bigInt)
67
+ }
68
+ return nil
57
69
}
58
70
}
59
71
extension UInt : ConstructibleFromJSValue { }
Original file line number Diff line number Diff line change @@ -23,3 +23,11 @@ public final class JSBigInt: JSObject {
23
23
}
24
24
}
25
25
}
26
+
27
+ public protocol JSBigIntExtended : JSBigInt {
28
+ var int64Value : Int64 { get }
29
+ var uInt64Value : UInt64 { get }
30
+
31
+ init ( _ value: Int64 )
32
+ init ( unsigned value: UInt64 )
33
+ }
Original file line number Diff line number Diff line change 1
1
@_spi ( JSObject_id) import JavaScriptKit
2
2
import _CJavaScriptKit_I64
3
3
4
- public extension JSBigInt {
5
- var int64Value : Int64 {
4
+ extension JSBigInt : JSBigIntExtended {
5
+ public var int64Value : Int64 {
6
6
_bigint_to_i64 ( id, true )
7
7
}
8
8
9
- var uInt64Value : UInt64 {
9
+ public var uInt64Value : UInt64 {
10
10
UInt64 ( bitPattern: _bigint_to_i64 ( id, false ) )
11
11
}
12
12
13
- convenience init ( _ value: Int64 ) {
13
+ convenience public init ( _ value: Int64 ) {
14
14
self . init ( id: _i64_to_bigint ( value, true ) )
15
15
}
16
16
17
- convenience init ( unsigned value: UInt64 ) {
17
+ convenience public init ( unsigned value: UInt64 ) {
18
18
self . init ( id: _i64_to_bigint ( Int64 ( bitPattern: value) , false ) )
19
19
}
20
20
}
You can’t perform that action at this time.
0 commit comments