Re: [heycam/webidl] non-readonly [FrozenArray] attributes are footguns as currently specced (#810)

> Is there a proposed description of [Cached]?

Sure.  I would define it as follows, informally, for the ES binding:

> `[Cached]` is an extended attribute that can be used on regular attributes of a non-callback interface.  When it is used, objects implementing that interface have a slot that corresponds to that attribute.  When the getter for the attribute runs, if there value in the slot is not `undefined` that value is returned.  Otherwise, the normal getter steps are executed, and the result is stored in the slot.  When the setter for the attribute runs, the value in the slot is cleared

In spec terms, https://heycam.github.io/webidl/#internally-create-a-new-object-implementing-the-interface step 4 would add more slots to the list as needed.  https://heycam.github.io/webidl/#dfn-attribute-getter would have extra steps to check the slot as needed and to store the gotten value into the slot after the https://heycam.github.io/webidl/#get-the-underlying-value step and doing the converting to an ES value.  https://heycam.github.io/webidl/#dfn-attribute-setter would have extra steps to clear the slot, probably after the "Perform the actions" step, and probably only if that step does not throw.  I think that's about all that's needed, plus possibly some language about being able to clear the slot manually from spec algorithms as needed if the value changes other than through the setter.

> Does [Cached] indicate that the language binding for an attribute (for example, or only attributes even) should cache?

That is my proposal, yes.

> I understand the proposal here would change that to pass by copy.

If we got rid of the FrozenArray type altogether, you mean?  It would depend on what type got used instead.  If we kept FrozenArray but just changes what ES-to-IDL conversion means for it, there would be no difference.

Are there specific APIs you're thinking of that use that pattern?  I'm not aware of any offhand; https://wicg.github.io/CSS-Parser-API/ has `FrozenArray<FrozenArray<CSSParserValue>>` but that's a readonly regular attribute on an interface.

>  Specifications preferring pass by reference could still retain the same behavior through

Indeed.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/810#issuecomment-538217858

Received on Friday, 4 October 2019 03:48:47 UTC