Skip to content

Commit d7e8747

Browse files
committed
Rename unsafe fuctions to no_catch and simplify invokeNonThrowingJSFunction implementation
1 parent baa6678 commit d7e8747

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

Runtime/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export class SwiftRuntime {
226226
this.memory
227227
);
228228
},
229-
swjs_call_function_unsafe: (
229+
swjs_call_function_no_catch: (
230230
ref: ref,
231231
argv: pointer,
232232
argc: number,
@@ -304,7 +304,7 @@ export class SwiftRuntime {
304304
);
305305
},
306306

307-
swjs_call_function_with_this_unsafe: (
307+
swjs_call_function_with_this_no_catch: (
308308
obj_ref: ref,
309309
func_ref: ref,
310310
argv: pointer,

Runtime/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export interface ImportedFunctions {
5858
payload1_ptr: pointer,
5959
payload2_ptr: pointer
6060
): void;
61-
swjs_call_function_unsafe(
61+
swjs_call_function_no_catch(
6262
ref: number,
6363
argv: pointer,
6464
argc: number,
@@ -75,7 +75,7 @@ export interface ImportedFunctions {
7575
payload1_ptr: pointer,
7676
payload2_ptr: pointer
7777
): void;
78-
swjs_call_function_with_this_unsafe(
78+
swjs_call_function_with_this_no_catch(
7979
obj_ref: ref,
8080
func_ref: ref,
8181
argv: pointer,

Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class JSFunction: JSObject {
1919
/// - Returns: The result of this call.
2020
@discardableResult
2121
public func callAsFunction(this: JSObject? = nil, arguments: [ConvertibleToJSValue]) -> JSValue {
22-
try! invokeNonThrowingJSFunction(self, arguments: arguments, this: this)
22+
invokeNonThrowingJSFunction(self, arguments: arguments, this: this)
2323
}
2424

2525
/// A variadic arguments version of `callAsFunction`.
@@ -84,31 +84,27 @@ public class JSFunction: JSObject {
8484
}
8585
}
8686

87-
private func invokeNonThrowingJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleToJSValue], this: JSObject?) throws -> JSValue {
88-
let (result, isException) = arguments.withRawJSValues { rawValues in
89-
rawValues.withUnsafeBufferPointer { bufferPointer -> (JSValue, Bool) in
87+
private func invokeNonThrowingJSFunction(_ jsFunc: JSFunction, arguments: [ConvertibleToJSValue], this: JSObject?) -> JSValue {
88+
arguments.withRawJSValues { rawValues in
89+
rawValues.withUnsafeBufferPointer { bufferPointer -> (JSValue) in
9090
let argv = bufferPointer.baseAddress
9191
let argc = bufferPointer.count
9292
var kindAndFlags = JavaScriptValueKindAndFlags()
9393
var payload1 = JavaScriptPayload1()
9494
var payload2 = JavaScriptPayload2()
9595
if let thisId = this?.id {
96-
_call_function_with_this_unsafe(thisId,
96+
_call_function_with_this_no_catch(thisId,
9797
jsFunc.id, argv, Int32(argc),
9898
&kindAndFlags, &payload1, &payload2)
9999
} else {
100-
_call_function_unsafe(
100+
_call_function_no_catch(
101101
jsFunc.id, argv, Int32(argc),
102102
&kindAndFlags, &payload1, &payload2
103103
)
104104
}
105105
assert(!kindAndFlags.isException)
106106
let result = RawJSValue(kind: kindAndFlags.kind, payload1: payload1, payload2: payload2)
107-
return (result.jsValue(), kindAndFlags.isException)
107+
return result.jsValue()
108108
}
109109
}
110-
if isException {
111-
throw result
112-
}
113-
return result
114110
}

Sources/JavaScriptKit/XcodeSupport.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import _CJavaScriptKit
5353
_: UnsafeMutablePointer<JavaScriptPayload1>!,
5454
_: UnsafeMutablePointer<JavaScriptPayload2>!
5555
) { fatalError() }
56-
func _call_function_unsafe(
56+
func _call_function_no_catch(
5757
_: JavaScriptObjectRef,
5858
_: UnsafePointer<RawJSValue>!, _: Int32,
5959
_: UnsafeMutablePointer<JavaScriptValueKindAndFlags>!,
@@ -68,7 +68,7 @@ import _CJavaScriptKit
6868
_: UnsafeMutablePointer<JavaScriptPayload1>!,
6969
_: UnsafeMutablePointer<JavaScriptPayload2>!
7070
) { fatalError() }
71-
func _call_function_with_this_unsafe(
71+
func _call_function_with_this_no_catch(
7272
_: JavaScriptObjectRef,
7373
_: JavaScriptObjectRef,
7474
_: UnsafePointer<RawJSValue>!, _: Int32,

Sources/_CJavaScriptKit/include/_CJavaScriptKit.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ extern void _call_function(const JavaScriptObjectRef ref, const RawJSValue *argv
179179
/// @param result_payload1 A result pointer of first payload of JavaScript value of returned result or thrown exception.
180180
/// @param result_payload2 A result pointer of second payload of JavaScript value of returned result or thrown exception.
181181
__attribute__((__import_module__("javascript_kit"),
182-
__import_name__("swjs_call_function_unsafe")))
183-
extern void _call_function_unsafe(const JavaScriptObjectRef ref, const RawJSValue *argv,
182+
__import_name__("swjs_call_function_no_catch")))
183+
extern void _call_function_no_catch(const JavaScriptObjectRef ref, const RawJSValue *argv,
184184
const int argc, JavaScriptValueKindAndFlags *result_kind,
185185
JavaScriptPayload1 *result_payload1,
186186
JavaScriptPayload2 *result_payload2);
@@ -213,8 +213,8 @@ extern void _call_function_with_this(const JavaScriptObjectRef _this,
213213
/// @param result_payload1 A result pointer of first payload of JavaScript value of returned result or thrown exception.
214214
/// @param result_payload2 A result pointer of second payload of JavaScript value of returned result or thrown exception.
215215
__attribute__((__import_module__("javascript_kit"),
216-
__import_name__("swjs_call_function_with_this_unsafe")))
217-
extern void _call_function_with_this_unsafe(const JavaScriptObjectRef _this,
216+
__import_name__("swjs_call_function_with_this_no_catch")))
217+
extern void _call_function_with_this_no_catch(const JavaScriptObjectRef _this,
218218
const JavaScriptObjectRef func_ref,
219219
const RawJSValue *argv, const int argc,
220220
JavaScriptValueKindAndFlags *result_kind,

0 commit comments

Comments
 (0)