Skip to content

Commit 356d48e

Browse files
Merge pull request #171 from swiftwasm/katei/add-availability-attr
Use availability guarded APIs under @available for Xcode development
2 parents d2f0765 + bc8557c commit 356d48e

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

.github/workflows/test.yml

+9
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ jobs:
2626
SWIFT_VERSION=${{ matrix.toolchain }} make bootstrap
2727
echo ${{ matrix.toolchain }} > .swift-version
2828
make test
29+
native-build:
30+
# Check native build to make it easy to develop applications by Xcode
31+
name: Build for native target
32+
runs-on: macos-11
33+
steps:
34+
- uses: actions/checkout@v2
35+
- run: swift build
36+
env:
37+
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer/

Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import JavaScriptKit
22
import _CJavaScriptEventLoop
33

4+
// NOTE: `@available` annotations are semantically wrong, but they make it easier to develop applications targeting WebAssembly in Xcode.
5+
46
#if compiler(>=5.5)
57

8+
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
69
public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
710

811
/// A function that queues a given closure as a microtask into JavaScript event loop.
@@ -94,6 +97,7 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
9497
}
9598
}
9699

100+
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
97101
public extension JSPromise {
98102
/// Wait for the promise to complete, returning (or throwing) its result.
99103
var value: JSValue {

Sources/JavaScriptEventLoop/JobQueue.swift

+4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import _CJavaScriptEventLoop
66

77
#if compiler(>=5.5)
8+
9+
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
810
struct QueueState: Sendable {
911
fileprivate var headJob: UnownedJob? = nil
1012
fileprivate var isSpinning: Bool = false
1113
}
1214

15+
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
1316
extension JavaScriptEventLoop {
1417

1518
func insertJobQueue(job newJob: UnownedJob) {
@@ -55,6 +58,7 @@ extension JavaScriptEventLoop {
5558
}
5659
}
5760

61+
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
5862
fileprivate extension UnownedJob {
5963
private func asImpl() -> UnsafeMutablePointer<_CJavaScriptEventLoop.Job> {
6064
unsafeBitCast(self, to: UnsafeMutablePointer<_CJavaScriptEventLoop.Job>.self)

0 commit comments

Comments
 (0)