Skip to content

Commit 8cc56bf

Browse files
Remove all unsafe linker flags from Package.swift
1 parent 8f8b38c commit 8cc56bf

File tree

7 files changed

+37
-92
lines changed

7 files changed

+37
-92
lines changed

.swift-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
wasm-5.3-SNAPSHOT-2020-08-10-a
1+
wasm-5.3-SNAPSHOT-2020-10-02-a

Package.swift

+3-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.2
22

33
import PackageDescription
44

@@ -10,34 +10,8 @@ let package = Package(
1010
targets: [
1111
.target(
1212
name: "JavaScriptKit",
13-
dependencies: ["_CJavaScriptKit"],
14-
linkerSettings: [
15-
.unsafeFlags(
16-
[
17-
"-Xlinker",
18-
"--export=swjs_call_host_function",
19-
"-Xlinker",
20-
"--export=swjs_prepare_host_function_call",
21-
"-Xlinker",
22-
"--export=swjs_cleanup_host_function_call",
23-
"-Xlinker",
24-
"--export=swjs_library_version",
25-
],
26-
.when(platforms: [.wasi])
27-
),
28-
]
29-
),
30-
.target(
31-
name: "_CJavaScriptKit",
32-
linkerSettings: [
33-
.unsafeFlags(
34-
[
35-
"-Xlinker",
36-
"--allow-undefined",
37-
],
38-
.when(platforms: [.wasi])
39-
),
40-
]
13+
dependencies: ["_CJavaScriptKit"]
4114
),
15+
.target(name: "_CJavaScriptKit"),
4216
]
4317
)

[email protected]

-41
This file was deleted.

Sources/JavaScriptKit/Compatibility.swift

-7
This file was deleted.

Sources/JavaScriptKit/FundamentalObjects/JSFunction.swift

+2-13
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,8 @@ public class JSClosure: JSFunction {
190190
// │ │ │
191191
// └─────────────────────┴──────────────────────────┘
192192

193-
@_cdecl("swjs_prepare_host_function_call")
194-
func _prepare_host_function_call(_ argc: Int32) -> UnsafeMutableRawPointer {
195-
let argumentSize = MemoryLayout<RawJSValue>.size * Int(argc)
196-
return malloc(Int(argumentSize))!
197-
}
198-
199-
@_cdecl("swjs_cleanup_host_function_call")
200-
func _cleanup_host_function_call(_ pointer: UnsafeMutableRawPointer) {
201-
free(pointer)
202-
}
203-
204-
@_cdecl("swjs_call_host_function")
205-
func _call_host_function(
193+
@_cdecl("_call_host_function_impl")
194+
func _call_host_function_impl(
206195
_ hostFuncRef: JavaScriptHostFuncRef,
207196
_ argv: UnsafePointer<RawJSValue>, _ argc: Int32,
208197
_ callbackFuncRef: JavaScriptObjectRef
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "_CJavaScriptKit.h"
2+
#include <stdlib.h>
3+
4+
void _call_host_function_impl(const JavaScriptHostFuncRef host_func_ref,
5+
const RawJSValue *argv, const int argc,
6+
const JavaScriptObjectRef callback_func);
7+
8+
__attribute__((export_name("swjs_call_host_function")))
9+
void _call_host_function(const JavaScriptHostFuncRef host_func_ref,
10+
const RawJSValue *argv, const int argc,
11+
const JavaScriptObjectRef callback_func) {
12+
_call_host_function_impl(host_func_ref, argv, argc, callback_func);
13+
}
14+
15+
__attribute__((export_name("swjs_prepare_host_function_call")))
16+
void *_prepare_host_function_call(const int argc) {
17+
return malloc(argc * sizeof(RawJSValue));
18+
}
19+
20+
__attribute__((export_name("swjs_cleanup_host_function_call")))
21+
void _cleanup_host_function_call(void *argv_buffer) {
22+
free(argv_buffer);
23+
}
24+
25+
/// The compatibility runtime library version.
26+
/// Notes: If you change any interface of runtime library, please increment
27+
/// this and `SwiftRuntime.version` in `./Runtime/src/index.ts`.
28+
__attribute__((export_name("swjs_library_version")))
29+
int _library_version() {
30+
return 700;
31+
}

Sources/_CJavaScriptKit/dummy.c

-1
This file was deleted.

0 commit comments

Comments
 (0)