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

NodeFilter constants are missing #252

Open
ahmednfwela opened this issue Jun 10, 2024 · 2 comments
Open

NodeFilter constants are missing #252

ahmednfwela opened this issue Jun 10, 2024 · 2 comments

Comments

@ahmednfwela
Copy link

The following constants are missing from NodeFilter: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker/whatToShow
note that NodeFilter is defined as JSFunction so I am not sure how these constants would be mapped.

@srujzs
Copy link
Contributor

srujzs commented Jun 10, 2024

Ah it looks like these are callbacks with actual interfaces (seems like there's a total of 3 such callback interfaces): https://github.com/w3c/webref/blob/889fb706923c9a666c73a64545193a35cdec3983/ed/idl/dom.idl#L551C20-L551C30.

Generating an appropriate interface for this might be tricky. Naively, we can generate an extension type on JSFunction:

extension type NodeFilter._(JSFunction _) implements JSFunction {
  external static int get SHOW_ALL;
  ...
}

But then because it's no longer a typedef, users who want to use APIs that accept a NodeFilter will now need to cast/construct a NodeFilter trivially.

@ahmednfwela
Copy link
Author

ahmednfwela commented Jun 11, 2024

it looks like the spec identifies callback interface as legacy https://webidl.spec.whatwg.org/#dfn-callback-interface

Also from my limited understanding, these are interfaces that contain EXACTLY ONE function, and any number of constants

e.g.

  1. EventListener has
    undefined handleEvent(Event event);
  2. NodeFilter has
    unsigned short acceptNode(Node node);
    and some constants
  3. XPathNSResolver has
    DOMString? lookupNamespaceURI(DOMString? prefix);

from a first glance, they are very similar to dart's callable classes

so they are technically just interfaces, meaning they can be defined as

extension type NodeFilter._(JSObject _) implements JSObject {
  external static int get SHOW_ALL;
  //...
  external static int acceptNode(Node node);
  // this line is optional
  int call(Node node) => acceptNode(node);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants