Browse files

update to use builtin WeakMap if available, builtin Map if available

  • Loading branch information...
1 parent 11fa776 commit b438b9cc97f7d2c0673e3cc43368dbee311ca86a @Benvie committed Oct 5, 2012
Showing with 251 additions and 208 deletions.
  1. +250 −207 harmony-collections.js
  2. +1 −1 harmony-collections.min.js
View
457 harmony-collections.js
@@ -100,107 +100,143 @@ void function(string_, object_, function_, prototype_, toString_,
// ### Data ###
// ############
- var MapData = (function(){
- var locker = 'return function(k){if(k===s)return l}',
- random = Math.random,
- uids = create(null),
- slice = callbind(''.slice),
- indexOf = callbind([].indexOf);
-
- var createUID = function(){
- var key = slice(numberToString(random(), 36), 2);
- return key in uids ? createUID() : uids[key] = key;
- };
+ var builtinWeakMap = 'WeakMap' in global;
- var globalID = createUID();
+ var MapData = builtinWeakMap
+ ? (function(){
+ var BuiltinWeakMap = global.WeakMap,
+ wmget = callbind(BuiltinWeakMap[prototype_].get),
+ wmset = callbind(BuiltinWeakMap[prototype_].set),
+ wmhas = callbind(BuiltinWeakMap[prototype_].has);
- // common per-object storage area made visible by patching getOwnPropertyNames'
- function getOwnPropertyNames(obj){
- var props = getProperties(obj);
- if (hasOwn(obj, globalID))
- splice(props, indexOf(props, globalID), 1);
- return props;
- }
+ function MapData(name){
+ var map = new BuiltinWeakMap;
+
+ this.get = function(o){
+ return wmget(map, o);
+ };
+ this.set = function(o, v){
+ wmset(map, o, v);
+ };
- if (es5) {
- // check for the random key on an object, create new storage if missing, return it
- var storage = function(obj){
- if (!hasOwn(obj, globalID))
- defineProperty(obj, globalID, { value: create(null) });
- return obj[globalID];
+ if (name) {
+ this.wrap = function(o, v){
+ if (wmhas(map, o))
+ throw new TypeError("Object is already a " + name);
+ wmset(map, o, v);
+ };
+ this.unwrap = function(o){
+ var storage = wmget(map, o);
+ if (!storage)
+ throw new TypeError(name + " is not generic");
+ return storage;
+ };
+ }
+ }
+
+ return MapData;
+ })()
+ : (function(){
+ var locker = 'return function(k){if(k===s)return l}',
+ random = Math.random,
+ uids = create(null),
+ slice = callbind(''.slice),
+ indexOf = callbind([].indexOf);
+
+ var createUID = function(){
+ var key = slice(numberToString(random(), 36), 2);
+ return key in uids ? createUID() : uids[key] = key;
};
- define(Object, getOwnPropertyNames);
- } else {
+ var globalID = createUID();
- var toStringToString = function(s){
- function toString(){ return s }
- return toString[toString_] = toString;
- }(Object[prototype_][toString_]+'');
+ // common per-object storage area made visible by patching getOwnPropertyNames'
+ function getOwnPropertyNames(obj){
+ var props = getProperties(obj);
+ if (hasOwn(obj, globalID))
+ splice(props, indexOf(props, globalID), 1);
+ return props;
+ }
- // store the values on a custom valueOf in order to hide them but store them locally
- var storage = function(obj){
- if (hasOwn(obj, toString_) && globalID in obj[toString_])
- return obj[toString_][globalID];
+ if (es5) {
+ // check for the random key on an object, create new storage if missing, return it
+ var storage = function(obj){
+ if (!hasOwn(obj, globalID))
+ defineProperty(obj, globalID, { value: create(null) });
+ return obj[globalID];
+ };
- if (!(toString_ in obj))
- throw new Error("Can't store values for "+obj);
+ define(Object, getOwnPropertyNames);
+ } else {
- var oldToString = obj[toString_];
- function toString(){ return oldToString.call(this) }
- obj[toString_] = toString;
- toString[toString_] = toStringToString;
- return toString[globalID] = {};
- };
- }
+ var toStringToString = function(s){
+ function toString(){ return s }
+ return toString[toString_] = toString;
+ }(Object[prototype_][toString_]+'');
+ // store the values on a custom valueOf in order to hide them but store them locally
+ var storage = function(obj){
+ if (hasOwn(obj, toString_) && globalID in obj[toString_])
+ return obj[toString_][globalID];
+ if (!(toString_ in obj))
+ throw new Error("Can't store values for "+obj);
- // shim for [[MapData]] from es6 spec, and pulls double duty as WeakMap storage
- function MapData(name){
- var puid = createUID(),
- iuid = createUID(),
- secret = {};
+ var oldToString = obj[toString_];
+ function toString(){ return oldToString.call(this) }
+ obj[toString_] = toString;
+ toString[toString_] = toStringToString;
+ return toString[globalID] = {};
+ };
+ }
- secret[iuid] = { writable: true, value: undefined };
- var attach = function(obj){
- var store = storage(obj);
- if (hasOwn(store, puid))
- return store[puid](secret);
- var lockbox = create(null, secret);
- defineProperty(store, puid, {
- value: new Function('s', 'l', locker)(secret, lockbox)
- });
- return lockbox;
- };
+ // shim for [[MapData]] from es6 spec, and pulls double duty as WeakMap storage
+ function MapData(name){
+ var puid = createUID(),
+ iuid = createUID(),
+ secret = {};
- this.get = function(o){
- return attach(o)[iuid];
- };
- this.set = function(o, v){
- return attach(o)[iuid] = v;
- };
+ secret[iuid] = { writable: true, value: undefined };
- if (name) {
- this.wrap = function(o, v){
- var lockbox = attach(o);
- if (lockbox[iuid])
- throw new TypeError("Object is already a " + name);
- lockbox[iuid] = v;
+ var attach = function(obj){
+ var store = storage(obj);
+ if (hasOwn(store, puid))
+ return store[puid](secret);
+
+ var lockbox = create(null, secret);
+ defineProperty(store, puid, {
+ value: new Function('s', 'l', locker)(secret, lockbox)
+ });
+ return lockbox;
+ };
+
+ this.get = function(o){
+ return attach(o)[iuid];
};
- this.unwrap = function(o){
- var storage = attach(o)[iuid];
- if (!storage)
- throw new TypeError(name + " is not generic");
- return storage;
+ this.set = function(o, v){
+ attach(o)[iuid] = v;
};
+
+ if (name) {
+ this.wrap = function(o, v){
+ var lockbox = attach(o);
+ if (lockbox[iuid])
+ throw new TypeError("Object is already a " + name);
+ lockbox[iuid] = v;
+ };
+ this.unwrap = function(o){
+ var storage = attach(o)[iuid];
+ if (!storage)
+ throw new TypeError(name + " is not generic");
+ return storage;
+ };
+ }
}
- }
- return MapData;
- }());
+ return MapData;
+ }());
var exporter = (function(){
// [native code] looks slightly different in each engine
@@ -275,11 +311,13 @@ void function(string_, object_, function_, prototype_, toString_,
}
}
+ var WM, HM, M;
+
// ###############
// ### WeakMap ###
// ###############
- var WM = exporter('WeakMap', function(wrap, unwrap){
+ WM = builtinWeakMap ? (exports.WeakMap = global.WeakMap) : exporter('WeakMap', function(wrap, unwrap){
var prototype = WeakMap[prototype_];
var validate = function(key){
if (key == null || typeof key !== object_ && typeof key !== function_)
@@ -361,7 +399,7 @@ void function(string_, object_, function_, prototype_, toString_,
// ### HashMap ###
// ###############
- var HM = exporter('HashMap', function(wrap, unwrap){
+ HM = exporter('HashMap', function(wrap, unwrap){
// separate numbers, strings, and atoms to compensate for key coercion to string
var prototype = HashMap[prototype_],
@@ -513,132 +551,138 @@ void function(string_, object_, function_, prototype_, toString_,
// ### Map ###
// ###########
- var M = exporter('Map', function(wrap, unwrap){
- var prototype = Map[prototype_],
- wm = WM[prototype_],
- hm = HM[prototype_],
- mget = [callbind(hm.get), callbind(wm.get)],
- mset = [callbind(hm.set), callbind(wm.set)],
- mhas = [callbind(hm.has), callbind(wm.has)],
- mdelete = [callbind(hm['delete']), callbind(wm['delete'])];
-
- var type = function(o){
- return o != null && typeof o === object_ || typeof o === function_ ? 1 : 0;
- }
-
- /**
- * @class Map
- * @description Collection that allows any kind of value to be a key.
- * @param {Iterable} [iterable] An item to populate the collection with.
- */
- function Map(iterable){
- if (this === global || this == null || this === prototype)
- return new Map(iterable);
-
- wrap(this, {
- 0: new HM,
- 1: new WM,
- keys: [],
- values: []
- });
-
- var self = this;
- iterable && initialize(iterable, function(value, key){
- call(set, self, value, key);
- });
- }
- /**
- * @method <get>
- * @description Retrieve the value in the collection that matches key
- * @param {Any} key
- * @return {Any}
- */
- function get(key){
- var data = unwrap(this),
- t = type(key);
- return data.values[mget[t](data[t], key)];
- }
- /**
- * @method <set>
- * @description Add or update a pair in the collection. Enforces uniqueness by overwriting.
- * @param {Any} key
- * @param {Any} val
- **/
- function set(key, value){
- var data = unwrap(this),
- t = type(key),
- index = mget[t](data[t], key);
-
- if (index === undefined) {
- mset[t](data[t], key, data.keys.length);
- push(data.keys, key);
- push(data.values, value);
- } else {
- data.keys[index] = key;
- data.values[index] = value;
+ if ('Map' in global && 'forEach' in global.Map.prototype) {
+ M = exports.Map = global.Map;
+ } else {
+ M = exporter('Map', function(wrap, unwrap){
+ var BuiltinMap = global.Map,
+ prototype = Map[prototype_],
+ wm = WM[prototype_],
+ hm = (BuiltinMap || HM)[prototype_],
+ mget = [callbind(hm.get), callbind(wm.get)],
+ mset = [callbind(hm.set), callbind(wm.set)],
+ mhas = [callbind(hm.has), callbind(wm.has)],
+ mdelete = [callbind(hm['delete']), callbind(wm['delete'])];
+
+ var type = BuiltinMap
+ ? function(){ return 0 }
+ : function(o){ return +(typeof o === object_ ? o !== null : typeof o === function_) }
+
+ var init = BuiltinMap
+ ? function(){ return { 0: new BuiltinMap } }
+ : function(){ return { 0: new HM, 1: new WM } };
+
+ /**
+ * @class Map
+ * @description Collection that allows any kind of value to be a key.
+ * @param {Iterable} [iterable] An item to populate the collection with.
+ */
+ function Map(iterable){
+ if (this === global || this == null || this === prototype)
+ return new Map(iterable);
+
+ var data = init();
+ data.keys = [];
+ data.values = [];
+ wrap(this, data);
+
+ var self = this;
+ iterable && initialize(iterable, function(value, key){
+ call(set, self, value, key);
+ });
+ }
+ /**
+ * @method <get>
+ * @description Retrieve the value in the collection that matches key
+ * @param {Any} key
+ * @return {Any}
+ */
+ function get(key){
+ var data = unwrap(this),
+ t = type(key);
+ return data.values[mget[t](data[t], key)];
+ }
+ /**
+ * @method <set>
+ * @description Add or update a pair in the collection. Enforces uniqueness by overwriting.
+ * @param {Any} key
+ * @param {Any} val
+ **/
+ function set(key, value){
+ var data = unwrap(this),
+ t = type(key),
+ index = mget[t](data[t], key);
+
+ if (index === undefined) {
+ mset[t](data[t], key, data.keys.length);
+ push(data.keys, key);
+ push(data.values, value);
+ } else {
+ data.keys[index] = key;
+ data.values[index] = value;
+ }
+ }
+ /**
+ * @method <has>
+ * @description Check if key exists in the collection.
+ * @param {Any} key
+ * @return {Boolean} is in collection
+ **/
+ function has(key){
+ var t = type(key);
+ return mhas[t](unwrap(this)[t], key);
+ }
+ /**
+ * @method <delete>
+ * @description Remove key and matching value if found
+ * @param {Any} key
+ * @return {Boolean} true if item was in collection
+ */
+ function delete_(key){
+ var data = unwrap(this),
+ t = type(key),
+ index = mget[t](data[t], key);
+
+ if (index === undefined)
+ return false;
+
+ mdelete[t](data[t], key);
+ splice(data.keys, index, 1);
+ splice(data.values, index, 1);
+ return true;
+ }
+ /**
+ * @method <size>
+ * @description Retrieve the amount of items in the collection
+ * @return {Number}
+ */
+ function size(){
+ return unwrap(this).keys.length;
+ }
+ /**
+ * @method <forEach>
+ * @description Loop through the collection raising callback for each
+ * @param {Function} callback `callback(value, key)`
+ * @param {Object} context The `this` binding for callbacks, default null
+ */
+ function forEach(callback, context){
+ var data = unwrap(this),
+ keys = data.keys,
+ values = data.values;
+
+ context = context == null ? global : context;
+
+ for (var i=0, len=keys.length; i < len; i++)
+ call(callback, context, values[i], keys[i], this);
}
- }
- /**
- * @method <has>
- * @description Check if key exists in the collection.
- * @param {Any} key
- * @return {Boolean} is in collection
- **/
- function has(key){
- var t = type(key);
- return mhas[t](unwrap(this)[t], key);
- }
- /**
- * @method <delete>
- * @description Remove key and matching value if found
- * @param {Any} key
- * @return {Boolean} true if item was in collection
- */
- function delete_(key){
- var data = unwrap(this),
- t = type(key),
- index = mget[t](data[t], key);
-
- if (index === undefined)
- return false;
-
- mdelete[t](data[t], key);
- splice(data.keys, index, 1);
- splice(data.values, index, 1);
- return true;
- }
- /**
- * @method <size>
- * @description Retrieve the amount of items in the collection
- * @return {Number}
- */
- function size(){
- return unwrap(this).keys.length;
- }
- /**
- * @method <forEach>
- * @description Loop through the collection raising callback for each
- * @param {Function} callback `callback(value, key)`
- * @param {Object} context The `this` binding for callbacks, default null
- */
- function forEach(callback, context){
- var data = unwrap(this),
- keys = data.keys,
- values = data.values;
-
- context = context == null ? global : context;
-
- for (var i=0, len=keys.length; i < len; i++)
- call(callback, context, values[i], keys[i], this);
- }
-
- delete_ = fixDelete(delete_,
- ['type', 'unwrap', 'call', 'splice'],
- [type, unwrap, call, splice]
- );
- return [Map, get, set, has, delete_, size, forEach];
- });
+ delete_ = fixDelete(delete_,
+ ['type', 'unwrap', 'call', 'splice'],
+ [type, unwrap, call, splice]
+ );
+ return [Map, get, set, has, delete_, size, forEach];
+ });
+ }
// ###########
@@ -725,4 +769,3 @@ void function(string_, object_, function_, prototype_, toString_,
}('string', 'object', 'function', 'prototype', 'toString',
Array, Object, Function, Function.prototype, (0, eval)('this'),
typeof exports === 'undefined' ? this : exports, {});
-
View
2 harmony-collections.min.js
@@ -18,4 +18,4 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-void function(D,y,j,b,c,s,f,C,g,i,x,A,d){var w=f.getOwnPropertyNames,m=typeof w===j&&!(b in w);var a=g.bind?g.bind.bind(g.call):function(a){return function(b){return function(){return a.apply(b,arguments)}}}(g.call);var J=a(g[c]),G=a({}[c]),H=a(0..toString),e=a(g.call),K=a(g.apply),p=a({}.hasOwnProperty),B=a([].push),q=a([].splice);var v=function(a){return typeof a!==j?'':'name'in a?a.name:J(a).match(/^\n?function\s?(\w*)?_?\(/)[1]};var h=m?f.create:function(e,a){var c=function(){};c[b]=f(e);var d=new c;if(a)for(var g in a)t(d,g,a[k]);return d};var t=m?f.defineProperty:function(a,b,c){return a[b]=c.value,a};var u=function(c,a,b){return typeof a===j&&(b=a,a=v(b).replace(/_$/,'')),t(c,a,{configurable:!0,writable:!0,value:b})};var I=m?function(a){return function(b){return a(b)||b instanceof s}}(s.isArray):function(a){return a instanceof s||G(a)==='[object Array]'};var r=function(){function getOwnPropertyNames(b){var a=w(b);return p(b,e)&&q(a,o(a,e),1),a}function r(e){var f=g(),a=g(),b={};b[a]={writable:!0,value:d};var c=function(d){var a=j(d);if(p(a,f))return a[f](b);var c=h(null,b);return t(a,f,{value:new C('s','l',k)(b,c)}),c};this.get=function(b){return c(b)[a]},this.set=function(b,d){return c(b)[a]=d},e&&(this.wrap=function(d,f){var b=c(d);if(b[a])throw new TypeError('Object is already a '+e);b[a]=f},this.unwrap=function(d){var b=c(d)[a];if(!b)throw new TypeError(e+' is not generic');return b})}var k='return function(k){if(k===s)return l}',l=Math.random,i=h(null),n=a(''.slice),o=a([].indexOf);var g=function(){var a=n(H(l(),36),2);return a in i?g():i[a]=a};var e=g();if(m){var j=function(a){return!p(a,e)&&t(a,e,{value:h(null)}),a[e]};u(f,getOwnPropertyNames)}else{var s=function(a){function toString(){return a}return toString[c]=toString}(f[b][c]+'');var j=function(a){function toString(){return b.call(this)}if(p(a,c)&&e in a[c])return a[c][e];if(!(c in a))throw new Error('Can\'t store values for '+a);var b=a[c];return a[c]=toString,toString[c]=s,toString[e]={}}}return r}();var l=function(){function toString(){return a[0]+v(this)+a[1]}var a=(''+f).split('Object');u(toString,toString);var c={__proto__:[]}instanceof s?function(a){a.__proto__=toString}:function(a){u(a,toString)};var d=function(a){function toString(){return f}var d=a.shift(),f='[object '+v(d)+']';a.push(toString),c(d);for(var e=0;e<a.length;e++)c(a[e]),u(d[b],a[e]);return d};return function(a,c){if(a in x)return x[a];var b=new r(a);return x[a]=d(c(function(a,c){b.wrap(a,c)},function(a){return b.unwrap(a)}))}}();var o=function(a,b){a!==null&&typeof a===y&&typeof a.forEach===j&&a.forEach(function(d,c){I(d)&&d.length===2?b(a[c][0],a[c][1]):b(a[c],c)})};var n=function(b,a,c){try{return a[a.length]=('return '+b).replace('e_','\\u0065'),C.apply(0,a).apply(0,c)}catch(a){return b}};var F=l('WeakMap',function(f,a){function WeakMap(a){if(this===i||this==null||this===g)return new WeakMap(a);f(this,new r);var b=this;a&&o(a,function(a,c){e(set,b,a,c)})}function get(b){c(b);var e=a(this).get(b);return e===A?d:e}function set(b,e){c(b),a(this).set(b,e===d?A:e)}function has(b){return c(b),a(this).get(b)!==d}function delete_(b){c(b);var e=a(this);return e.get(b)===d?!1:(e.set(b,d),!0)}var g=WeakMap[b];var c=function(a){if(a==null||typeof a!==y&&typeof a!==j)throw new TypeError('Invalid WeakMap key')};return delete_=n(delete_,['c','a'],[c,a]),[WeakMap,get,set,has,delete_]});var z=l('HashMap',function(m,a){function HashMap(a){if(this===i||this==null||this===q)return new HashMap(a);m(this,{size:0,0:h(null),1:h(null),2:h(null)});var b=this;a&&o(a,function(a,c){e(set,b,a,c)})}function get(b){return a(this)[d(b)][c(b)]}function set(b,g){var e=a(this),f=e[d(b)];b=c(b),b in f||e.size++,f[b]=g}function has(b){return c(b)in a(this)[d(b)]}function delete_(b){var e=a(this),f=e[d(b)];return b=c(b),b in f?(delete f[b],e.size--,!0):!1}function size(){return a(this).size}function forEach(g,c){var d=a(this);c=c==null?i:c;for(var b=0;b<3;b++)for(var f in d[b])e(g,c,d[b][f],r(b,f),this)}var q=HashMap[b],g=0,j=1,f=2,p={'true':!0,'false':!1,'null':null,0:-0};if('toString'in h(null)){var c=function(a){return typeof a===D?'_'+a:''+a};var k=function(a){return a.slice(1)}}else{var l=Math.random().toString(36).slice(2);var k=function(a){return a===l?'__proto__':a};var c=function(a){return a==='__proto__'?l:a}}var r=function(b,a){switch(b){case g:return k(a);case j:return+a;case f:return p[a]}};var d=function(a){if(a==null)return f;switch(typeof a){case'boolean':return f;case D:return g;case'number':return a===0&&Infinity/a===-Infinity?f:j;default:throw new TypeError('Invalid HashMap key')}};return delete_=n(delete_,['d','a','c'],[d,a,c]),[HashMap,get,set,has,delete_,size,forEach]});var E=l('Map',function(m,c){function Map(a){if(this===i||this==null||this===l)return new Map(a);m(this,{0:new z,1:new F,keys:[],values:[]});var b=this;a&&o(a,function(a,c){e(set,b,a,c)})}function get(a){var b=c(this),d=f(a);return b.values[k[d](b[d],a)]}function set(b,h){var a=c(this),e=f(b),g=k[e](a[e],b);g===d?(p[e](a[e],b,a.keys.length),B(a.keys,b),B(a.values,h)):(a.keys[g]=b,a.values[g]=h)}function has(a){var b=f(a);return r[b](c(this)[b],a)}function delete_(e){var a=c(this),b=f(e),g=k[b](a[b],e);return g===d?!1:(s[b](a[b],e),q(a.keys,g,1),q(a.values,g,1),!0)}function size(){return c(this).keys.length}function forEach(g,a){var d=c(this),f=d.keys,h=d.values;a=a==null?i:a;for(var b=0,j=f.length;b<j;b++)e(g,a,h[b],f[b],this)}var l=Map[b],h=F[b],g=z[b],k=[a(g.get),a(h.get)],p=[a(g.set),a(h.set)],r=[a(g.has),a(h.has)],s=[a(g['delete']),a(h['delete'])];var f=function(a){return a!=null&&typeof a===y||typeof a===j?1:0};return delete_=n(delete_,['f','c','e','q'],[f,c,e,q]),[Map,get,set,has,delete_,size,forEach]});l('Set',function(j,c){function Set(a){if(this===i||this==null||this===g)return new Set(a);j(this,new E);var b=this;a&&o(a,function(c,a){e(add,b,a)})}function add(a){m(c(this),a,a)}function has(a){return l(c(this),a)}function delete_(a){return f(c(this),a)}function size(){return h(c(this))}function forEach(a,b){var d=0,f=this;k(c(this,function(b){e(a,this,b,d++,f)},b))}var g=Set[b],d=E[b],h=a(d.size),k=a(d.forEach),p=a(d.get),m=a(d.set),l=a(d.has),f=a(d['delete']);return delete_=n(delete_,['f','c'],[f,c]),[Set,add,has,delete_,size,forEach]})}('string','object','function','prototype','toString',Array,Object,Function,Function.prototype,(0,eval)('this'),typeof exports==='undefined'?this:exports,{})
+void function(G,A,l,b,d,t,h,F,i,c,m,E,e){var z=h.getOwnPropertyNames,r=typeof z===l&&!(b in z);var a=i.bind?i.bind.bind(i.call):function(a){return function(b){return function(){return a.apply(b,arguments)}}}(i.call);var J=a(i[d]),K=a({}[d]),H=a(0..toString),f=a(i.call),L=a(i.apply),q=a({}.hasOwnProperty),D=a([].push),s=a([].splice);var x=function(a){return typeof a!==l?'':'name'in a?a.name:J(a).match(/^\n?function\s?(\w*)?_?\(/)[1]};var g=r?h.create:function(e,a){var c=function(){};c[b]=h(e);var d=new c;if(a)for(var f in a)u(d,f,a[k]);return d};var u=r?h.defineProperty:function(a,b,c){return a[b]=c.value,a};var v=function(c,a,b){return typeof a===l&&(b=a,a=x(b).replace(/_$/,'')),u(c,a,{configurable:!0,writable:!0,value:b})};var I=r?function(a){return function(b){return a(b)||b instanceof t}}(t.isArray):function(a){return a instanceof t||K(a)==='[object Array]'};var C='WeakMap'in c;var j=C?function(){function j(b){var a=new d;this.get=function(b){return e(a,b)},this.set=function(b,c){f(a,b,c)},b&&(this.wrap=function(c,d){if(g(a,c))throw new TypeError('Object is already a '+b);f(a,c,d)},this.unwrap=function(d){var c=e(a,d);if(!c)throw new TypeError(b+' is not generic');return c})}var d=c.WeakMap,e=a(d[b].get),f=a(d[b].set),g=a(d[b].has);return j}():function(){function getOwnPropertyNames(b){var a=z(b);return q(b,c)&&s(a,o(a,c),1),a}function j(d){var h=f(),a=f(),b={};b[a]={writable:!0,value:e};var c=function(d){var a=k(d);if(q(a,h))return a[h](b);var c=g(null,b);return u(a,h,{value:new F('s','l',l)(b,c)}),c};this.get=function(b){return c(b)[a]},this.set=function(b,d){c(b)[a]=d},d&&(this.wrap=function(e,f){var b=c(e);if(b[a])throw new TypeError('Object is already a '+d);b[a]=f},this.unwrap=function(e){var b=c(e)[a];if(!b)throw new TypeError(d+' is not generic');return b})}var l='return function(k){if(k===s)return l}',m=Math.random,i=g(null),n=a(''.slice),o=a([].indexOf);var f=function(){var a=n(H(m(),36),2);return a in i?f():i[a]=a};var c=f();if(r){var k=function(a){return!q(a,c)&&u(a,c,{value:g(null)}),a[c]};v(h,getOwnPropertyNames)}else{var p=function(a){function toString(){return a}return toString[d]=toString}(h[b][d]+'');var k=function(a){function toString(){return b.call(this)}if(q(a,d)&&c in a[d])return a[d][c];if(!(d in a))throw new Error('Can\'t store values for '+a);var b=a[d];return a[d]=toString,toString[d]=p,toString[c]={}}}return j}();var n=function(){function toString(){return a[0]+x(this)+a[1]}var a=(''+h).split('Object');v(toString,toString);var c={__proto__:[]}instanceof t?function(a){a.__proto__=toString}:function(a){v(a,toString)};var d=function(a){function toString(){return f}var d=a.shift(),f='[object '+x(d)+']';a.push(toString),c(d);for(var e=0;e<a.length;e++)c(a[e]),v(d[b],a[e]);return d};return function(a,c){if(a in m)return m[a];var b=new j(a);return m[a]=d(c(function(a,c){b.wrap(a,c)},function(a){return b.unwrap(a)}))}}();var o=function(a,b){a!==null&&typeof a===A&&typeof a.forEach===l&&a.forEach(function(d,c){I(d)&&d.length===2?b(a[c][0],a[c][1]):b(a[c],c)})};var p=function(b,a,c){try{return a[a.length]=('return '+b).replace('e_','\\u0065'),F.apply(0,a).apply(0,c)}catch(a){return b}};var B,y,w;B=C?m.WeakMap=c.WeakMap:n('WeakMap',function(g,a){function WeakMap(a){if(this===c||this==null||this===h)return new WeakMap(a);g(this,new j);var b=this;a&&o(a,function(a,c){f(set,b,a,c)})}function get(b){d(b);var c=a(this).get(b);return c===E?e:c}function set(b,c){d(b),a(this).set(b,c===e?E:c)}function has(b){return d(b),a(this).get(b)!==e}function delete_(b){d(b);var c=a(this);return c.get(b)===e?!1:(c.set(b,e),!0)}var h=WeakMap[b];var d=function(a){if(a==null||typeof a!==A&&typeof a!==l)throw new TypeError('Invalid WeakMap key')};return delete_=p(delete_,['d','a'],[d,a]),[WeakMap,get,set,has,delete_]}),y=n('HashMap',function(m,a){function HashMap(a){if(this===c||this==null||this===q)return new HashMap(a);m(this,{size:0,0:g(null),1:g(null),2:g(null)});var b=this;a&&o(a,function(a,c){f(set,b,a,c)})}function get(b){return a(this)[e(b)][d(b)]}function set(b,g){var c=a(this),f=c[e(b)];b=d(b),b in f||c.size++,f[b]=g}function has(b){return d(b)in a(this)[e(b)]}function delete_(b){var c=a(this),f=c[e(b)];return b=d(b),b in f?(delete f[b],c.size--,!0):!1}function size(){return a(this).size}function forEach(h,d){var e=a(this);d=d==null?c:d;for(var b=0;b<3;b++)for(var g in e[b])f(h,d,e[b][g],r(b,g),this)}var q=HashMap[b],i=0,j=1,h=2,n={'true':!0,'false':!1,'null':null,0:-0};if('toString'in g(null)){var d=function(a){return typeof a===G?'_'+a:''+a};var k=function(a){return a.slice(1)}}else{var l=Math.random().toString(36).slice(2);var k=function(a){return a===l?'__proto__':a};var d=function(a){return a==='__proto__'?l:a}}var r=function(b,a){switch(b){case i:return k(a);case j:return+a;case h:return n[a]}};var e=function(a){if(a==null)return h;switch(typeof a){case'boolean':return h;case G:return i;case'number':return a===0&&Infinity/a===-Infinity?h:j;default:throw new TypeError('Invalid HashMap key')}};return delete_=p(delete_,['e','a','d'],[e,a,d]),[HashMap,get,set,has,delete_,size,forEach]}),'Map'in c&&'forEach'in c.Map.prototype?w=m.Map=c.Map:w=n('Map',function(m,d){function Map(a){if(this===c||this==null||this===n)return new Map(a);var b=u();b.keys=[],b.values=[],m(this,b);var d=this;a&&o(a,function(a,b){f(set,d,a,b)})}function get(a){var b=d(this),c=g(a);return b.values[k[c](b[c],a)]}function set(b,h){var a=d(this),c=g(b),f=k[c](a[c],b);f===e?(q[c](a[c],b,a.keys.length),D(a.keys,b),D(a.values,h)):(a.keys[f]=b,a.values[f]=h)}function has(a){var b=g(a);return r[b](d(this)[b],a)}function delete_(c){var a=d(this),b=g(c),f=k[b](a[b],c);return f===e?!1:(t[b](a[b],c),s(a.keys,f,1),s(a.values,f,1),!0)}function size(){return d(this).keys.length}function forEach(h,a){var e=d(this),g=e.keys,i=e.values;a=a==null?c:a;for(var b=0,j=g.length;b<j;b++)f(h,a,i[b],g[b],this)}var i=c.Map,n=Map[b],j=B[b],h=(i||y)[b],k=[a(h.get),a(j.get)],q=[a(h.set),a(j.set)],r=[a(h.has),a(j.has)],t=[a(h['delete']),a(j['delete'])];var g=i?function(){return 0}:function(a){return+(typeof a===A?a!==null:typeof a===l)};var u=i?function(){return{0:new i}}:function(){return{0:new y,1:new B}};return delete_=p(delete_,['g','d','f','s'],[g,d,f,s]),[Map,get,set,has,delete_,size,forEach]}),n('Set',function(j,d){function Set(a){if(this===c||this==null||this===h)return new Set(a);j(this,new w);var b=this;a&&o(a,function(c,a){f(add,b,a)})}function add(a){m(d(this),a,a)}function has(a){return l(d(this),a)}function delete_(a){return g(d(this),a)}function size(){return i(d(this))}function forEach(a,b){var c=0,e=this;k(d(this,function(b){f(a,this,b,c++,e)},b))}var h=Set[b],e=w[b],i=a(e.size),k=a(e.forEach),n=a(e.get),m=a(e.set),l=a(e.has),g=a(e['delete']);return delete_=p(delete_,['g','d'],[g,d]),[Set,add,has,delete_,size,forEach]})}('string','object','function','prototype','toString',Array,Object,Function,Function.prototype,(0,eval)('this'),typeof exports==='undefined'?this:exports,{})

0 comments on commit b438b9c

Please sign in to comment.