Skip to content

Commit aef882c

Browse files
Migrate JavaScriptBigIntSupport module
1 parent 1c7e65f commit aef882c

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

Sources/JavaScriptBigIntSupport/JSBigInt+I64.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import _CJavaScriptBigIntSupport
33

44
extension JSBigInt: JSBigIntExtended {
55
public var int64Value: Int64 {
6-
_bigint_to_i64(id, true)
6+
swjs_bigint_to_i64(id, true)
77
}
88

99
public var uInt64Value: UInt64 {
10-
UInt64(bitPattern: _bigint_to_i64(id, false))
10+
UInt64(bitPattern: swjs_bigint_to_i64(id, false))
1111
}
1212

1313
public convenience init(_ value: Int64) {
14-
self.init(id: _i64_to_bigint(value, true))
14+
self.init(id: swjs_i64_to_bigint(value, true))
1515
}
1616

1717
public convenience init(unsigned value: UInt64) {
18-
self.init(id: _i64_to_bigint(Int64(bitPattern: value), false))
18+
self.init(id: swjs_i64_to_bigint(Int64(bitPattern: value), false))
1919
}
2020
}

Sources/JavaScriptBigIntSupport/XcodeSupport.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Sources/_CJavaScriptBigIntSupport/include/_CJavaScriptKit+I64.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@
44

55
#include <_CJavaScriptKit.h>
66

7+
#if __wasm32__
8+
# define IMPORT_JS_FUNCTION(name, returns, args) \
9+
__attribute__((__import_module__("javascript_kit"), __import_name__(#name))) extern returns name args;
10+
#else
11+
# define IMPORT_JS_FUNCTION(name, returns, args) \
12+
static inline returns name args { \
13+
abort(); \
14+
}
15+
#endif
16+
717
/// Converts the provided Int64 or UInt64 to a BigInt.
818
///
919
/// @param value The value to convert.
1020
/// @param is_signed Whether to treat the value as a signed integer or not.
11-
#if __wasi__
12-
__attribute__((__import_module__("javascript_kit"),
13-
__import_name__("swjs_i64_to_bigint")))
14-
#endif
15-
extern JavaScriptObjectRef _i64_to_bigint(const long long value, bool is_signed);
21+
IMPORT_JS_FUNCTION(swjs_i64_to_bigint, JavaScriptObjectRef, (const long long value, bool is_signed))
1622

1723
/// Converts the provided BigInt to an Int64 or UInt64.
1824
///
1925
/// @param ref The target JavaScript object.
2026
/// @param is_signed Whether to treat the return value as a signed integer or not.
21-
#if __wasi__
22-
__attribute__((__import_module__("javascript_kit"),
23-
__import_name__("swjs_bigint_to_i64")))
24-
#endif
25-
extern long long _bigint_to_i64(const JavaScriptObjectRef ref, bool is_signed);
27+
IMPORT_JS_FUNCTION(swjs_bigint_to_i64, long long, (const JavaScriptObjectRef ref, bool is_signed))
2628

2729
#endif /* _CJavaScriptBigIntSupport_h */

0 commit comments

Comments
 (0)