Skip to content

Commit 6517b7e

Browse files
committed
remove JAVASCRIPTKIT_WITHOUT_BIGINTS
1 parent a44de1a commit 6517b7e

File tree

8 files changed

+6
-53
lines changed

8 files changed

+6
-53
lines changed

.github/workflows/compatibility.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,3 @@ jobs:
2323
cd Example/JavaScriptKitExample
2424
swift build --triple wasm32-unknown-wasi
2525
swift build --triple wasm32-unknown-wasi -Xswiftc -DJAVASCRIPTKIT_WITHOUT_WEAKREFS
26-
swift build --triple wasm32-unknown-wasi -Xswiftc -DJAVASCRIPTKIT_WITHOUT_BIGINTS
27-
swift build --triple wasm32-unknown-wasi -Xswiftc -DJAVASCRIPTKIT_WITHOUT_WEAKREFS -Xswiftc -DJAVASCRIPTKIT_WITHOUT_BIGINTS

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ JavaScript features should work, which currently includes:
149149
- Mobile Safari 14.8+
150150

151151
If you need to support older browser versions, you'll have to build with
152-
`JAVASCRIPTKIT_WITHOUT_WEAKREFS` and `JAVASCRIPTKIT_WITHOUT_BIGINTS` flags, passing `-Xswiftc -DJAVASCRIPTKIT_WITHOUT_WEAKREFS -Xswiftc -DJAVASCRIPTKIT_WITHOUT_BIGINTS` flags
152+
the `JAVASCRIPTKIT_WITHOUT_WEAKREFS` flag, passing `-Xswiftc -DJAVASCRIPTKIT_WITHOUT_WEAKREFS` flags
153153
when compiling. This should lower browser requirements to these versions:
154154

155155
- Edge 16+

Runtime/src/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ export class SwiftRuntime {
3535
}`
3636
);
3737
}
38-
39-
if (this.exports.swjs_library_features() & LibraryFeatures.BigInts) {
40-
if (typeof BigInt === "undefined") {
41-
throw new Error(
42-
"The Swift part of JavaScriptKit was configured to require " +
43-
"the availability of JavaScript BigInts. Please build " +
44-
"with `-Xswiftc -DJAVASCRIPTKIT_WITHOUT_BIGINTS` to " +
45-
"disable features that use BigInts."
46-
);
47-
}
48-
}
4938
}
5039

5140
private get instance() {

Sources/JavaScriptKit/ConstructibleFromJSValue.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,12 @@ extension Double: ConstructibleFromJSValue {}
3535
extension Float: ConstructibleFromJSValue {}
3636

3737
extension SignedInteger where Self: ConstructibleFromJSValue {
38-
#if JAVASCRIPTKIT_WITHOUT_BIGINTS
39-
public static func construct(from value: JSValue) -> Self? {
40-
value.number.map(Self.init)
41-
}
42-
#else
4338
public init(_ bigInt: JSBigInt) {
4439
self.init(bigInt.int64Value)
4540
}
4641
public static func construct(from value: JSValue) -> Self? {
4742
value.bigInt.map(Self.init) ?? value.number.map(Self.init)
4843
}
49-
#endif
5044
}
5145
extension Int: ConstructibleFromJSValue {}
5246
extension Int8: ConstructibleFromJSValue {}
@@ -55,18 +49,12 @@ extension Int32: ConstructibleFromJSValue {}
5549
extension Int64: ConstructibleFromJSValue {}
5650

5751
extension UnsignedInteger where Self: ConstructibleFromJSValue {
58-
#if JAVASCRIPTKIT_WITHOUT_BIGINTS
59-
public static func construct(from value: JSValue) -> Self? {
60-
value.number.map(Self.init)
61-
}
62-
#else
6352
public init(_ bigInt: JSBigInt) {
6453
self.init(bigInt.uInt64Value)
6554
}
6655
public static func construct(from value: JSValue) -> Self? {
6756
value.bigInt.map(Self.init) ?? value.number.map(Self.init)
6857
}
69-
#endif
7058
}
7159
extension UInt: ConstructibleFromJSValue {}
7260
extension UInt8: ConstructibleFromJSValue {}

Sources/JavaScriptKit/ConvertibleToJSValue.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,7 @@ extension RawJSValue: ConvertibleToJSValue {
218218
case .symbol:
219219
return .symbol(JSSymbol(id: UInt32(payload1)))
220220
case .bigInt:
221-
#if JAVASCRIPTKIT_WITHOUT_BIGINTS
222-
fatalError("Received unsupported BigInt value")
223-
#else
224221
return .bigInt(JSBigInt(id: UInt32(payload1)))
225-
#endif
226222
}
227223
}
228224
}
@@ -257,11 +253,9 @@ extension JSValue {
257253
case let .symbol(symbolRef):
258254
kind = .symbol
259255
payload1 = JavaScriptPayload1(symbolRef.id)
260-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
261256
case let .bigInt(bigIntRef):
262257
kind = .bigInt
263258
payload1 = JavaScriptPayload1(bigIntRef.id)
264-
#endif
265259
}
266260
let rawValue = RawJSValue(kind: kind, payload1: payload1, payload2: payload2)
267261
return body(rawValue)

Sources/JavaScriptKit/Features.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
enum LibraryFeatures {
22
static let weakRefs: Int32 = 1 << 0
3-
static let bigInts: Int32 = 1 << 1
43
}
54

65
@_cdecl("_library_features")
76
func _library_features() -> Int32 {
87
var features: Int32 = 0
98
#if !JAVASCRIPTKIT_WITHOUT_WEAKREFS
109
features |= LibraryFeatures.weakRefs
11-
#endif
12-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
13-
features |= LibraryFeatures.bigInts
1410
#endif
1511
return features
1612
}

Sources/JavaScriptKit/FundamentalObjects/JSBigInt.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import _CJavaScriptKit
22

3-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
43
private let constructor = JSObject.global.BigInt.function!
54

65
public final class JSBigInt: JSObject {
76
public var int64Value: Int64 {
87
_bigint_to_i64(id, true)
98
}
9+
1010
public var uInt64Value: UInt64 {
1111
UInt64(bitPattern: _bigint_to_i64(id, false))
1212
}
1313

1414
public convenience init(_ value: Int64) {
1515
self.init(id: _i64_to_bigint(value, true))
1616
}
17+
1718
public convenience init(unsigned value: UInt64) {
1819
self.init(id: _i64_to_bigint(Int64(bitPattern: value), false))
1920
}
2021

21-
public override init(id: JavaScriptObjectRef) {
22+
override public init(id: JavaScriptObjectRef) {
2223
super.init(id: id)
2324
}
2425

@@ -38,4 +39,3 @@ public final class JSBigInt: JSObject {
3839
}
3940
}
4041
}
41-
#endif

Sources/JavaScriptKit/JSValue.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ public enum JSValue: Equatable {
1111
case undefined
1212
case function(JSFunction)
1313
case symbol(JSSymbol)
14-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
1514
case bigInt(JSBigInt)
16-
#endif
1715

1816
/// Returns the `Bool` value of this JS value if its type is boolean.
1917
/// If not, returns `nil`.
@@ -80,7 +78,6 @@ public enum JSValue: Equatable {
8078
}
8179
}
8280

83-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
8481
/// Returns the `JSBigInt` of this JS value if its type is function.
8582
/// If not, returns `nil`.
8683
public var bigInt: JSBigInt? {
@@ -89,7 +86,6 @@ public enum JSValue: Equatable {
8986
default: return nil
9087
}
9188
}
92-
#endif
9389

9490
/// Returns the `true` if this JS value is null.
9591
/// If not, returns `false`.
@@ -249,12 +245,8 @@ public extension JSValue {
249245
/// - Returns: The result of `instanceof` in the JavaScript environment.
250246
func isInstanceOf(_ constructor: JSFunction) -> Bool {
251247
switch self {
252-
case .boolean, .string, .number, .null, .undefined, .symbol:
248+
case .boolean, .string, .number, .null, .undefined, .symbol, .bigInt:
253249
return false
254-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
255-
case .bigInt:
256-
return false
257-
#endif
258250
case let .object(ref):
259251
return ref.isInstanceOf(constructor)
260252
case let .function(ref):
@@ -273,12 +265,8 @@ extension JSValue: CustomStringConvertible {
273265
case let .number(number):
274266
return number.description
275267
case let .object(object), let .function(object as JSObject),
276-
let .symbol(object as JSObject):
277-
return object.toString!().fromJSValue()!
278-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
279-
case let .bigInt(object as JSObject):
268+
let .symbol(object as JSObject), let .bigInt(object as JSObject):
280269
return object.toString!().fromJSValue()!
281-
#endif
282270
case .null:
283271
return "null"
284272
case .undefined:

0 commit comments

Comments
 (0)