-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
don't automatically initialise all internal slots to undefined #3399
Comments
Recap of editor call:
|
And of course remove the implicit initialisation affordance. |
MakeBasicObject is used upstream, at least in WebIDL but plausibly also other specs, so this will take at least a little integration work. |
There's a related issue here in that there may be an invariant that is stated in terms of 2 or more slots, such that there is no way to change the value of 1 slot at a time without violating the invariant between steps. The slots would need to be atomically set in the same way we need to atomically set them as we are initialising an object. Maybe our solution should cover both of these use cases? |
We should just violate the invariant between execution of those two steps. |
Or, alternatively, use one slot with a Record in it instead of two separate slots? |
@bakkot If we were okay with that kind of sloppiness, I don't see why we wouldn't be okay with the sloppiness in the OP: just create the object without specifying the values of the slots and then populate the slots afterward. I'm personally not okay with that kind of sloppiness though. I think this is a worthwhile problem to solve. @ljharb That's reasonable though unfortunate that we have to refactor the data because we have no spec facility for atomic assignment. Another option would be to just do multiple assignments in one step and say the spec invariants only hold between any two steps. |
A proposal: remove the line about slots being initially undefined (including #3537), and change all the places where we initialize a slot using the wording "Set obj.[[slot]] to value" to instead use the wording "Initialize obj.[[slot]] to value". That will hopefully make it less likely that a later refactoring will move the initialization of the slot away from its creation. (Right now at least [[GeneratorContext]] is initialized pretty far from its creation, which is annoying, as mentioned in #3482.) |
We need to clean up how we create objects and set initial values of their internal slots. It is a common pattern today to call
OrdinaryCreateFromConstructor
with a list of additional slot names and then in the immediately following steps, set the initial values of each of these additional fields. But technically according to 6.1.7.2 Object Internal Methods and Internal Slots, these slots are given the valueundefined
in the interim.This means that the declared type of each of these internal slots is implicitly unioned with
undefined
. We should instead create these slots and give them their initial values atomically, then remove this provision.See related #3383.
The text was updated successfully, but these errors were encountered: