Skip to content

Bring code generation into this repo, update to latest specs, support async functions natively #10

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 124 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
05a8b9d
Swift interfaces for the WebIDL spec
j-f1 Mar 29, 2022
8fcd458
it parses!
j-f1 Mar 29, 2022
1a8b6e0
more fixes
j-f1 Mar 29, 2022
e169987
Start outputting Swift code
j-f1 Mar 29, 2022
7840dbc
Allow dynamic state
j-f1 Mar 29, 2022
2ab1dc6
more work
j-f1 Mar 29, 2022
7beaf87
whee it gets through the dom spec!
j-f1 Mar 29, 2022
75d117a
write out to the files, make public
j-f1 Mar 29, 2022
b1f0515
More fixes/polish
j-f1 Mar 29, 2022
affd27a
progress
j-f1 Mar 29, 2022
54367db
add HTML
j-f1 Mar 29, 2022
afc48a7
Fix broken enums
j-f1 Mar 29, 2022
2dc3245
Fix nullable IDLTypes
j-f1 Mar 29, 2022
f92b1cc
more fixes
j-f1 Mar 29, 2022
1569d9d
fetch all the IDL files
j-f1 Mar 29, 2022
aff3c64
remove IDLIncludes conformance for now since it is unused
j-f1 Mar 29, 2022
98c9315
fixes to optional arguments, merge declarations
j-f1 Mar 29, 2022
ae2568c
fix nullable optional params
j-f1 Mar 30, 2022
ee2f72d
use ReadWriteAttribute for dictionaries
j-f1 Mar 30, 2022
cc72638
remove broken getter support, fix IDLDictionary init
j-f1 Mar 30, 2022
5c2f314
Changes to JSKit
j-f1 Mar 30, 2022
d6fab9b
hammer more on errors
j-f1 Mar 30, 2022
cd34b3c
fix broken dictionaries
j-f1 Mar 30, 2022
139c412
try fix constructors
j-f1 Mar 30, 2022
e2f43ec
add uievents
j-f1 Mar 30, 2022
9b31877
oops
j-f1 Mar 30, 2022
b3a61b5
fancy number types
j-f1 Mar 30, 2022
3706967
correctly label class methods
j-f1 Mar 30, 2022
bcfa230
Work around type checking slowness
j-f1 Mar 30, 2022
82c358a
Add IDLNamed protocol
j-f1 Mar 30, 2022
fbda57c
Handle overridden declarations
j-f1 Mar 30, 2022
8a5586a
use Self more, comment out static overrides
j-f1 Mar 30, 2022
d0194a4
patches to Support.swift
j-f1 Mar 30, 2022
e265f6c
upstream Uint8ClampedArray, update JSClosure usage
j-f1 Mar 30, 2022
8b141f5
manually remove problematic entities
j-f1 Mar 30, 2022
ab42420
print mixins
j-f1 Mar 30, 2022
6a8f02a
add includes to the appropriate inheritances
j-f1 Mar 30, 2022
6667dcb
make ReadWriteAttribute, ReadonlyAttribute inlinable
j-f1 Mar 30, 2022
a1bc774
Update OptionalClosureHandler based on new closure lifetimes
j-f1 Mar 30, 2022
0b03441
fix inlinable, expand static subscripts
j-f1 Mar 30, 2022
843c5e1
fix wrapped properties on extensions
j-f1 Mar 30, 2022
41a5c24
more SwiftSource API
j-f1 Mar 30, 2022
77f2072
fix readonly properties
j-f1 Mar 30, 2022
8d5bd84
separate mixin and class inheritance
j-f1 Mar 30, 2022
5c74264
)
j-f1 Mar 30, 2022
dd9cf5b
oops
j-f1 Mar 30, 2022
41b2fba
fix some errors
j-f1 Mar 30, 2022
7480bb0
more work
j-f1 Mar 30, 2022
b0a7b2f
fix typo
j-f1 Mar 30, 2022
b2e1755
BUILD PASSES
j-f1 Mar 30, 2022
66bb949
add comment that the code was generated
j-f1 Mar 30, 2022
b8c1bb2
add iterable support
j-f1 Mar 30, 2022
e77a9eb
consistent syntax for removed code
j-f1 Mar 30, 2022
5bd89f6
Add getter support
j-f1 Mar 30, 2022
20fd412
merge namespaces too
j-f1 Mar 30, 2022
8a2073e
pretend to support async iterators
j-f1 Mar 30, 2022
d4384f9
generate async functions
j-f1 Mar 30, 2022
9d72d1b
add more specs
j-f1 Mar 30, 2022
b4dec82
Update Package.swift
j-f1 Mar 30, 2022
ce19248
drop custom ReadableStream
j-f1 Mar 30, 2022
e87bc3d
fix async functions
j-f1 Mar 30, 2022
2ea2764
\(quoted: ...)
j-f1 Mar 30, 2022
4fe726e
Generate closure wrapper types automatically
j-f1 Mar 30, 2022
5fdcd99
remove unsupported function
j-f1 Mar 30, 2022
4c37eb8
fix 0-arg closures
j-f1 Mar 30, 2022
ef7637b
“fix” readonly closure properties (why are these not methods?)
j-f1 Mar 30, 2022
9daa6e8
fix variadic callbacks
j-f1 Mar 30, 2022
18a9483
fixes for the Function type
j-f1 Mar 30, 2022
b65c5b2
Fix closure keys in dictionaries
j-f1 Mar 30, 2022
3d7c312
check in my changes to the iterator support (not working)
j-f1 Mar 30, 2022
4e24216
refactor main.swift
j-f1 Mar 30, 2022
5d1baef
Clean output folder before building
j-f1 Mar 30, 2022
fdee5ba
more refactoring
j-f1 Mar 30, 2022
ad6fe93
Parse the IDL files at runtime
j-f1 Mar 30, 2022
2d99509
check in updated IDL files
j-f1 Mar 30, 2022
67f10c8
reformat iterators
j-f1 Mar 30, 2022
934a47e
Don’t forget to format!
j-f1 Mar 30, 2022
5421c98
Update .gitignore
j-f1 Mar 30, 2022
ff24efd
clean up Support.swift, “fix” build error
j-f1 Mar 30, 2022
810a4f7
Don’t subclass JSObject anymore
j-f1 Apr 1, 2022
aacbe79
Just quote all the names and let SwiftFormat sort it out
j-f1 Apr 1, 2022
443952c
Use JSString more, intern all object keys
j-f1 Apr 1, 2022
f5d0edc
bump JSKit
j-f1 Apr 1, 2022
a7b625b
sdfasg
j-f1 Apr 1, 2022
4c75f8d
remove some swiftRepresentation
j-f1 Apr 1, 2022
7f8681e
Revert "Just quote all the names and let SwiftFormat sort it out"
j-f1 Apr 2, 2022
3d778bf
Fix most errors
j-f1 Apr 2, 2022
3a0e627
Merge all the strings into one enum
j-f1 Apr 2, 2022
432eba6
Also look up global names using Strings
j-f1 Apr 2, 2022
6dc015f
Add the rest of the APIs!
j-f1 Apr 2, 2022
43ff31e
Refactor ECMAScript folder into more files
j-f1 Apr 2, 2022
819b467
Fix typos, ignore a bunch of types
j-f1 Apr 2, 2022
cbd9bf1
update generated files
j-f1 Apr 2, 2022
fc48330
Pick a fixed order of loading in the specs
j-f1 Apr 2, 2022
c818907
Refactor ClosureAttribute code
j-f1 Apr 2, 2022
0544fde
Add support for void-returning closures
j-f1 Apr 2, 2022
cfd9f79
Correctly handle variadic method parameters
j-f1 Apr 2, 2022
72463cf
Also handle variadic constructors
j-f1 Apr 2, 2022
47d99df
Fix constants on protocol extensions
j-f1 Apr 2, 2022
8a367b3
Make things inlinable
j-f1 Apr 2, 2022
05351af
disable broken TrustedTypePolicyOptions
j-f1 Apr 2, 2022
3662d5b
nonmutating
j-f1 Apr 2, 2022
9d204ce
paper over compile error
j-f1 Apr 2, 2022
2d59fd9
Implement ValueIterableIterator, ValueIterableAsyncIterator
j-f1 Apr 2, 2022
8542c19
remove non-Window-exposed APIs
j-f1 Apr 2, 2022
b79a328
Initial union support
j-f1 Apr 2, 2022
24bf907
Replace X_or_Void unions with Optional<X>
j-f1 Apr 2, 2022
3f7febf
Remove redundant union
j-f1 Apr 2, 2022
2ddcf8e
special-case CustomElementConstructor
j-f1 Apr 2, 2022
cd16a42
fix ArrayBufferView
j-f1 Apr 2, 2022
582a77d
fix RotationMatrixType
j-f1 Apr 2, 2022
4600290
(wip) Automatically pick up friendly names for unions
j-f1 Apr 3, 2022
157f5ca
switch back to main branch of JSKit
j-f1 Apr 5, 2022
1d8188b
update to the new JSKit APIs
j-f1 Apr 5, 2022
b9c4648
polish naming of union cases that start with an acronym
j-f1 Apr 23, 2022
c435299
limit parsed specs
j-f1 Apr 22, 2022
2edf07e
fix UnionType crash
j-f1 Apr 23, 2022
a0d5667
add typed accessors to unions
j-f1 Apr 23, 2022
9bc4426
hand-implement RenderingContext, OffscreenRenderingContext
j-f1 Apr 23, 2022
6254975
cut some more
j-f1 Apr 23, 2022
8392de9
cut more
j-f1 Apr 23, 2022
3884036
Use macOS Monterey and Xcode 13.3.1
MaxDesiatov Apr 30, 2022
4e9716d
Use `macos-12` image name
MaxDesiatov Apr 30, 2022
96688c3
Add BodyInit typealias
j-f1 Apr 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ on:

jobs:
macos_test:
runs-on: macos-11.0
runs-on: macos-12

steps:
- uses: actions/checkout@v2
- name: Run the test suite on macOS
shell: bash
run: |
set -ex
sudo xcode-select --switch /Applications/Xcode_12.3.app/Contents/Developer/
sudo xcode-select --switch /Applications/Xcode_13.3.1.app/Contents/Developer/

brew install swiftwasm/tap/carton

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/Packages
/*.xcodeproj
xcuserdata/
node_modules
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"package": "JavaScriptKit",
"repositoryURL": "https://github.com/swiftwasm/JavaScriptKit.git",
"state": {
"branch": null,
"revision": "b7a02434c6e973c08c3fd5069105ef44dd82b891",
"version": "0.9.0"
"branch": "main",
"revision": "95d0c4cd78b48ffc7e19c618d57c3244917be09a",
"version": null
}
}
]
Expand Down
14 changes: 9 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ let package = Package(
.library(
name: "DOMKit",
targets: ["DOMKit"]),
.library(name: "WebIDL", targets: ["WebIDL"]),
.executable(name: "WebIDLToSwift", targets: ["WebIDLToSwift"]),
],
dependencies: [
.package(
name: "JavaScriptKit",
url: "https://github.com/swiftwasm/JavaScriptKit.git",
.upToNextMinor(from: "0.9.0")),
.branch("main")),
],
targets: [
.target(
name: "DOMKitDemo",
dependencies: ["DOMKit"]
),
dependencies: ["DOMKit"]),
.target(
name: "DOMKit",
dependencies: ["JavaScriptKit"]),
dependencies: ["JavaScriptKit", .product(name: "JavaScriptEventLoop", package: "JavaScriptKit")]),
.target(name: "WebIDL"),
.target(
name: "WebIDLToSwift",
dependencies: ["WebIDL"]),
.testTarget(
name: "DOMKitTests",
dependencies: ["DOMKit"]),
Expand Down
1 change: 0 additions & 1 deletion Sources/DOMKit/ECMAScript/ArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public typealias Int32Array = JSTypedArray<Int32>
public typealias Uint8Array = JSTypedArray<UInt8>
public typealias Uint16Array = JSTypedArray<UInt16>
public typealias Uint32Array = JSTypedArray<UInt32>
//public typealias Uint8ClampedArray = JSTypedArray<Uint8Clamped>
public typealias Float32Array = JSTypedArray<Float32>
public typealias Float64Array = JSTypedArray<Float64>

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

import JavaScriptEventLoop
import JavaScriptKit

// TODO: expand this to BigInt arrays
public protocol AnyArrayBufferView: ConvertibleToJSValue {}
extension DataView: AnyArrayBufferView {}
extension JSTypedArray: AnyArrayBufferView {}

public enum ArrayBufferView: JSValueCompatible, AnyArrayBufferView {
case dataView(DataView)
// case bigInt64Array(BigInt64Array)
// case bigUint64Array(BigUint64Array)
case float32Array(Float32Array)
case float64Array(Float64Array)
case int16Array(Int16Array)
case int32Array(Int32Array)
case int8Array(Int8Array)
case uint16Array(Uint16Array)
case uint32Array(Uint32Array)
case uint8Array(Uint8Array)
case uint8ClampedArray(Uint8ClampedArray)

public static func construct(from value: JSValue) -> Self? {
// if let bigInt64Array: BigInt64Array = value.fromJSValue() {
// return .bigInt64Array(bigInt64Array)
// }
// if let bigUint64Array: BigUint64Array = value.fromJSValue() {
// return .bigUint64Array(bigUint64Array)
// }
if let dataView: DataView = value.fromJSValue() {
return .dataView(dataView)
}
if let float32Array: Float32Array = value.fromJSValue() {
return .float32Array(float32Array)
}
if let float64Array: Float64Array = value.fromJSValue() {
return .float64Array(float64Array)
}
if let int16Array: Int16Array = value.fromJSValue() {
return .int16Array(int16Array)
}
if let int32Array: Int32Array = value.fromJSValue() {
return .int32Array(int32Array)
}
if let int8Array: Int8Array = value.fromJSValue() {
return .int8Array(int8Array)
}
if let uint16Array: Uint16Array = value.fromJSValue() {
return .uint16Array(uint16Array)
}
if let uint32Array: Uint32Array = value.fromJSValue() {
return .uint32Array(uint32Array)
}
if let uint8Array: Uint8Array = value.fromJSValue() {
return .uint8Array(uint8Array)
}
if let uint8ClampedArray: Uint8ClampedArray = value.fromJSValue() {
return .uint8ClampedArray(uint8ClampedArray)
}
return nil
}

public var jsValue: JSValue {
switch self {
// case let .bigInt64Array(bigInt64Array):
// return bigInt64Array.jsValue
// case let .bigUint64Array(bigUint64Array):
// return bigUint64Array.jsValue
case let .dataView(dataView):
return dataView.jsValue
case let .float32Array(float32Array):
return float32Array.jsValue
case let .float64Array(float64Array):
return float64Array.jsValue
case let .int16Array(int16Array):
return int16Array.jsValue
case let .int32Array(int32Array):
return int32Array.jsValue
case let .int8Array(int8Array):
return int8Array.jsValue
case let .uint16Array(uint16Array):
return uint16Array.jsValue
case let .uint32Array(uint32Array):
return uint32Array.jsValue
case let .uint8Array(uint8Array):
return uint8Array.jsValue
case let .uint8ClampedArray(uint8ClampedArray):
return uint8ClampedArray.jsValue
}
}
}
39 changes: 39 additions & 0 deletions Sources/DOMKit/ECMAScript/Attributes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import JavaScriptKit

@propertyWrapper public struct ReadWriteAttribute<Wrapped: 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: Wrapped {
get { ReadWriteAttribute[name, in: jsObject] }
nonmutating set { ReadWriteAttribute[name, in: jsObject] = newValue }
}

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

@propertyWrapper public struct ReadonlyAttribute<Wrapped: ConstructibleFromJSValue> {
@usableFromInline let jsObject: JSObject
@usableFromInline let name: JSString

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

@inlinable public var wrappedValue: Wrapped {
ReadonlyAttribute[name, in: jsObject]
}

@inlinable public static subscript(name: JSString, in jsObject: JSObject) -> Wrapped {
jsObject[name].fromJSValue()!
}
}
24 changes: 24 additions & 0 deletions Sources/DOMKit/ECMAScript/BridgedDictionary.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import JavaScriptKit

public class BridgedDictionary: JSValueCompatible {
public let jsObject: JSObject

public var jsValue: JSValue {
jsObject.jsValue
}

public required init(unsafelyWrapping jsObject: JSObject) {
self.jsObject = jsObject
}

public static func construct(from value: JSValue) -> Self? {
if let object = value.object {
return Self.construct(from: object)
}
return nil
}

public static func construct(from object: JSObject) -> Self? {
Self(unsafelyWrapping: object)
}
}
102 changes: 102 additions & 0 deletions Sources/DOMKit/ECMAScript/CanvasImageSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!

import JavaScriptEventLoop
import JavaScriptKit

public protocol Any_CanvasImageSource: ConvertibleToJSValue {}
extension HTMLCanvasElement: Any_CanvasImageSource {}
extension HTMLOrSVGImageElement: Any_CanvasImageSource {}
extension HTMLVideoElement: Any_CanvasImageSource {}
extension ImageBitmap: Any_CanvasImageSource {}
extension OffscreenCanvas: Any_CanvasImageSource {}
//extension VideoFrame: Any_CanvasImageSource {}

public enum CanvasImageSource: JSValueCompatible, Any_CanvasImageSource {
case htmlCanvasElement(HTMLCanvasElement)
case htmlOrSVGImageElement(HTMLOrSVGImageElement)
case htmlVideoElement(HTMLVideoElement)
case imageBitmap(ImageBitmap)
case offscreenCanvas(OffscreenCanvas)
// case videoFrame(VideoFrame)

var htmlCanvasElement: HTMLCanvasElement? {
switch self {
case let .htmlCanvasElement(htmlCanvasElement): return htmlCanvasElement
default: return nil
}
}

var htmlOrSVGImageElement: HTMLOrSVGImageElement? {
switch self {
case let .htmlOrSVGImageElement(htmlOrSVGImageElement): return htmlOrSVGImageElement
default: return nil
}
}

var htmlVideoElement: HTMLVideoElement? {
switch self {
case let .htmlVideoElement(htmlVideoElement): return htmlVideoElement
default: return nil
}
}

var imageBitmap: ImageBitmap? {
switch self {
case let .imageBitmap(imageBitmap): return imageBitmap
default: return nil
}
}

var offscreenCanvas: OffscreenCanvas? {
switch self {
case let .offscreenCanvas(offscreenCanvas): return offscreenCanvas
default: return nil
}
}

// var videoFrame: VideoFrame? {
// switch self {
// case let .videoFrame(videoFrame): return videoFrame
// default: return nil
// }
// }

public static func construct(from value: JSValue) -> Self? {
if let htmlCanvasElement: HTMLCanvasElement = value.fromJSValue() {
return .htmlCanvasElement(htmlCanvasElement)
}
if let htmlOrSVGImageElement: HTMLOrSVGImageElement = value.fromJSValue() {
return .htmlOrSVGImageElement(htmlOrSVGImageElement)
}
if let htmlVideoElement: HTMLVideoElement = value.fromJSValue() {
return .htmlVideoElement(htmlVideoElement)
}
if let imageBitmap: ImageBitmap = value.fromJSValue() {
return .imageBitmap(imageBitmap)
}
if let offscreenCanvas: OffscreenCanvas = value.fromJSValue() {
return .offscreenCanvas(offscreenCanvas)
}
// if let videoFrame: VideoFrame = value.fromJSValue() {
// return .videoFrame(videoFrame)
// }
return nil
}

public var jsValue: JSValue {
switch self {
case let .htmlCanvasElement(htmlCanvasElement):
return htmlCanvasElement.jsValue
case let .htmlOrSVGImageElement(htmlOrSVGImageElement):
return htmlOrSVGImageElement.jsValue
case let .htmlVideoElement(htmlVideoElement):
return htmlVideoElement.jsValue
case let .imageBitmap(imageBitmap):
return imageBitmap.jsValue
case let .offscreenCanvas(offscreenCanvas):
return offscreenCanvas.jsValue
// case let .videoFrame(videoFrame):
// return videoFrame.jsValue
}
}
}
Loading