Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

What happens when invoking WeakRef.deref() on a WeakCell? #30

Closed
dtribble opened this issue Apr 11, 2018 · 4 comments
Closed

What happens when invoking WeakRef.deref() on a WeakCell? #30

dtribble opened this issue Apr 11, 2018 · 4 comments

Comments

@dtribble
Copy link
Contributor

dtribble commented Apr 11, 2018

The spec says it just looks for WeakRef fields on the instance, which are the same as the WeakCell fields. Therefore it would just work on a WeakCell. Is that acceptable? If not, we need to change how the parent and child classes are defined. (from @bmeck)

@erights
Copy link
Contributor

erights commented Apr 11, 2018

Great catch! Yes, we need to fix this.

Example code to clarify the question:

WeakRef.prototype.deref.call(wc);

where wc is a WeakCell. This code should throw, not succeed.

@tschneidereit
Copy link
Member

In my polyfill I have a brand check to make deref only work for WeakRef, not WeakCell. Without such a check WeakCell wouldn't make all that much sense, I think.

@ljharb
Copy link
Member

ljharb commented Apr 11, 2018

Indeed, I’d think WeakRef would need a second internal slot, and then it and WeakCell would share the first one, and most methods would need to brand check the appropriate slot.

@littledan
Copy link
Member

The current specification and explainer does not maintain the distinction between WeakRef and WeakCell. Closing, as this issue no longer seems relevant.

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

No branches or pull requests

5 participants