Skip to content

Commit 6e62619

Browse files
authored
Add missing doc comments for more types (#208)
I noticed that some of our types had no doc comments or had inconsistent formatting, here's a (potentially incomplete) fix for that.
1 parent 9b865b2 commit 6e62619

File tree

8 files changed

+49
-8
lines changed

8 files changed

+49
-8
lines changed

Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@ import _CJavaScriptEventLoop
55

66
#if compiler(>=5.5)
77

8+
/** Singleton type responsible for integrating JavaScript event loop as a Swift concurrency executor, conforming to
9+
`SerialExecutor` protocol from the standard library. To utilize it:
10+
11+
1. Make sure that your target depends on `JavaScriptEventLoop` in your `Packages.swift`:
12+
13+
```swift
14+
.target(
15+
name: "JavaScriptKitExample",
16+
dependencies: [
17+
"JavaScriptKit",
18+
.product(name: "JavaScriptEventLoop", package: "JavaScriptKit")
19+
]
20+
)
21+
```
22+
23+
2. Add an explicit import in the code that executes **before* you start using `await` and/or `Task`
24+
APIs (most likely in `main.swift`):
25+
26+
```swift
27+
import JavaScriptEventLoop
28+
```
29+
30+
3. Run this function **before* you start using `await` and/or `Task` APIs (again, most likely in
31+
`main.swift`):
32+
33+
```swift
34+
JavaScriptEventLoop.installGlobalExecutor()
35+
```
36+
*/
837
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
938
public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
1039

Sources/JavaScriptKit/BasicObjects/JSArray.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/// A wrapper around [the JavaScript Array class](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
1+
/// A wrapper around [the JavaScript `Array`
2+
/// class](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
23
/// that exposes its properties in a type-safe and Swifty way.
34
public class JSArray: JSBridgedClass {
45
public static let constructor = JSObject.global.Array.function
@@ -35,6 +36,8 @@ extension JSArray: RandomAccessCollection {
3536
Iterator(jsObject: jsObject)
3637
}
3738

39+
/// Iterator type for `JSArray`, conforming to `IteratorProtocol` from the standard library, which allows
40+
/// easy iteration over elements of `JSArray` instances.
3841
public class Iterator: IteratorProtocol {
3942
private let jsObject: JSObject
4043
private var index = 0

Sources/JavaScriptKit/BasicObjects/JSDate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** A wrapper around the [JavaScript Date
1+
/** A wrapper around the [JavaScript `Date`
22
class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) that
33
exposes its properties in a type-safe way. This doesn't 100% match the JS API, for example
44
`getMonth`/`setMonth` etc accessor methods are converted to properties, but the rest of it matches

Sources/JavaScriptKit/BasicObjects/JSError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** A wrapper around [the JavaScript Error
1+
/** A wrapper around [the JavaScript `Error`
22
class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) that
33
exposes its properties in a type-safe way.
44
*/

Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public protocol TypedArrayElement: ConvertibleToJSValue, ConstructibleFromJSValu
1010
static var typedArrayClass: JSFunction { get }
1111
}
1212

13-
/// A wrapper around all JavaScript [TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
14-
/// classes that exposes their properties in a type-safe way.
13+
/// A wrapper around all [JavaScript `TypedArray`(https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
14+
/// classes] that exposes their properties in a type-safe way.
1515
public class JSTypedArray<Element>: JSBridgedClass, ExpressibleByArrayLiteral where Element: TypedArrayElement {
1616
public class var constructor: JSFunction? { Element.typedArrayClass }
1717
public var jsObject: JSObject
@@ -120,6 +120,9 @@ extension UInt8: TypedArrayElement {
120120
public static var typedArrayClass = JSObject.global.Uint8Array.function!
121121
}
122122

123+
/// A wrapper around [the JavaScript `Uint8ClampedArray`
124+
/// class](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
125+
/// that exposes its properties in a type-safe and Swifty way.
123126
public class JSUInt8ClampedArray: JSTypedArray<UInt8> {
124127
override public class var constructor: JSFunction? { JSObject.global.Uint8ClampedArray.function! }
125128
}

Sources/JavaScriptKit/FundamentalObjects/JSBigInt.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import _CJavaScriptKit
22

33
private let constructor = JSObject.global.BigInt.function!
44

5+
/// A wrapper around [the JavaScript `BigInt`
6+
/// class](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
7+
/// that exposes its properties in a type-safe and Swifty way.
58
public final class JSBigInt: JSObject {
69
@_spi(JSObject_id)
710
override public init(id: JavaScriptObjectRef) {

Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _CJavaScriptKit
22

3-
/// JSClosureProtocol wraps Swift closure objects for use in JavaScript. Conforming types
3+
/// `JSClosureProtocol` wraps Swift closure objects for use in JavaScript. Conforming types
44
/// are responsible for managing the lifetime of the closure they wrap, but can delegate that
55
/// task to the user by requiring an explicit `release()` call.
66
public protocol JSClosureProtocol: JSValueCompatible {
@@ -10,8 +10,8 @@ public protocol JSClosureProtocol: JSValueCompatible {
1010
func release()
1111
}
1212

13-
14-
/// `JSOneshotClosure` is a JavaScript function that can be called only once.
13+
/// `JSOneshotClosure` is a JavaScript function that can be called only once. This class can be used
14+
/// for optimized memory management when compared to the common `JSClosure`.
1515
public class JSOneshotClosure: JSObject, JSClosureProtocol {
1616
private var hostFuncRef: JavaScriptHostFuncRef = 0
1717

Sources/JavaScriptKit/FundamentalObjects/JSSymbol.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import _CJavaScriptKit
22

33
private let Symbol = JSObject.global.Symbol.function!
44

5+
/// A wrapper around [the JavaScript `Symbol`
6+
/// class](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
7+
/// that exposes its properties in a type-safe and Swifty way.
58
public class JSSymbol: JSObject {
69
public var name: String? { self["description"].string }
710

0 commit comments

Comments
 (0)