Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use availability guarded APIs under @available for Xcode development #171

Merged
merged 2 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ jobs:
SWIFT_VERSION=${{ matrix.toolchain }} make bootstrap
echo ${{ matrix.toolchain }} > .swift-version
make test
native-build:
# Check native build to make it easy to develop applications by Xcode
name: Build for native target
runs-on: macos-11
steps:
- uses: actions/checkout@v2
- run: swift build
env:
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer/
4 changes: 4 additions & 0 deletions Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import JavaScriptKit
import _CJavaScriptEventLoop

// NOTE: `@available` annotations are semantically wrong, but they make it easier to develop applications targeting WebAssembly in Xcode.

#if compiler(>=5.5)

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

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

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
public extension JSPromise {
/// Wait for the promise to complete, returning (or throwing) its result.
var value: JSValue {
Expand Down
4 changes: 4 additions & 0 deletions Sources/JavaScriptEventLoop/JobQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import _CJavaScriptEventLoop

#if compiler(>=5.5)

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
struct QueueState: Sendable {
fileprivate var headJob: UnownedJob? = nil
fileprivate var isSpinning: Bool = false
}

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

func insertJobQueue(job newJob: UnownedJob) {
Expand Down Expand Up @@ -55,6 +58,7 @@ extension JavaScriptEventLoop {
}
}

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