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

"Dictionaries must not be used as the type of an attribute or constant" -- why? #981

Open
LeaVerou opened this issue May 12, 2021 · 7 comments

Comments

@LeaVerou
Copy link

I recently observed a case where an API became less usable because of this, so I was curious what's the rationale?

@annevk
Copy link
Member

annevk commented May 12, 2021

You'd have to keep them alive for the lifetime of the object the attribute is associated with, which isn't necessarily great as it would just be a normal mutable JavaScript object not necessarily representing the actual state of things (even if the actual state of things is immutable, say, as the object could be modified by any caller).

@domenic
Copy link
Member

domenic commented May 12, 2021

Also, a new copy would get created every time the getter steps run (when you convert the Web IDL dictionary into a JS object), so you'd have obj.attribute !== obj.attribute.

@annevk
Copy link
Member

annevk commented May 12, 2021

That we could mitigate with an improved (tm) [SameObject], aka [Cached]. To me the mutability is the main downside of this. It might well be that sanitizer would be better off exposing these as getters though, that's how we often expose such settings (e.g., on ShadowRoot).

@LeaVerou
Copy link
Author

It might well be that sanitizer would be better off exposing these as getters though, that's how we often expose such settings (e.g., on ShadowRoot).

Wouldn't what @domenic said be true with a getter though? That you'd have obj.attribute !== obj.attribute?

@annevk
Copy link
Member

annevk commented May 12, 2021

@LeaVerou you'd have a getter per setting. E.g., shadowRoot.mode.

@LeaVerou
Copy link
Author

@annevk In this case, the object properties are also objects though…

@annevk
Copy link
Member

annevk commented May 12, 2021

It seems ReadOnlyArray would fit a bunch, but AttributeMatchList is indeed tricky. In that case the snapshot approach they have taken might be the best. At least with that multiple consumers cannot end up confusing each other easily.

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

No branches or pull requests

3 participants