- From: Tab Atkins Jr. <notifications@github.com>
- Date: Fri, 14 Jul 2023 14:57:11 -0700
- To: whatwg/webidl <webidl@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/webidl/issues/1342@github.com>
In <https://github.com/w3c/csswg-drafts/issues/8350>, @domenic asked for us to make the new `CSSStyleRule.cssRules` attribute an `ObservableArray<CSSRule>`, rather than the existing weird legacy array-ish `CSSRuleList` that we use in similar places. We'd like to keep things consistent across the OM (in fact, we've now specified that `CSSStyleRule` just inherits from `CSSGroupingRule`, same as `CSSMediaRule` and the like), but that means we have to deal with legacy compat. In particular, `CSSRuleList` has an `item()` method. Unfortunately it's not currently possible to add methods to an ObservableArray; you just get the default stuff and that's it. We should add some way to "inherit" from ObservableArray so legacy cases like this can be handled. Quote from @domenic in the WHATWG chat room: > There are at least two ways you could do it I can think of: something that does actual inheritance (so that `x.constructor.name === "CSSRuleList"`, `x.hasOwnProperty("push") === false`, but `x.hasOwnProperty("item") === true`), or something that changes the proxy that `ObservableArray` uses to have special behavior for the defined properties (i.e., instead of `[[GetOwnProperty]]` on `"item"` returning `undefined`/whatever gets stored there via normal property access, it returns some property descriptor for the method that we conjured up). Both are pretty subtle to actually define and I'm not sure which is best, or if there's a better third option... I think either is fine, particularly for these sorts of legacy cases. The simple inheritance model might be the easiest, tho - you just put the Proxy object behind it in the prototype chain, and things will continue to Just Work, as far as I can tell? It also means you have the least chance of triggering incidental compat issues, like people branching on `instanceof`. I suspect it's also the easiest to fit into the existing syntax, as you'd literally just say `interface CSSRuleList : ObservableArray<CSSRule>` -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/webidl/issues/1342 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/webidl/issues/1342@github.com>
Received on Friday, 14 July 2023 21:57:18 UTC