@@ -59,18 +59,11 @@ extension IDLAttribute: SwiftRepresentable {
5959 """
6060 }
6161 }
62-
63- var initializer : SwiftSource ? {
64- assert ( !ModuleState. static)
65- return """
66- \( wrapperName) = \( idlType. propertyWrapper ( readonly: readonly) ) (jsObject: jsObject, name: \( ModuleState . source ( for: name) ) )
67- """
68- }
6962}
7063
7164extension IDLDictionary . Member {
7265 var isOptional : Bool {
73- !required && !idlType. nullable && !idlType . isFunction
66+ !required && !idlType. nullable
7467 }
7568
7669 var optionalSuffix : String {
@@ -263,7 +256,7 @@ extension MergedInterface: SwiftRepresentable {
263256 \( hasAsyncSequence ?
264257 """
265258 #if canImport(JavaScriptEventLoop)
266- public extension \( name) : AsyncSequence {}
259+ extension \( name) : AsyncSequence {}
267260 #endif
268261 """ :
269262 " "
@@ -427,7 +420,7 @@ extension IDLOperation: SwiftRepresentable, Initializable {
427420 case " stringifier " :
428421 return """
429422 @inlinable public var description: String {
430- \( ModuleState . this) [Strings.toString]!().fromJSValue()!
423+ \( ModuleState . this) [Strings.toString].function !().fromJSValue()!
431424 }
432425 """
433426 case " static " :
@@ -505,18 +498,26 @@ extension IDLOperation: SwiftRepresentable, Initializable {
505498
506499 fileprivate var nameAndParams : SwiftSource {
507500 let accessModifier : SwiftSource = ModuleState . static ? ( ModuleState . inClass ? " class " : " static " ) : " "
508- let overrideModifier : SwiftSource = ModuleState . override ? " override " : " "
501+ let overrideModifier : SwiftSource = if ModuleState . static && ModuleState . inClass {
502+ ModuleState . override ? " override " : " "
503+ } else {
504+ ModuleState . inClass && !ModuleState. current. inProtocol ? " final " : " "
505+ }
509506 return """
510507 \( overrideModifier) public \( accessModifier) func \( name) ( \( sequence: arguments. map ( \. swiftRepresentation) ) )
511508 """
512509 }
513510
514511 private var defaultRepresentation : SwiftSource {
515512 guard let idlType = idlType else { fatalError ( ) }
516- var returnType = idlType. swiftRepresentation
517- if returnType == ModuleState . className {
518- returnType = " Self "
513+
514+ // skip overrides, since ancestor functions are final and JS will do dynamic dispatch to overrides anyway
515+ // FIXME: still emit overrides that have a different number of arguments than an ancestor method, just without `override` keyword
516+ guard !ModuleState. override || ModuleState . static else {
517+ return " "
519518 }
519+
520+ let returnType = idlType. swiftRepresentation
520521 if ModuleState . override, ModuleState . static, !ModuleState. inClass {
521522 preconditionFailure ( " Cannot override static method in non-class " )
522523 }
@@ -572,12 +573,14 @@ extension AsyncOperation: SwiftRepresentable, Initializable {
572573 result = " return try await _promise.value \( returnType. fromJSValue) "
573574 }
574575 return """
576+ #if canImport(JavaScriptEventLoop)
575577 @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
576- @inlinable \( operation. nameAndParams) async throws -> \( returnType) {
578+ @inlinable \( operation. nameAndParams) async throws(JSException) -> \( returnType) {
577579 \( prep)
578580 let _promise: JSPromise = \( call) .fromJSValue()!
579581 \( result)
580582 }
583+ #endif
581584 """
582585 }
583586
@@ -673,7 +676,7 @@ extension IDLType: SwiftRepresentable {
673676 case " Promise " :
674677 return " JSPromise "
675678 case " record " :
676- return " [ \( args [ 0 ] ) : \( args [ 1 ] ) ] "
679+ return " JSObject "
677680 default :
678681 fatalError ( " Unsupported generic type: \( name) " )
679682 }
@@ -712,39 +715,38 @@ extension IDLType: SwiftRepresentable {
712715 return false
713716 }
714717
715- func propertyWrapper( readonly: Bool ) -> SwiftSource {
716- // TODO: handle readonly closure properties
717- // (should they be a JSFunction? or a closure? or something else?))
718+ var closurePattern : ClosurePattern ? {
718719 if case let . single( name) = value {
719720 if let callback = ModuleState . types [ name] as? IDLCallback {
720- precondition ( !readonly, " readonly closure properties are not supported " )
721- return " \( closureWrapper ( callback, optional: false ) ) "
721+ return closureWrapper ( callback, optional: false )
722722 }
723723 if let ref = ModuleState . types [ name] as? IDLTypedef ,
724724 case let . single( name) = ref. idlType. value,
725725 let callback = ModuleState . types [ name] as? IDLCallback
726726 {
727- precondition ( !readonly, " readonly closure properties are not supported " )
728727 precondition ( ref. idlType. nullable)
729- return " \( closureWrapper ( callback, optional: true ) ) "
728+ return closureWrapper ( callback, optional: true )
730729 }
731730 }
732731
733- if readonly {
734- return . readOnlyAttribute
735- } else {
736- return . readWriteAttribute
737- }
732+ return nil
738733 }
739734
740- private func closureWrapper( _ callback: IDLCallback , optional: Bool ) -> SwiftSource {
735+ private func closureWrapper( _ callback: IDLCallback , optional: Bool ) -> ClosurePattern {
741736 let returnsVoid = callback. idlType. swiftRepresentation == " Void "
742737 let argCount = callback. arguments. count
743- return ClosurePattern ( nullable: optional, void: returnsVoid, argCount: argCount) . name
738+ return ClosurePattern ( nullable: optional, void: returnsVoid, argCount: argCount)
744739 }
745740}
746741
747742extension IDLTypedef : SwiftRepresentable {
743+ static let typeNameMap : [ String : SwiftSource ] = [
744+ // FIXME: WebIDL specifies these as `unsigned long long`, but major browsers expect
745+ // a JS number and not BigInt here, so we have to keep it `Int32` on the Swift side.
746+ " GLintptr " : " Int32 " ,
747+ " GPUSize64 " : " UInt32 " ,
748+ ]
749+
748750 var unionType : UnionType ? {
749751 if case let . union( types) = idlType. value {
750752 return ModuleState . union ( for: Set ( types. map ( SlimIDLType . init) ) , defaultName: name)
@@ -753,6 +755,8 @@ extension IDLTypedef: SwiftRepresentable {
753755 }
754756
755757 var swiftRepresentation : SwiftSource {
758+ let aliasedType : SwiftSource
759+
756760 if let unionType = unionType {
757761 guard unionType. friendlyName != name else { return " " }
758762 if let existingName = unionType. friendlyName {
0 commit comments