-
Notifications
You must be signed in to change notification settings - Fork 163
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
Make [SameObject] beneficial #212
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Note that changing this will affect specifications. @bzbarsky collected a list that will need to be updated after the change: #211 (comment). Seems doable. |
Unlike [SameObject] I think we should allow this new [Cached] (or whatever we call it) extended attribute to be used for getters that return promises. That a non-cached value is returned when this is wrong seems fine. |
Yes, I agree. |
+1 to [Cached] - it's basically what we do in Blink, and end up writing Aside: I'd love to put [SameObject] on IDBObjectStore and IDBIndex's |
Yeah, so what Gecko has is:
|
I think it might make specs a bit hard to read, as the prose may look like it's returning a different object every time, but a sneaky bit in the IDL is changing the behaviour. I'd rather this feature was delivered via some prose defined in infra, like: "The memoized getter steps for foo return…" There can be an idl comment for it too, of course. |
Makes sense. I think we need both. |
WFM. Fwiw, I think "memoize" is a more accurate and well-known term when it comes to storing the result of an algorithm & returning it on future calls https://en.wikipedia.org/wiki/Memoization. But, 'cached' is fine. |
I believe the contract with [SameObject] is supposed to be that whatever is returned the first time cannot ever change, right?
Currently specifications have to maintain that invariant and add the [SameObject] extended attribute as documentation.
However, what IDL could do instead is to allocate an internal slot when such an attribute is used. IDL's algorithm for the getter could then be to return the value from the internal slot when it's set, and when it's unset run the specification algorithm to get a value, set the internal slot to that value, and return that value.
That way the specification does not have to define how the value is stored, just how it's computed/retrieved.
The text was updated successfully, but these errors were encountered: