A different semantics for WeakMap#get default value

Mark S. Miller erights at google.com
Thu Jan 19 09:24:53 PST 2012

On Thu, Jan 19, 2012 at 12:44 AM, Andreas Rossberg <rossberg at google.com>wrote:

> On 19 January 2012 07:51, Mark S. Miller <erights at google.com> wrote:
> >
> > Because an instance of InfiniteMap conforms to the full Map contract
> (given
> > that baseMap does and is not otherwise used), we have full Liskov
> > substitutability -- you can validly pass an InfiniteMap to an abstraction
> > expecting a Map.
> PS: Won't the "full Map contract" eventually contain iterators, too?
> An infinite map cannot sensibly support those.
Depends what you mean by "sensibly". I see nothing at
http://wiki.ecmascript.org/doku.php?id=harmony:iterators that implies that
iterators must or even should terminate. And infinite iterators (in general
though not here) are clearly useful.

However, I agree that doing an infinite iteration over an InfiniteMap is
unlikely to be useful. For example, the contract can almost be trivially
and uselessly satisfied by having the InfiniteMap return the following
"items" (key-value pair) iterator:

    { next: function() { return [{}, lazyFactory()]; } }

Since each of these keys are fresh, we know we don't need to consult the
baseMap for an overriding mapping. Since there are an infinite number of
such keys, we know they'll never run out, so we can indefinitely postpone
ever needing to return a meaningful mapping. However the "almost" qualifier
above is because, to be correct, the iterator would have to store the new
useless associations in the baseMap before returning them -- making this
technique even more useless.

Infinities are indeed weird.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120119/e4719749/attachment.html>

More information about the es-discuss mailing list