Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

using Records where only Objects are currently permitted: [[Prototype]]? #326

Closed
michaelficarra opened this issue Jul 19, 2022 · 3 comments

Comments

@michaelficarra
Copy link
Member

#264 is trying to allow records to be interchangeable with objects in more places. Currently, there is a guard at the beginning of all mechanisms that assign a value to an object's [[Prototype]] (such as Object.create and Object.setPrototypeOf) that the value is null or an Object. Do we want to change these guards to permit records to be added to the prototype chain? A workaround currently is to just pass the record through Object() first, as in Object.create(Object(record)).

@acutmore
Copy link
Collaborator

Hi @michaelficarra - were you suggesting that the object coercion here be implicit? i.e. Object.create(#{}) would be equivalent to Object.create(Object(#{})), or that records could actual be used as the [[Prototype]] directly?

For the implicit conversion, this is different from the implicit conversions added in #264 where the conversion is internal to the methods. e.g. new Error(msg, #{ cause: v }) and JSON.stringify(v, #["a", "b"]) allows records and tuples as inputs so their internal values can be read/extracted by the algorithms; the converted object is not exposed anywhere.

For allowing records to be used as a [[Prototype]] value, this would be observable and impact anywhere that calls [[GetPrototypeOf]] making it a significant change relative to the other changes in #264. Also considering the most common use of prototypes is to share methods, and records can't contain functions, so it may not prove particular valuable to add this change.

@rricard rricard mentioned this issue Jul 25, 2022
25 tasks
@michaelficarra
Copy link
Member Author

were you suggesting that the object coercion here be implicit?

Yes.

the converted object is not exposed anywhere

That's fair, and I would accept that reasoning.

@acutmore
Copy link
Collaborator

Thanks @michaelficarra - I'll close this for now as "converting a record to be used as a prototype should be done explicitly". We can always re-open if discussion prompts.

As a side note, I realized I wasn't sure what would happen for __proto__ in a object literal when set to a non-null primitive. Turns out the spec silently ignores it.

const o = {
  __proto__: 42
};
Object.getPrototypeOf(o) === Object.prototype; // true
Reflect.ownKeys(o); // []

@acutmore acutmore closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants