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

Resolve inconsistencies between null and undefined #25

Closed
erights opened this issue Feb 21, 2018 · 6 comments
Closed

Resolve inconsistencies between null and undefined #25

erights opened this issue Feb 21, 2018 · 6 comments

Comments

@erights
Copy link
Contributor

erights commented Feb 21, 2018

Some parts of the spec say or imply that 'get/deref on a weakref whose target is collected returns null. Other parts say or imply void 0, i.e., undefined.

There may also be inconsistencies with the holdings, but I did not look as carefully. In any case, we need to look and resolve any such inconsistencies.

I can't see any way to observe whether an executor is null or undefined, but we should be sure we're consistent here anyway.

Has anyone written down any widely accepted criteria for choosing between null and undefined?

@ljharb
Copy link
Member

ljharb commented Feb 21, 2018

The majority of the JS community treats null and undefined identically, including much of the ES spec itself.

However, argument/destructuring defaults, in particular, only apply to undefined and not to null, and it seems the consensus in that camp is "Giving you undefined means I don't care what it is, null means I'm intentionally choosing 'nothing'".

So, I think weakrefs could legitimately choose either one. tc39/proposal-nullish-coalescing#20 is a relevant issue for nullish coalescing, which will have to make and defend the same choice (my strong hope is that it treats the two identically).

@dtribble
Copy link
Contributor

The open questions section discusses this question some. The fallback answer is "undefined", which was concluded after the first draft. The spec text and implementation in the current proposal consistently say "unefined" for the target and "null" for the holdings, but I think that's a mistake and it should just be "undefined". The rationale is that this is about references, and "undefined" is equivalent to "you don't have a reference (e.g., if you provide fewer arguments to a functions than expected). So GC returns the reference to an "uninitialized state".

@dtribble
Copy link
Contributor

Can you point me at parts that imply null? I'll fix them.

@erights
Copy link
Contributor Author

erights commented Feb 22, 2018

Proposed Solutions says

The target can be retrieved from the resulting weak reference unless the target has been condemned, in which case null is returned.

Basic Usage says

assert(wr.get() === null);

@littledan
Copy link
Member

The current proposal uses undefined, not null, for the WeakRef deref method when the object has already been collected. This matches my intuition of undefined standing for missing values. I am not aware of any inconsistencies. Would it make sense to close this issue?

@gsathya
Copy link
Member

gsathya commented Apr 18, 2019

Would it make sense to close this issue?

Yeah, it looks like the spec is all cleaned up now.

@gsathya gsathya closed this as completed Apr 18, 2019
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