Skip to content
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

Editorial: make record objects non exotic (alternative) #359

Merged
merged 3 commits into from
Sep 23, 2022

Conversation

acutmore
Copy link
Collaborator

This is an alternative PR to #357. They both change the spec so that the object returned by ToObject(recordPrimitive) is ordinary.

The difference in this PR is the object retains the additional [[RecordData]] slot, so that ToPrimitive and Object.prototype.toString can detect this branding and have bespoke behavior. This PR also retains the Record.recordValue API as a way to infallibly check for the presence of this slot. This makes this change editorial, we keep all the same observable outcomes of the current spec, but reduce the amount of spectext required to express it. This should also make it clearer that interacting with records via their object-methods is exactly the same as working with Object.freeze({__proto__: null}) objects.

@acutmore acutmore marked this pull request as draft September 21, 2022 11:59
@acutmore acutmore marked this pull request as ready for review September 21, 2022 15:42
@nicolo-ribaudo nicolo-ribaudo changed the title spec: make record objects non exotic (alternative) Editorial: make record objects non exotic (alternative) Sep 22, 2022
@acutmore acutmore merged commit 99e1d97 into main Sep 23, 2022
@acutmore acutmore deleted the ac/remove-record-wrappers-2 branch September 23, 2022 10:59
@bakkot
Copy link
Contributor

bakkot commented Sep 23, 2022

Aw :( the other PR was a lot simpler, and people seemed enthusiastic about it in committee. Can you say more about why you went with this more complex design?

@acutmore
Copy link
Collaborator Author

Hey @bakkot !

In terms of more complexity. Compared to #357, the difference is:

  • a [[RecordData]] slot is used for storing the original primitive
  • Object::toString checks for this slot
  • Record.recordValue checks for this slot
  • ToPrimitive checks for this slot

Comparing this to existing primitive types, e.g. Boolean

  • a [[BooleanData]] slot is used for storing the original primitive
  • Object::toString checks for this slot
  • Boolean.prototype.valueOf checks for this slot

So the only major difference between record objects and boolean objects is the one line in ToPrimitive to address the lack of valueOf, toString or Symbol.toPrimitive methods on records. For implementers this could amount to the equivalent of an internal private WeakSet to 'tag' record objects and checking for this 'tag' in their ToPrimitive implementation.

In terms of why this PR was merged. Primarily because it was editorial while still benefiting from the spec simplification demonstrated by #357. Secondarily, because @ljharb was keen for us to retain the implicit type coercion when people use + for string concatenation of record objects. Thirdly, because we have discovered another way to still provide a brand-check for this slot (the core motivation for removing the slot was due to the difficulty in also providing a brand-check for it without compromising other APIs).

@bakkot
Copy link
Contributor

bakkot commented Sep 26, 2022

To my mind the major difference between this PR and #357 is that this PR includes an additional kind of object, "boxed records", which are observably different from normal objects.

I don't think it's worth having an additional kind of object just to make + for string concatenation of boxed record objects not throw. More generally I don't think it's worth any amount of additional complexity to make boxed record objects special, given how rarely they should come up in real code. So I would much prefer to go with #357 instead, and to remove Record[@@hasInstance].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants