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
Consider [LegacyStringClass] #547
Comments
My take is that this is probably not a great idea. String objects are generally confusing and a "mistake" in JavaScript (it would have been better to just have lowercase-s string primitive values). But, let's explore a bit... Probably the best thing to do is figure out what programmer-facing experience you'd be able to achieve here. I can think of a few things:
Maybe there are more... will ask around/think harder. My general takeaway is that you're most likely to land yourself in a weird uncanny valley by inheriting from |
From https://svgwg.org/svg2-draft/types.html#InterfaceSVGAnimatedString it does not seem like it has |
Being a proper subclass would enable |
(Note that we also researched string subclasses in the past for the CSSOM and it wasn't really workable. Though the angle there was to replace things that were strings.) |
@ljharb I'm curious why those string methods aren't generic. Web-breaking compat issues? |
@tobie every builtin besides Error (until stacks arrive) has at least one available brand-checking method; I have no idea what the history is with String but i assume it was originally for legacy reasons. |
@tobie as I think more about it, in order for those methods to be shared, the actual string data on a boxed primitive String would have to be per-instance, which necessitates an internal slot, which means the methods can’t be generic. |
@ljharb Right, but what prevents objects with a |
@tobie nothing at all - svg String objects could easily have both, but the caveats mentioned #547 (comment) here would still apply. |
Agreed. But that would fix your concern expressed in #547 (comment). |
Oh - to clarify, i don’t think it’s important to have those two methods work with svg strings - i was pointing out that that would be the only meaningful difference (since all the prototype methods could be shared or replicated) |
Appreciate the exploratory thoughts!
This is indeed the tricky problem. Ideally, we'd want the However, it sounds like this path has been trod before, and there's not a great solution to subclass String objects (nor should we be encouraging this). |
[PutForwards] and stringifier it is. Thanks folks. |
See: w3c/svgwg#175
@dstorey, @AmeliaBR
Folks working on SVG are trying to fix
href
andclassName
in the SVG DOM to be more compatible with the HTML equivalent versions of those APIs. In HTML, these attributes get and set strings, in SVG they getSVGAnimatedString
(and don't set), andSVGAnimatedString
hasbaseVal
(gets and sets string) andanimVal
gets a string only.After a lot of thought, our "A" solution is to somehow make the
SVGAnimatedString
a type of actual string object for maximum compat, augmented with thebaseVal
andanimVal
attributes for backwards compatibility. This is the solution proposed in Issue w3c/svgwg#175.How to actually do that? Following the pattern of
Legacy...
extended attributes, havingSVGAnimatedString
use a new [LegacyStringClass] seems like an option that might work, although there's a lot of assumptions we're making. We're hoping this issue and the smart folks working on WebIDL bindings can help work out if/how this could be achieved.At it's surface, the interface would inherit from %StringPrototype%, but then we have a host of questions:
The list goes on.
If this is an insane idea, would love to know--it certainly seems like it will be complicated, but also pretty compatible if it does work.
The text was updated successfully, but these errors were encountered: