Skip to content

Commit f72b207

Browse files
Add JavaScriptEventLoopTestSupport module to install executor
1 parent e9422fe commit f72b207

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

Package.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,13 @@ let package = Package(
2626
dependencies: ["JavaScriptKit", "_CJavaScriptEventLoop"]
2727
),
2828
.target(name: "_CJavaScriptEventLoop"),
29+
.target(
30+
name: "JavaScriptEventLoopTestSupport",
31+
dependencies: [
32+
"_CJavaScriptEventLoopTestSupport",
33+
.product(name: "JavaScriptEventLoop", package: "JavaScriptKit"),
34+
]
35+
),
36+
.target(name: "_CJavaScriptEventLoopTestSupport"),
2937
]
3038
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This module just expose 'JavaScriptEventLoop.installGlobalExecutor' to C ABI
2+
// See _CJavaScriptEventLoopTestSupport.c for why this is needed
3+
4+
import JavaScriptEventLoop
5+
6+
@_cdecl("swift_javascriptkit_activate_js_executor_impl")
7+
func swift_javascriptkit_activate_js_executor_impl() {
8+
JavaScriptEventLoop.installGlobalExecutor()
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This 'ctor' function is called at startup time of this program.
2+
// It's invoked by '_start' of command-line or '_initialize' of reactor.
3+
// This ctor activate the event loop based global executor automatically
4+
// before running the test cases. For general applications, applications
5+
// have to activate the event loop manually on their responsibility.
6+
// However, XCTest framework doesn't provide a way to run arbitrary code
7+
// before running all of the test suites. So, we have to do it here.
8+
//
9+
// See also: https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md#current-unstable-abi
10+
11+
extern void swift_javascriptkit_activate_js_executor_impl(void);
12+
13+
// priority 0~100 is reserved by wasi-libc
14+
// https://github.com/WebAssembly/wasi-libc/blob/30094b6ed05f19cee102115215863d185f2db4f0/libc-bottom-half/sources/environ.c#L20
15+
__attribute__((constructor(/* priority */ 200)))
16+
void swift_javascriptkit_activate_js_executor(void) {
17+
swift_javascriptkit_activate_js_executor_impl();
18+
}
19+

Sources/_CJavaScriptEventLoopTestSupport/include/dummy.h

Whitespace-only changes.

0 commit comments

Comments
 (0)