Skip to content

Commit bf3bac3

Browse files
committed
Add JSBigInt/clamped method, fix overload
1 parent 3ca1539 commit bf3bac3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Sources/JavaScriptKit/FundamentalObjects/JSBigInt.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import _CJavaScriptKit
22

3-
public class JSBigInt: JSObject {
4-
var int64Value: Int64 { _bigint_to_i64(id, true) }
5-
var uInt64Value: UInt64 {
3+
private let constructor = JSObject.global.BigInt.function!
4+
5+
public final class JSBigInt: JSObject {
6+
public var int64Value: Int64 {
7+
_bigint_to_i64(id, true)
8+
}
9+
public var uInt64Value: UInt64 {
610
UInt64(bitPattern: _bigint_to_i64(id, false))
711
}
812

913
public convenience init(_ value: Int64) {
1014
self.init(id: _i64_to_bigint(value, true))
1115
}
12-
public convenience init(_ value: UInt64) {
16+
public convenience init(unsigned value: UInt64) {
1317
self.init(id: _i64_to_bigint(Int64(bitPattern: value), false))
1418
}
1519

@@ -24,4 +28,12 @@ public class JSBigInt: JSObject {
2428
override public var jsValue: JSValue {
2529
.bigInt(self)
2630
}
31+
32+
public func clamped(bitSize: Int, signed: Bool) -> JSBigInt {
33+
if signed {
34+
return constructor.asIntN!(bitSize, self).bigInt!
35+
} else {
36+
return constructor.asUintN!(bitSize, self).bigInt!
37+
}
38+
}
2739
}

0 commit comments

Comments
 (0)