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

Support callback interfaces #34

Open
j-f1 opened this issue May 3, 2022 · 1 comment
Open

Support callback interfaces #34

j-f1 opened this issue May 3, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@j-f1
Copy link
Member

j-f1 commented May 3, 2022

These are a Cursed Object in the WebIDL spec (https://webidl.spec.whatwg.org/#idl-callback-interfaces), and they’re essentially shorthand for a union between a function/closure type and an object with a property matching that function type. They are unfortunately important because EventListener is a callback interface (although NodeFilter and XPathNSResolver are also a callback interface, they are less commonly used). This PR depends on #32, probably.

https://github.com/swiftwasm/DOMKit/blob/070f99efca195eaa38f46beeb4dc46ca1d6ce04b/Sources/WebIDLToSwift/IDLBuilder.swift#L82-L88

@j-f1 j-f1 added the enhancement New feature or request label May 3, 2022
@j-f1
Copy link
Member Author

j-f1 commented Jan 29, 2023

Update: Implemented EventListener in 61144ad by interpreting it as a simple closure (EventTarget) -> Void. This does technically mean you can’t pass an object as an event listener but I’ve never heard of anyone wanting to do that.

The other two callback interfaces are available as properties/method return values (EventListener is currently only used in the spec as a parameter), so it’s possible to get one of the object-y versions which could not be converted directly to a closure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant