Proposal: Abstract References

Mark S. Miller erights at google.com
Wed Oct 22 07:48:25 PDT 2014


Should be



var WeakMap;

(function() {
   'use strict';

   var SlowWeakMap = WeakMap;

   function FastWeakMap() {
     var token = Object.freeze(Object.create(null));
     return Object.freeze({
       get: function(key) {
         var shadow = key.[[Shadow]];
         return shadow ? shadow.get(token) : void 0;
       },
       set: function(key, value) {
         var shadow = key.[[Shadow]]
         if (!shadow) {
           shadow = new SlowWeakMap();
           key.[[Shadow]] = shadow;
         }
         shadow.set(token, value);
       },
       clear: function() {
         token = Object.freeze(Object.create({}));
       }
     });
   }

   // Don't do this until it is a complete shim
   // WeakMap = FastWeakMap;

 }());
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141022/e89bc85b/attachment.html>


More information about the es-discuss mailing list