bloomberg / record-tuple-polyfill

A polyfill for the ECMAScript Record and Tuple proposal.
Apache License 2.0
164 stars 11 forks source link

Theoretical unsafe if condition #106

Closed mfbx9da4 closed 10 months ago

mfbx9da4 commented 10 months ago

https://github.com/bloomberg/record-tuple-polyfill/blob/5f9cae34f0d331c4836efbc9cd618836c03e75f5/packages/record-tuple-polyfill/src/interngraph.js#L55

Theoretically couldn't the value be garbage collected between calls to ref.deref()? So therefore InternGraph.deref() could return undefined?

if (ref && ref.deref()) {
  return ref.deref();
}

Suggestion:

const existingValue = ref?.deref()
if (existingValue) {
  return existingValue;
}
mhofman commented 10 months ago

foo.deref() is guaranteed to return the same value when called in the same synchronous execution. Forcing a GC between the 2 calls here will never return undefined for the second call by spec