Skip to content

Commit f668f15

Browse files
Migrate rest of imported functions
1 parent bd81b28 commit f668f15

File tree

11 files changed

+105
-245
lines changed

11 files changed

+105
-245
lines changed

Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
9494
#if compiler(>=5.9)
9595
typealias swift_task_asyncMainDrainQueue_hook_Fn = @convention(thin) (swift_task_asyncMainDrainQueue_original, swift_task_asyncMainDrainQueue_override) -> Void
9696
let swift_task_asyncMainDrainQueue_hook_impl: swift_task_asyncMainDrainQueue_hook_Fn = { _, _ in
97-
_unsafe_event_loop_yield()
97+
swjs_unsafe_event_loop_yield()
9898
}
9999
swift_task_asyncMainDrainQueue_hook = unsafeBitCast(swift_task_asyncMainDrainQueue_hook_impl, to: UnsafeMutableRawPointer?.self)
100100
#endif
@@ -225,8 +225,3 @@ public extension JSPromise {
225225
}
226226

227227
#endif
228-
229-
// See `Sources/JavaScriptKit/XcodeSupport.swift` for rationale of the stub functions.
230-
#if !arch(wasm32)
231-
func _unsafe_event_loop_yield() { fatalError() }
232-
#endif

Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral wh
4747
/// - Parameter array: The array that will be copied to create a new instance of TypedArray
4848
public convenience init(_ array: [Element]) {
4949
let jsArrayRef = array.withUnsafeBufferPointer { ptr in
50-
_create_typed_array(Self.constructor!.id, ptr.baseAddress!, Int32(array.count))
50+
swjs_create_typed_array(Self.constructor!.id, ptr.baseAddress!, Int32(array.count))
5151
}
5252
self.init(unsafelyWrapping: JSObject(id: jsArrayRef))
5353
}
@@ -82,7 +82,7 @@ public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral wh
8282
let rawBuffer = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: bytesLength)
8383
defer { rawBuffer.deallocate() }
8484
let baseAddress = rawBuffer.baseAddress!
85-
_load_typed_array(jsObject.id, baseAddress)
85+
swjs_load_typed_array(jsObject.id, baseAddress)
8686
let length = bytesLength / MemoryLayout<Element>.size
8787
let rawBaseAddress = UnsafeRawPointer(baseAddress)
8888
let bufferPtr = UnsafeBufferPointer<Element>(
@@ -113,7 +113,7 @@ public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral wh
113113
let rawBuffer = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: bytesLength)
114114
defer { rawBuffer.deallocate() }
115115
let baseAddress = rawBuffer.baseAddress!
116-
_load_typed_array(jsObject.id, baseAddress)
116+
swjs_load_typed_array(jsObject.id, baseAddress)
117117
let length = bytesLength / MemoryLayout<Element>.size
118118
let rawBaseAddress = UnsafeRawPointer(baseAddress)
119119
let bufferPtr = UnsafeBufferPointer<Element>(

Sources/JavaScriptKit/FundamentalObjects/JSBigInt.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public final class JSBigInt: JSObject {
1515
/// This doesn't require [JS-BigInt-integration](https://github.com/WebAssembly/JS-BigInt-integration) feature.
1616
public init(_slowBridge value: Int64) {
1717
let value = UInt64(bitPattern: value)
18-
super.init(id: _i64_to_bigint_slow(UInt32(value & 0xffffffff), UInt32(value >> 32), true))
18+
super.init(id: swjs_i64_to_bigint_slow(UInt32(value & 0xffffffff), UInt32(value >> 32), true))
1919
}
2020

2121
/// Instantiate a new `JSBigInt` with given UInt64 value in a slow path
2222
/// This doesn't require [JS-BigInt-integration](https://github.com/WebAssembly/JS-BigInt-integration) feature.
2323
public init(_slowBridge value: UInt64) {
24-
super.init(id: _i64_to_bigint_slow(UInt32(value & 0xffffffff), UInt32(value >> 32), false))
24+
super.init(id: swjs_i64_to_bigint_slow(UInt32(value & 0xffffffff), UInt32(value >> 32), false))
2525
}
2626

2727
override public var jsValue: JSValue {

Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class JSOneshotClosure: JSObject, JSClosureProtocol {
2222
// 2. Create a new JavaScript function which calls the given Swift function.
2323
hostFuncRef = JavaScriptHostFuncRef(bitPattern: ObjectIdentifier(self))
2424
id = withExtendedLifetime(JSString(file)) { file in
25-
_create_function(hostFuncRef, line, file.asInternalJSRef())
25+
swjs_create_function(hostFuncRef, line, file.asInternalJSRef())
2626
}
2727

2828
// 3. Retain the given body in static storage by `funcRef`.
@@ -88,7 +88,7 @@ public class JSClosure: JSFunction, JSClosureProtocol {
8888
// 2. Create a new JavaScript function which calls the given Swift function.
8989
hostFuncRef = JavaScriptHostFuncRef(bitPattern: ObjectIdentifier(self))
9090
id = withExtendedLifetime(JSString(file)) { file in
91-
_create_function(hostFuncRef, line, file.asInternalJSRef())
91+
swjs_create_function(hostFuncRef, line, file.asInternalJSRef())
9292
}
9393

9494
// 3. Retain the given body in static storage by `funcRef`.

Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class JSFunction: JSObject {
5555
public func new(arguments: [ConvertibleToJSValue]) -> JSObject {
5656
arguments.withRawJSValues { rawValues in
5757
rawValues.withUnsafeBufferPointer { bufferPointer in
58-
JSObject(id: _call_new(self.id, bufferPointer.baseAddress!, Int32(bufferPointer.count)))
58+
JSObject(id: swjs_call_new(self.id, bufferPointer.baseAddress!, Int32(bufferPointer.count)))
5959
}
6060
}
6161
}
@@ -101,7 +101,7 @@ public class JSFunction: JSObject {
101101
let argc = bufferPointer.count
102102
var payload1 = JavaScriptPayload1()
103103
var payload2 = JavaScriptPayload2()
104-
let resultBitPattern = _call_function_no_catch(
104+
let resultBitPattern = swjs_call_function_no_catch(
105105
id, argv, Int32(argc),
106106
&payload1, &payload2
107107
)
@@ -121,7 +121,7 @@ public class JSFunction: JSObject {
121121
let argc = bufferPointer.count
122122
var payload1 = JavaScriptPayload1()
123123
var payload2 = JavaScriptPayload2()
124-
let resultBitPattern = _call_function_with_this_no_catch(this.id,
124+
let resultBitPattern = swjs_call_function_with_this_no_catch(this.id,
125125
id, argv, Int32(argc),
126126
&payload1, &payload2
127127
)

Sources/JavaScriptKit/FundamentalObjects/JSObject.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public class JSObject: Equatable {
130130
/// - Parameter constructor: The constructor function to check.
131131
/// - Returns: The result of `instanceof` in the JavaScript environment.
132132
public func isInstanceOf(_ constructor: JSFunction) -> Bool {
133-
_instanceof(id, constructor.id)
133+
swjs_instanceof(id, constructor.id)
134134
}
135135

136136
static let _JS_Predef_Value_Global: JavaScriptObjectRef = 0
@@ -139,7 +139,7 @@ public class JSObject: Equatable {
139139
/// This allows access to the global properties and global names by accessing the `JSObject` returned.
140140
public static let global = JSObject(id: _JS_Predef_Value_Global)
141141

142-
deinit { _release(id) }
142+
deinit { swjs_release(id) }
143143

144144
/// Returns a Boolean value indicating whether two values point to same objects.
145145
///

Sources/JavaScriptKit/FundamentalObjects/JSString.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ public struct JSString: LosslessStringConvertible, Equatable {
2323
lazy var jsRef: JavaScriptObjectRef = {
2424
self.shouldDealocateRef = true
2525
return buffer.withUTF8 { bufferPtr in
26-
return _decode_string(bufferPtr.baseAddress!, Int32(bufferPtr.count))
26+
return swjs_decode_string(bufferPtr.baseAddress!, Int32(bufferPtr.count))
2727
}
2828
}()
2929

3030
lazy var buffer: String = {
3131
var bytesRef: JavaScriptObjectRef = 0
32-
let bytesLength = Int(_encode_string(jsRef, &bytesRef))
32+
let bytesLength = Int(swjs_encode_string(jsRef, &bytesRef))
3333
// +1 for null terminator
3434
let buffer = malloc(Int(bytesLength + 1))!.assumingMemoryBound(to: UInt8.self)
3535
defer {
3636
free(buffer)
37-
_release(bytesRef)
37+
swjs_release(bytesRef)
3838
}
39-
_load_string(bytesRef, buffer)
39+
swjs_load_string(bytesRef, buffer)
4040
buffer[bytesLength] = 0
4141
return String(decodingCString: UnsafePointer(buffer), as: UTF8.self)
4242
}()
@@ -52,7 +52,7 @@ public struct JSString: LosslessStringConvertible, Equatable {
5252

5353
deinit {
5454
guard shouldDealocateRef else { return }
55-
_release(jsRef)
55+
swjs_release(jsRef)
5656
}
5757
}
5858

Sources/JavaScriptKit/FundamentalObjects/JSThrowingFunction.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class JSThrowingFunction {
4444
var exceptionKind = JavaScriptValueKindAndFlags()
4545
var exceptionPayload1 = JavaScriptPayload1()
4646
var exceptionPayload2 = JavaScriptPayload2()
47-
let resultObj = _call_throwing_new(
47+
let resultObj = swjs_call_throwing_new(
4848
self.base.id, argv, Int32(argc),
4949
&exceptionKind, &exceptionPayload1, &exceptionPayload2
5050
)
@@ -73,13 +73,13 @@ private func invokeJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleToJSV
7373
var payload1 = JavaScriptPayload1()
7474
var payload2 = JavaScriptPayload2()
7575
if let thisId = this?.id {
76-
let resultBitPattern = _call_function_with_this(
76+
let resultBitPattern = swjs_call_function_with_this(
7777
thisId, id, argv, Int32(argc),
7878
&payload1, &payload2
7979
)
8080
kindAndFlags = unsafeBitCast(resultBitPattern, to: JavaScriptValueKindAndFlags.self)
8181
} else {
82-
let resultBitPattern = _call_function(
82+
let resultBitPattern = swjs_call_function(
8383
id, argv, Int32(argc),
8484
&payload1, &payload2
8585
)

Sources/JavaScriptKit/JSValue.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ extension JSValue: ExpressibleByNilLiteral {
196196

197197
public func getJSValue(this: JSObject, name: JSString) -> JSValue {
198198
var rawValue = RawJSValue()
199-
let rawBitPattern = _get_prop(
199+
let rawBitPattern = swjs_get_prop(
200200
this.id, name.asInternalJSRef(),
201201
&rawValue.payload1, &rawValue.payload2
202202
)
@@ -212,7 +212,7 @@ public func setJSValue(this: JSObject, name: JSString, value: JSValue) {
212212

213213
public func getJSValue(this: JSObject, index: Int32) -> JSValue {
214214
var rawValue = RawJSValue()
215-
let rawBitPattern = _get_subscript(
215+
let rawBitPattern = swjs_get_subscript(
216216
this.id, index,
217217
&rawValue.payload1, &rawValue.payload2
218218
)
@@ -222,15 +222,15 @@ public func getJSValue(this: JSObject, index: Int32) -> JSValue {
222222

223223
public func setJSValue(this: JSObject, index: Int32, value: JSValue) {
224224
value.withRawJSValue { rawValue in
225-
_set_subscript(this.id, index,
225+
swjs_set_subscript(this.id, index,
226226
rawValue.kind,
227227
rawValue.payload1, rawValue.payload2)
228228
}
229229
}
230230

231231
public func getJSValue(this: JSObject, symbol: JSSymbol) -> JSValue {
232232
var rawValue = RawJSValue()
233-
let rawBitPattern = _get_prop(
233+
let rawBitPattern = swjs_get_prop(
234234
this.id, symbol.id,
235235
&rawValue.payload1, &rawValue.payload2
236236
)
-94
Original file line numberDiff line numberDiff line change
@@ -1,95 +1 @@
1-
import _CJavaScriptKit
21

3-
/// Note:
4-
/// Define stubs for runtime functions which are usually imported from JavaScript environment.
5-
/// JavaScriptKit itself supports only WebAssembly target, but it should be able
6-
/// to be built for host platforms like macOS or Linux for tentative IDE support.
7-
/// (ideally, IDE should build for WebAssembly target though)
8-
#if !arch(wasm32)
9-
func _get_prop(
10-
_: JavaScriptObjectRef,
11-
_: JavaScriptObjectRef,
12-
_: UnsafeMutablePointer<JavaScriptPayload1>!,
13-
_: UnsafeMutablePointer<JavaScriptPayload2>!
14-
) -> UInt32 { fatalError() }
15-
func _set_subscript(
16-
_: JavaScriptObjectRef,
17-
_: Int32,
18-
_: JavaScriptValueKind,
19-
_: JavaScriptPayload1,
20-
_: JavaScriptPayload2
21-
) { fatalError() }
22-
func _get_subscript(
23-
_: JavaScriptObjectRef,
24-
_: Int32,
25-
_: UnsafeMutablePointer<JavaScriptPayload1>!,
26-
_: UnsafeMutablePointer<JavaScriptPayload2>!
27-
) -> UInt32 { fatalError() }
28-
func _encode_string(
29-
_: JavaScriptObjectRef,
30-
_: UnsafeMutablePointer<JavaScriptObjectRef>!
31-
) -> Int32 { fatalError() }
32-
func _decode_string(
33-
_: UnsafePointer<UInt8>!,
34-
_: Int32
35-
) -> JavaScriptObjectRef { fatalError() }
36-
func _load_string(
37-
_: JavaScriptObjectRef,
38-
_: UnsafeMutablePointer<UInt8>!
39-
) { fatalError() }
40-
func _i64_to_bigint_slow(
41-
_: UInt32, _: UInt32, _: Bool
42-
) -> JavaScriptObjectRef { fatalError() }
43-
func _call_function(
44-
_: JavaScriptObjectRef,
45-
_: UnsafePointer<RawJSValue>!, _: Int32,
46-
_: UnsafeMutablePointer<JavaScriptPayload1>!,
47-
_: UnsafeMutablePointer<JavaScriptPayload2>!
48-
) -> UInt32 { fatalError() }
49-
func _call_function_no_catch(
50-
_: JavaScriptObjectRef,
51-
_: UnsafePointer<RawJSValue>!, _: Int32,
52-
_: UnsafeMutablePointer<JavaScriptPayload1>!,
53-
_: UnsafeMutablePointer<JavaScriptPayload2>!
54-
) -> UInt32 { fatalError() }
55-
func _call_function_with_this(
56-
_: JavaScriptObjectRef,
57-
_: JavaScriptObjectRef,
58-
_: UnsafePointer<RawJSValue>!, _: Int32,
59-
_: UnsafeMutablePointer<JavaScriptPayload1>!,
60-
_: UnsafeMutablePointer<JavaScriptPayload2>!
61-
) -> UInt32 { fatalError() }
62-
func _call_function_with_this_no_catch(
63-
_: JavaScriptObjectRef,
64-
_: JavaScriptObjectRef,
65-
_: UnsafePointer<RawJSValue>!, _: Int32,
66-
_: UnsafeMutablePointer<JavaScriptPayload1>!,
67-
_: UnsafeMutablePointer<JavaScriptPayload2>!
68-
) -> UInt32 { fatalError() }
69-
func _call_new(
70-
_: JavaScriptObjectRef,
71-
_: UnsafePointer<RawJSValue>!, _: Int32
72-
) -> JavaScriptObjectRef { fatalError() }
73-
func _call_throwing_new(
74-
_: JavaScriptObjectRef,
75-
_: UnsafePointer<RawJSValue>!, _: Int32,
76-
_: UnsafeMutablePointer<JavaScriptValueKindAndFlags>!,
77-
_: UnsafeMutablePointer<JavaScriptPayload1>!,
78-
_: UnsafeMutablePointer<JavaScriptPayload2>!
79-
) -> JavaScriptObjectRef { fatalError() }
80-
func _instanceof(
81-
_: JavaScriptObjectRef,
82-
_: JavaScriptObjectRef
83-
) -> Bool { fatalError() }
84-
func _create_function(_: JavaScriptHostFuncRef, _: UInt32, _: JavaScriptObjectRef) -> JavaScriptObjectRef { fatalError() }
85-
func _create_typed_array<T: TypedArrayElement>(
86-
_: JavaScriptObjectRef,
87-
_: UnsafePointer<T>,
88-
_: Int32
89-
) -> JavaScriptObjectRef { fatalError() }
90-
func _load_typed_array(
91-
_: JavaScriptObjectRef,
92-
_: UnsafeMutablePointer<UInt8>!
93-
) { fatalError() }
94-
func _release(_: JavaScriptObjectRef) { fatalError() }
95-
#endif

0 commit comments

Comments
 (0)