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

Add indexing operators for getter and setter attributes #127

Closed
parlough opened this issue Dec 20, 2023 · 8 comments · Fixed by #293
Closed

Add indexing operators for getter and setter attributes #127

parlough opened this issue Dec 20, 2023 · 8 comments · Fixed by #293

Comments

@parlough
Copy link
Member

parlough commented Dec 20, 2023

DOMStringMap, primarily returned by HTMLElement#dataset does not provide any mechanism to set or access its values.

Would be nice if it implemented something like Map<String, String> if that was possible :)

See

// TODO(joshualitt): We may be able to handle some unnamed

@kevmoo
Copy link
Member

kevmoo commented Dec 20, 2023

I've ran into this, too! CC @srujzs

@srujzs
Copy link
Contributor

srujzs commented Dec 21, 2023

I'm surprised we don't emit some properties already:

https://github.com/w3c/webref/blob/8d7678e1740d00c3b79ebf70013d0448b23e3c8b/ed/idl/html.idl#L161

It might be due to us not handling getter and setter? Maybe we should emit them using [] and []=. https://webidl.spec.whatwg.org/#idl-special-operations

That being said, I don't think we can feasibly implement Map (or any Dart collections type), but hopefully the indexing operations are enough!

@adrianlmm
Copy link

This one is a show stopper for me, I can't start the migration from 'dart:html' to 'web' until it gets fixed.

@srujzs
Copy link
Contributor

srujzs commented Feb 27, 2024

Can you describe a bit more on what's affecting your migration? If it's the above indexing operators, you can define your own external extension members on any interop type if they're not available: https://dart.dev/interop/js-interop/usage#extension-members-on-interop-types e.g.

import 'dart:js_interop';
import 'dart:js_interop_unsafe';

extension on DOMStringMap {
  external String operator [](String name);
  external void operator []=(String name, String value);
  void delete(String name) => this.delete(name.toJS);
}

Matching the definition here: https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes:domstringmap-3.

@srujzs srujzs changed the title DOMStringMap has no mechanism to add/remove/change values Add indexing operators for getter and setter attributes Jul 8, 2024
@kevmoo
Copy link
Member

kevmoo commented Aug 8, 2024

image

From a grep of the IDL directory, there are a LOT of these!

@rutvik110
Copy link
Contributor

rutvik110 commented Aug 25, 2024

@srujzs I was looking into this issue and was wondering how I can approach this? Would the addition of [] and []= operators on DOMStringMap be sufficient here to address this particular issue or would we also need to add handlers in the bindings generator tool for getter and setter special operations to fully support what this issue describes. If so, how can one approach adding support for them in the generator? Any examples I can look into?

@srujzs
Copy link
Contributor

srujzs commented Aug 27, 2024

I think ideally we'll want these in the generator as lots of types define them. The generator has enough layers that it may be a bit complicated to dive into. I'm working on adding this request, but the resulting PR may be useful as an example of how it works and we can chat on that PR.

@rutvik110
Copy link
Contributor

Sounds good!

srujzs added a commit to srujzs/web that referenced this issue Aug 27, 2024
Closes dart-lang#127

The IDL defines unnamed getters or setters which should be
emitted as special variants of the index operators.
@srujzs srujzs closed this as completed in 3619fd8 Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants