Skip to content

Commit 7af5917

Browse files
committed
Move i64 stuff to a separate module
1 parent c54bd10 commit 7af5917

File tree

10 files changed

+67
-54
lines changed

10 files changed

+67
-54
lines changed

Package.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ let package = Package(
77
products: [
88
.library(name: "JavaScriptKit", targets: ["JavaScriptKit"]),
99
.library(name: "JavaScriptEventLoop", targets: ["JavaScriptEventLoop"]),
10+
.library(name: "JavaScriptKit_I64", targets: ["JavaScriptKit_I64"]),
1011
],
1112
targets: [
1213
.target(
1314
name: "JavaScriptKit",
1415
dependencies: ["_CJavaScriptKit"]
1516
),
1617
.target(name: "_CJavaScriptKit"),
18+
.target(
19+
name: "JavaScriptKit_I64",
20+
dependencies: ["_CJavaScriptKit_I64", "JavaScriptKit"]
21+
),
22+
.target(name: "_CJavaScriptKit_I64", dependencies: ["_CJavaScriptKit"]),
1723
.target(
1824
name: "JavaScriptEventLoop",
1925
dependencies: ["JavaScriptKit", "_CJavaScriptEventLoop"]

Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,6 @@ extension UInt32: TypedArrayElement {
135135
public static var typedArrayClass = JSObject.global.Uint32Array.function!
136136
}
137137

138-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
139-
extension Int64: TypedArrayElement {
140-
public static var typedArrayClass = JSObject.global.BigInt64Array.function!
141-
}
142-
extension UInt64: TypedArrayElement {
143-
public static var typedArrayClass = JSObject.global.BigUint64Array.function!
144-
}
145-
#endif
146-
147138
extension Float32: TypedArrayElement {
148139
public static var typedArrayClass = JSObject.global.Float32Array.function!
149140
}

Sources/JavaScriptKit/ConvertibleToJSValue.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ extension UInt32: ConvertibleToJSValue {
6363
public var jsValue: JSValue { .number(Double(self)) }
6464
}
6565

66-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
67-
extension UInt64: ConvertibleToJSValue {
68-
public var jsValue: JSValue { .bigInt(JSBigInt(unsigned: self)) }
69-
}
70-
#endif
7166

7267
extension Int8: ConvertibleToJSValue {
7368
public var jsValue: JSValue { .number(Double(self)) }
@@ -81,12 +76,6 @@ extension Int32: ConvertibleToJSValue {
8176
public var jsValue: JSValue { .number(Double(self)) }
8277
}
8378

84-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
85-
extension Int64: ConvertibleToJSValue {
86-
public var jsValue: JSValue { .bigInt(JSBigInt(self)) }
87-
}
88-
#endif
89-
9079
extension JSString: ConvertibleToJSValue {
9180
public var jsValue: JSValue { .string(self) }
9281
}

Sources/JavaScriptKit/FundamentalObjects/JSBigInt.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,6 @@ import _CJavaScriptKit
33
private let constructor = JSObject.global.BigInt.function!
44

55
public final class JSBigInt: JSObject {
6-
public var int64Value: Int64 {
7-
_bigint_to_i64(id, true)
8-
}
9-
10-
public var uInt64Value: UInt64 {
11-
UInt64(bitPattern: _bigint_to_i64(id, false))
12-
}
13-
14-
public convenience init(_ value: Int64) {
15-
self.init(id: _i64_to_bigint(value, true))
16-
}
17-
18-
public convenience init(unsigned value: UInt64) {
19-
self.init(id: _i64_to_bigint(Int64(bitPattern: value), false))
20-
}
21-
226
@_spi(JSObject_id) override public init(id: JavaScriptObjectRef) {
237
super.init(id: id)
248
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import JavaScriptKit
2+
3+
extension UInt64: ConvertibleToJSValue, TypedArrayElement {
4+
public static var typedArrayClass = JSObject.global.BigUint64Array.function!
5+
6+
public var jsValue: JSValue { .bigInt(JSBigInt(unsigned: self)) }
7+
}
8+
9+
extension Int64: ConvertibleToJSValue, TypedArrayElement {
10+
public static var typedArrayClass = JSObject.global.BigInt64Array.function!
11+
12+
public var jsValue: JSValue { .bigInt(JSBigInt(self)) }
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@_spi(JSObject_id) import JavaScriptKit
2+
import _CJavaScriptKit_I64
3+
4+
public extension JSBigInt {
5+
var int64Value: Int64 {
6+
_bigint_to_i64(id, true)
7+
}
8+
9+
var uInt64Value: UInt64 {
10+
UInt64(bitPattern: _bigint_to_i64(id, false))
11+
}
12+
13+
convenience init(_ value: Int64) {
14+
self.init(id: _i64_to_bigint(value, true))
15+
}
16+
17+
convenience init(unsigned value: UInt64) {
18+
self.init(id: _i64_to_bigint(Int64(bitPattern: value), false))
19+
}
20+
}

Sources/_CJavaScriptKit/include/_CJavaScriptKit.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -301,24 +301,6 @@ __attribute__((__import_module__("javascript_kit"),
301301
extern void _release(const JavaScriptObjectRef ref);
302302

303303

304-
#if !JAVASCRIPTKIT_WITHOUT_BIGINTS
305-
/// Converts the provided Int64 or UInt64 to a BigInt.
306-
///
307-
/// @param value The value to convert.
308-
/// @param is_signed Whether to treat the value as a signed integer or not.
309-
__attribute__((__import_module__("javascript_kit"),
310-
__import_name__("swjs_i64_to_bigint")))
311-
extern JavaScriptObjectRef _i64_to_bigint(const long long value, bool is_signed);
312-
313-
/// Converts the provided BigInt to an Int64 or UInt64.
314-
///
315-
/// @param ref The target JavaScript object.
316-
/// @param is_signed Whether to treat the return value as a signed integer or not.
317-
__attribute__((__import_module__("javascript_kit"),
318-
__import_name__("swjs_bigint_to_i64")))
319-
extern long long _bigint_to_i64(const JavaScriptObjectRef ref, bool is_signed);
320-
#endif
321-
322304
#endif
323305

324306
#endif /* _CJavaScriptKit_h */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// empty file to appease build process
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
#ifndef _CJavaScriptKit_I64_h
3+
#define _CJavaScriptKit_I64_h
4+
5+
#include <_CJavaScriptKit.h>
6+
7+
/// Converts the provided Int64 or UInt64 to a BigInt.
8+
///
9+
/// @param value The value to convert.
10+
/// @param is_signed Whether to treat the value as a signed integer or not.
11+
__attribute__((__import_module__("javascript_kit"),
12+
__import_name__("swjs_i64_to_bigint")))
13+
extern JavaScriptObjectRef _i64_to_bigint(const long long value, bool is_signed);
14+
15+
/// Converts the provided BigInt to an Int64 or UInt64.
16+
///
17+
/// @param ref The target JavaScript object.
18+
/// @param is_signed Whether to treat the return value as a signed integer or not.
19+
__attribute__((__import_module__("javascript_kit"),
20+
__import_name__("swjs_bigint_to_i64")))
21+
extern long long _bigint_to_i64(const JavaScriptObjectRef ref, bool is_signed);
22+
23+
#endif /* _CJavaScriptKit_I64_h */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module _CJavaScriptKit_I64 {
2+
header "_CJavaScriptKit+I64.h"
3+
export *
4+
}

0 commit comments

Comments
 (0)