On May 11, 2011, at 12:44 PM, Oliver Hunt wrote:
> So you want to do
> if (map.has(bar))
> wiffle = map.get(bar)
>
> or some such?
>
> The problem here is that you can't guarantee that GC won't happen between
> those two calls, and therefore you could still end up getting undefined in
> response to the get.
Not if bar refers to the key object, since it must be a strong ref.
If you do
if (map.has(bar)) {
bar = null;
// might GC here, or do stuff that might
wiffle = map.get(bar);
. . .
}
then you get what you deserve.
> GC is (from the language's perspective) non-deterministic, so any non-atomic
> operation with a weak map leads to "non-sensical" behaviour.
True, but this does not apply to
if (map.has(bar))
wiffle = map.get(bar);
as written.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss