Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fa93b91
Initial BigInt support
j-f1 Apr 9, 2022
3ca1539
Switch to const enums
j-f1 Apr 9, 2022
bf3bac3
Add JSBigInt/clamped method, fix overload
j-f1 Apr 9, 2022
8c02c79
Convert BigInts into Swift ints automatically
j-f1 Apr 9, 2022
814774b
Add support for JAVASCRIPTKIT_WITHOUT_BIGINTS
j-f1 Apr 9, 2022
0bcb359
Allow Int64/UInt64-based arrays
j-f1 Apr 9, 2022
d1543fc
Don’t use BigInt literal for backwards compat
j-f1 Apr 9, 2022
f8838eb
bump lib version
j-f1 Apr 9, 2022
26b51c7
long long?
j-f1 Apr 9, 2022
4dd4aae
document JAVASCRIPTKIT_WITHOUT_BIGINTS flag
j-f1 Apr 9, 2022
cd3c076
check compatibility workflow builds all variants
j-f1 Apr 9, 2022
76303b9
Increase error stack trace limit
j-f1 Apr 9, 2022
c356aba
Use correct type for setTimeout in JavaScriptEventLoop
j-f1 Apr 9, 2022
6f150ad
Add symbol support to runtime’s JSValue.decode
j-f1 Apr 9, 2022
6257d35
remove JavaScriptValueKindInvalid since neither side produces it
j-f1 Apr 9, 2022
203844f
use assertNever to ensure runtime switch statements are kept up to date
j-f1 Apr 9, 2022
9d066f9
BigInt tests
j-f1 Apr 9, 2022
1fdcd26
Revert changes to README
j-f1 Apr 10, 2022
14541b8
consistent whitespace (by semantic grouping) in index.ts
j-f1 Apr 10, 2022
dcd38c7
Rename: type→kind
j-f1 Apr 10, 2022
63f33d0
drop implicit return
j-f1 Apr 10, 2022
30a3e66
assert Int/UInt types are 32-bit for now
j-f1 Apr 10, 2022
68cb689
Require BigInts for ConvertibleToJSValue conformance on Int64/UInt64
j-f1 Apr 10, 2022
01ae32d
run Prettier on primary-tests.js
j-f1 Apr 10, 2022
a44de1a
move stackTraceLimit change to non-benchmark tests only
j-f1 Apr 10, 2022
6517b7e
remove JAVASCRIPTKIT_WITHOUT_BIGINTS
j-f1 Apr 16, 2022
c54bd10
SPI for JSObject_id
j-f1 Apr 16, 2022
7af5917
Move i64 stuff to a separate module
j-f1 Apr 16, 2022
b7a6a7d
fix Signed/UnsignedInteger ConstructibleFromJSValue
j-f1 Apr 16, 2022
b83611f
fix tests?
j-f1 Apr 16, 2022
4ca7705
Address review comments
j-f1 Apr 16, 2022
35dd9f7
Simplify JSValue: CustomStringConvertible conformance
j-f1 Apr 16, 2022
0ec8fc3
rename to JavaScriptBigIntSupport
j-f1 Apr 22, 2022
7960198
Formatting tweak
j-f1 Apr 22, 2022
5cff142
fix typo
j-f1 Apr 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove JAVASCRIPTKIT_WITHOUT_BIGINTS
  • Loading branch information
j-f1 committed Apr 16, 2022
commit 6517b7e4da51a472e81c41d12e1b68904bc770d8
2 changes: 0 additions & 2 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ jobs:
cd Example/JavaScriptKitExample
swift build --triple wasm32-unknown-wasi
swift build --triple wasm32-unknown-wasi -Xswiftc -DJAVASCRIPTKIT_WITHOUT_WEAKREFS
swift build --triple wasm32-unknown-wasi -Xswiftc -DJAVASCRIPTKIT_WITHOUT_BIGINTS
swift build --triple wasm32-unknown-wasi -Xswiftc -DJAVASCRIPTKIT_WITHOUT_WEAKREFS -Xswiftc -DJAVASCRIPTKIT_WITHOUT_BIGINTS
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ JavaScript features should work, which currently includes:
- Mobile Safari 14.8+

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

- Edge 16+
Expand Down
11 changes: 0 additions & 11 deletions Runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ export class SwiftRuntime {
}`
);
}

if (this.exports.swjs_library_features() & LibraryFeatures.BigInts) {
if (typeof BigInt === "undefined") {
throw new Error(
"The Swift part of JavaScriptKit was configured to require " +
"the availability of JavaScript BigInts. Please build " +
"with `-Xswiftc -DJAVASCRIPTKIT_WITHOUT_BIGINTS` to " +
"disable features that use BigInts."
);
}
}
}

private get instance() {
Expand Down
12 changes: 0 additions & 12 deletions Sources/JavaScriptKit/ConstructibleFromJSValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ extension Double: ConstructibleFromJSValue {}
extension Float: ConstructibleFromJSValue {}

extension SignedInteger where Self: ConstructibleFromJSValue {
#if JAVASCRIPTKIT_WITHOUT_BIGINTS
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
#else
public init(_ bigInt: JSBigInt) {
self.init(bigInt.int64Value)
}
public static func construct(from value: JSValue) -> Self? {
value.bigInt.map(Self.init) ?? value.number.map(Self.init)
}
#endif
}
extension Int: ConstructibleFromJSValue {}
extension Int8: ConstructibleFromJSValue {}
Expand All @@ -55,18 +49,12 @@ extension Int32: ConstructibleFromJSValue {}
extension Int64: ConstructibleFromJSValue {}

extension UnsignedInteger where Self: ConstructibleFromJSValue {
#if JAVASCRIPTKIT_WITHOUT_BIGINTS
public static func construct(from value: JSValue) -> Self? {
value.number.map(Self.init)
}
#else
public init(_ bigInt: JSBigInt) {
self.init(bigInt.uInt64Value)
}
public static func construct(from value: JSValue) -> Self? {
value.bigInt.map(Self.init) ?? value.number.map(Self.init)
}
#endif
}
extension UInt: ConstructibleFromJSValue {}
extension UInt8: ConstructibleFromJSValue {}
Expand Down
6 changes: 0 additions & 6 deletions Sources/JavaScriptKit/ConvertibleToJSValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,7 @@ extension RawJSValue: ConvertibleToJSValue {
case .symbol:
return .symbol(JSSymbol(id: UInt32(payload1)))
case .bigInt:
#if JAVASCRIPTKIT_WITHOUT_BIGINTS
fatalError("Received unsupported BigInt value")
#else
return .bigInt(JSBigInt(id: UInt32(payload1)))
#endif
}
}
}
Expand Down Expand Up @@ -257,11 +253,9 @@ extension JSValue {
case let .symbol(symbolRef):
kind = .symbol
payload1 = JavaScriptPayload1(symbolRef.id)
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
case let .bigInt(bigIntRef):
kind = .bigInt
payload1 = JavaScriptPayload1(bigIntRef.id)
#endif
}
let rawValue = RawJSValue(kind: kind, payload1: payload1, payload2: payload2)
return body(rawValue)
Expand Down
4 changes: 0 additions & 4 deletions Sources/JavaScriptKit/Features.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
enum LibraryFeatures {
static let weakRefs: Int32 = 1 << 0
static let bigInts: Int32 = 1 << 1
}

@_cdecl("_library_features")
func _library_features() -> Int32 {
var features: Int32 = 0
#if !JAVASCRIPTKIT_WITHOUT_WEAKREFS
features |= LibraryFeatures.weakRefs
#endif
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
features |= LibraryFeatures.bigInts
#endif
return features
}
6 changes: 3 additions & 3 deletions Sources/JavaScriptKit/FundamentalObjects/JSBigInt.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import _CJavaScriptKit

#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
private let constructor = JSObject.global.BigInt.function!

public final class JSBigInt: JSObject {
public var int64Value: Int64 {
_bigint_to_i64(id, true)
}

public var uInt64Value: UInt64 {
UInt64(bitPattern: _bigint_to_i64(id, false))
}

public convenience init(_ value: Int64) {
self.init(id: _i64_to_bigint(value, true))
}

public convenience init(unsigned value: UInt64) {
self.init(id: _i64_to_bigint(Int64(bitPattern: value), false))
}

public override init(id: JavaScriptObjectRef) {
override public init(id: JavaScriptObjectRef) {
super.init(id: id)
}

Expand All @@ -38,4 +39,3 @@ public final class JSBigInt: JSObject {
}
}
}
#endif
16 changes: 2 additions & 14 deletions Sources/JavaScriptKit/JSValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public enum JSValue: Equatable {
case undefined
case function(JSFunction)
case symbol(JSSymbol)
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
case bigInt(JSBigInt)
#endif

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

#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
/// Returns the `JSBigInt` of this JS value if its type is function.
/// If not, returns `nil`.
public var bigInt: JSBigInt? {
Expand All @@ -89,7 +86,6 @@ public enum JSValue: Equatable {
default: return nil
}
}
#endif

/// Returns the `true` if this JS value is null.
/// If not, returns `false`.
Expand Down Expand Up @@ -249,12 +245,8 @@ public extension JSValue {
/// - Returns: The result of `instanceof` in the JavaScript environment.
func isInstanceOf(_ constructor: JSFunction) -> Bool {
switch self {
case .boolean, .string, .number, .null, .undefined, .symbol:
case .boolean, .string, .number, .null, .undefined, .symbol, .bigInt:
return false
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
case .bigInt:
return false
#endif
case let .object(ref):
return ref.isInstanceOf(constructor)
case let .function(ref):
Expand All @@ -273,12 +265,8 @@ extension JSValue: CustomStringConvertible {
case let .number(number):
return number.description
case let .object(object), let .function(object as JSObject),
let .symbol(object as JSObject):
return object.toString!().fromJSValue()!
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
case let .bigInt(object as JSObject):
let .symbol(object as JSObject), let .bigInt(object as JSObject):
return object.toString!().fromJSValue()!
#endif
case .null:
return "null"
case .undefined:
Expand Down