Skip to content

Add streams IDL spec and generated code #15

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

Merged
merged 1 commit into from
May 2, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/*.xcodeproj
xcuserdata/
node_modules
.vscode
.swiftpm
7 changes: 0 additions & 7 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

This file was deleted.

This file was deleted.

26 changes: 26 additions & 0 deletions Sources/DOMKit/WebIDL/ByteLengthQueuingStrategy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!

import JavaScriptEventLoop
import JavaScriptKit

public class ByteLengthQueuingStrategy: JSBridgedClass {
@inlinable public class var constructor: JSFunction { JSObject.global[Strings.ByteLengthQueuingStrategy].function! }

public let jsObject: JSObject

public required init(unsafelyWrapping jsObject: JSObject) {
_highWaterMark = ReadonlyAttribute(jsObject: jsObject, name: Strings.highWaterMark)
_size = ReadonlyAttribute(jsObject: jsObject, name: Strings.size)
self.jsObject = jsObject
}

@inlinable public convenience init(init: QueuingStrategyInit) {
self.init(unsafelyWrapping: Self.constructor.new(arguments: [`init`.jsValue]))
}

@ReadonlyAttribute
public var highWaterMark: Double

@ReadonlyAttribute
public var size: JSFunction
}
128 changes: 128 additions & 0 deletions Sources/DOMKit/WebIDL/ClosureAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,70 @@ import JavaScriptEventLoop
import JavaScriptKit

/* variadic generics please */
@propertyWrapper public final class ClosureAttribute0<ReturnType>
where ReturnType: JSValueCompatible
{
@usableFromInline let jsObject: JSObject
@usableFromInline let name: JSString

public init(jsObject: JSObject, name: JSString) {
self.jsObject = jsObject
self.name = name
}

@inlinable public var wrappedValue: () -> ReturnType {
get { ClosureAttribute0[name, in: jsObject] }
set { ClosureAttribute0[name, in: jsObject] = newValue }
}

@inlinable public static subscript(name: JSString, in jsObject: JSObject) -> () -> ReturnType {
get {
let function = jsObject[name].function!
return { function().fromJSValue()! }
}
set {
jsObject[name] = JSClosure { _ in
newValue().jsValue
}.jsValue
}
}
}

@propertyWrapper public final class ClosureAttribute0Optional<ReturnType>
where ReturnType: JSValueCompatible
{
@usableFromInline let jsObject: JSObject
@usableFromInline let name: JSString

public init(jsObject: JSObject, name: JSString) {
self.jsObject = jsObject
self.name = name
}

@inlinable public var wrappedValue: (() -> ReturnType)? {
get { ClosureAttribute0Optional[name, in: jsObject] }
set { ClosureAttribute0Optional[name, in: jsObject] = newValue }
}

@inlinable public static subscript(name: JSString, in jsObject: JSObject) -> (() -> ReturnType)? {
get {
guard let function = jsObject[name].function else {
return nil
}
return { function().fromJSValue()! }
}
set {
if let newValue = newValue {
jsObject[name] = JSClosure { _ in
newValue().jsValue
}.jsValue
} else {
jsObject[name] = .null
}
}
}
}

@propertyWrapper public final class ClosureAttribute0OptionalVoid {
@usableFromInline let jsObject: JSObject
@usableFromInline let name: JSString
Expand Down Expand Up @@ -196,6 +260,70 @@ import JavaScriptKit
}
}

@propertyWrapper public final class ClosureAttribute2<A0, A1, ReturnType>
where A0: JSValueCompatible, A1: JSValueCompatible, ReturnType: JSValueCompatible
{
@usableFromInline let jsObject: JSObject
@usableFromInline let name: JSString

public init(jsObject: JSObject, name: JSString) {
self.jsObject = jsObject
self.name = name
}

@inlinable public var wrappedValue: (A0, A1) -> ReturnType {
get { ClosureAttribute2[name, in: jsObject] }
set { ClosureAttribute2[name, in: jsObject] = newValue }
}

@inlinable public static subscript(name: JSString, in jsObject: JSObject) -> (A0, A1) -> ReturnType {
get {
let function = jsObject[name].function!
return { function($0.jsValue, $1.jsValue).fromJSValue()! }
}
set {
jsObject[name] = JSClosure {
newValue($0[0].fromJSValue()!, $0[1].fromJSValue()!).jsValue
}.jsValue
}
}
}

@propertyWrapper public final class ClosureAttribute2Optional<A0, A1, ReturnType>
where A0: JSValueCompatible, A1: JSValueCompatible, ReturnType: JSValueCompatible
{
@usableFromInline let jsObject: JSObject
@usableFromInline let name: JSString

public init(jsObject: JSObject, name: JSString) {
self.jsObject = jsObject
self.name = name
}

@inlinable public var wrappedValue: ((A0, A1) -> ReturnType)? {
get { ClosureAttribute2Optional[name, in: jsObject] }
set { ClosureAttribute2Optional[name, in: jsObject] = newValue }
}

@inlinable public static subscript(name: JSString, in jsObject: JSObject) -> ((A0, A1) -> ReturnType)? {
get {
guard let function = jsObject[name].function else {
return nil
}
return { function($0.jsValue, $1.jsValue).fromJSValue()! }
}
set {
if let newValue = newValue {
jsObject[name] = JSClosure {
newValue($0[0].fromJSValue()!, $0[1].fromJSValue()!).jsValue
}.jsValue
} else {
jsObject[name] = .null
}
}
}
}

@propertyWrapper public final class ClosureAttribute2OptionalVoid<A0, A1>
where A0: JSValueCompatible, A1: JSValueCompatible
{
Expand Down
26 changes: 26 additions & 0 deletions Sources/DOMKit/WebIDL/CountQueuingStrategy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!

import JavaScriptEventLoop
import JavaScriptKit

public class CountQueuingStrategy: JSBridgedClass {
@inlinable public class var constructor: JSFunction { JSObject.global[Strings.CountQueuingStrategy].function! }

public let jsObject: JSObject

public required init(unsafelyWrapping jsObject: JSObject) {
_highWaterMark = ReadonlyAttribute(jsObject: jsObject, name: Strings.highWaterMark)
_size = ReadonlyAttribute(jsObject: jsObject, name: Strings.size)
self.jsObject = jsObject
}

@inlinable public convenience init(init: QueuingStrategyInit) {
self.init(unsafelyWrapping: Self.constructor.new(arguments: [`init`.jsValue]))
}

@ReadonlyAttribute
public var highWaterMark: Double

@ReadonlyAttribute
public var size: JSFunction
}
11 changes: 11 additions & 0 deletions Sources/DOMKit/WebIDL/GenericTransformStream.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!

import JavaScriptEventLoop
import JavaScriptKit

public protocol GenericTransformStream: JSBridgedClass {}
public extension GenericTransformStream {
@inlinable var readable: ReadableStream { ReadonlyAttribute[Strings.readable, in: jsObject] }

@inlinable var writable: WritableStream { ReadonlyAttribute[Strings.writable, in: jsObject] }
}
25 changes: 25 additions & 0 deletions Sources/DOMKit/WebIDL/QueuingStrategy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!

import JavaScriptEventLoop
import JavaScriptKit

public class QueuingStrategy: BridgedDictionary {
public convenience init(highWaterMark: Double, size: @escaping QueuingStrategySize) {
let object = JSObject.global[Strings.Object].function!.new()
object[Strings.highWaterMark] = highWaterMark.jsValue
ClosureAttribute1[Strings.size, in: object] = size
self.init(unsafelyWrapping: object)
}

public required init(unsafelyWrapping object: JSObject) {
_highWaterMark = ReadWriteAttribute(jsObject: object, name: Strings.highWaterMark)
_size = ClosureAttribute1(jsObject: object, name: Strings.size)
super.init(unsafelyWrapping: object)
}

@ReadWriteAttribute
public var highWaterMark: Double

@ClosureAttribute1
public var size: QueuingStrategySize
}
20 changes: 20 additions & 0 deletions Sources/DOMKit/WebIDL/QueuingStrategyInit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!

import JavaScriptEventLoop
import JavaScriptKit

public class QueuingStrategyInit: BridgedDictionary {
public convenience init(highWaterMark: Double) {
let object = JSObject.global[Strings.Object].function!.new()
object[Strings.highWaterMark] = highWaterMark.jsValue
self.init(unsafelyWrapping: object)
}

public required init(unsafelyWrapping object: JSObject) {
_highWaterMark = ReadWriteAttribute(jsObject: object, name: Strings.highWaterMark)
super.init(unsafelyWrapping: object)
}

@ReadWriteAttribute
public var highWaterMark: Double
}
37 changes: 37 additions & 0 deletions Sources/DOMKit/WebIDL/ReadableByteStreamController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!

import JavaScriptEventLoop
import JavaScriptKit

public class ReadableByteStreamController: JSBridgedClass {
@inlinable public class var constructor: JSFunction { JSObject.global[Strings.ReadableByteStreamController].function! }

public let jsObject: JSObject

public required init(unsafelyWrapping jsObject: JSObject) {
_byobRequest = ReadonlyAttribute(jsObject: jsObject, name: Strings.byobRequest)
_desiredSize = ReadonlyAttribute(jsObject: jsObject, name: Strings.desiredSize)
self.jsObject = jsObject
}

@ReadonlyAttribute
public var byobRequest: ReadableStreamBYOBRequest?

@ReadonlyAttribute
public var desiredSize: Double?

@inlinable public func close() {
let this = jsObject
_ = this[Strings.close].function!(this: this, arguments: [])
}

@inlinable public func enqueue(chunk: ArrayBufferView) {
let this = jsObject
_ = this[Strings.enqueue].function!(this: this, arguments: [chunk.jsValue])
}

@inlinable public func error(e: JSValue? = nil) {
let this = jsObject
_ = this[Strings.error].function!(this: this, arguments: [e?.jsValue ?? .undefined])
}
}
67 changes: 67 additions & 0 deletions Sources/DOMKit/WebIDL/ReadableStream.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!

import JavaScriptEventLoop
import JavaScriptKit

public class ReadableStream: JSBridgedClass, AsyncSequence {
@inlinable public class var constructor: JSFunction { JSObject.global[Strings.ReadableStream].function! }

public let jsObject: JSObject

public required init(unsafelyWrapping jsObject: JSObject) {
_locked = ReadonlyAttribute(jsObject: jsObject, name: Strings.locked)
self.jsObject = jsObject
}

@inlinable public convenience init(underlyingSource: JSObject? = nil, strategy: QueuingStrategy? = nil) {
self.init(unsafelyWrapping: Self.constructor.new(arguments: [underlyingSource?.jsValue ?? .undefined, strategy?.jsValue ?? .undefined]))
}

@ReadonlyAttribute
public var locked: Bool

@inlinable public func cancel(reason: JSValue? = nil) -> JSPromise {
let this = jsObject
return this[Strings.cancel].function!(this: this, arguments: [reason?.jsValue ?? .undefined]).fromJSValue()!
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@inlinable public func cancel(reason: JSValue? = nil) async throws {
let this = jsObject
let _promise: JSPromise = this[Strings.cancel].function!(this: this, arguments: [reason?.jsValue ?? .undefined]).fromJSValue()!
_ = try await _promise.value
}

@inlinable public func getReader(options: ReadableStreamGetReaderOptions? = nil) -> ReadableStreamReader {
let this = jsObject
return this[Strings.getReader].function!(this: this, arguments: [options?.jsValue ?? .undefined]).fromJSValue()!
}

@inlinable public func pipeThrough(transform: ReadableWritablePair, options: StreamPipeOptions? = nil) -> Self {
let this = jsObject
return this[Strings.pipeThrough].function!(this: this, arguments: [transform.jsValue, options?.jsValue ?? .undefined]).fromJSValue()!
}

@inlinable public func pipeTo(destination: WritableStream, options: StreamPipeOptions? = nil) -> JSPromise {
let this = jsObject
return this[Strings.pipeTo].function!(this: this, arguments: [destination.jsValue, options?.jsValue ?? .undefined]).fromJSValue()!
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@inlinable public func pipeTo(destination: WritableStream, options: StreamPipeOptions? = nil) async throws {
let this = jsObject
let _promise: JSPromise = this[Strings.pipeTo].function!(this: this, arguments: [destination.jsValue, options?.jsValue ?? .undefined]).fromJSValue()!
_ = try await _promise.value
}

@inlinable public func tee() -> [ReadableStream] {
let this = jsObject
return this[Strings.tee].function!(this: this, arguments: []).fromJSValue()!
}

public typealias Element = JSValue
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public func makeAsyncIterator() -> ValueIterableAsyncIterator<ReadableStream> {
ValueIterableAsyncIterator(sequence: self)
}
}
Loading