es6-weak-map
Advanced tools
Comparing version 0.1.2 to 0.1.3
'use strict'; | ||
module.exports = require('./is-implemented')() ? | ||
WeakMap : require('./polyfill'); | ||
module.exports = require('./is-implemented')() ? WeakMap : require('./polyfill'); |
'use strict'; | ||
module.exports = function () { | ||
var map; | ||
var weakMap, x; | ||
if (typeof WeakMap !== 'function') return false; | ||
map = new WeakMap(); | ||
if (typeof map.set !== 'function') return false; | ||
if (map.set({}, 1) !== map) return false; | ||
if (typeof map.clear !== 'function') return false; | ||
if (typeof map.delete !== 'function') return false; | ||
if (typeof map.has !== 'function') return false; | ||
if (String(WeakMap.prototype) !== '[object WeakMap]') return false; | ||
try { | ||
// WebKit doesn't support arguments and crashes | ||
weakMap = new WeakMap([[x = {}, 'one'], [{}, 'two'], [{}, 'three']]); | ||
} catch (e) { | ||
return false; | ||
} | ||
if (typeof weakMap.set !== 'function') return false; | ||
if (weakMap.set({}, 1) !== weakMap) return false; | ||
if (typeof weakMap.delete !== 'function') return false; | ||
if (typeof weakMap.has !== 'function') return false; | ||
if (weakMap.get(x) !== 'one') return false; | ||
return true; | ||
}; |
{ | ||
"name": "es6-weak-map", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "ECMAScript6 WeakMap polyfill", | ||
@@ -22,10 +22,14 @@ "author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)", | ||
"d": "~0.1.1", | ||
"es5-ext": "~0.10.4", | ||
"es6-iterator": "~0.1.1", | ||
"es6-symbol": "0.1.x" | ||
"es5-ext": "~0.10.6", | ||
"es6-iterator": "~0.1.3", | ||
"es6-symbol": "~2.0.1" | ||
}, | ||
"devDependencies": { | ||
"tad": "0.2.x" | ||
"tad": "~0.2.2", | ||
"xlint": "~0.2.2", | ||
"xlint-jslint-medikoo": "~0.1.2" | ||
}, | ||
"scripts": { | ||
"lint": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --no-cache --no-stream", | ||
"lint-console": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --watch", | ||
"test": "node ./node_modules/tad/bin/tad" | ||
@@ -32,0 +36,0 @@ }, |
@@ -6,2 +6,3 @@ 'use strict'; | ||
, value = require('es5-ext/object/valid-value') | ||
, randomUniq = require('es5-ext/string/random-uniq') | ||
, d = require('d') | ||
@@ -13,31 +14,21 @@ , getIterator = require('es6-iterator/get') | ||
, isArray = Array.isArray, defineProperty = Object.defineProperty, random = Math.random | ||
, hasOwnProperty = Object.prototype.hasOwnProperty | ||
, genId, WeakMapPoly; | ||
, isArray = Array.isArray, defineProperty = Object.defineProperty | ||
, hasOwnProperty = Object.prototype.hasOwnProperty, getPrototypeOf = Object.getPrototypeOf | ||
, WeakMapPoly; | ||
genId = (function () { | ||
var generated = Object.create(null); | ||
return function () { | ||
var id; | ||
do { id = random().toString(36).slice(2); } while (generated[id]); | ||
generated[id] = true; | ||
return id; | ||
}; | ||
}()); | ||
module.exports = WeakMapPoly = function (/*iterable*/) { | ||
var iterable = arguments[0]; | ||
if (!(this instanceof WeakMapPoly)) return new WeakMapPoly(iterable); | ||
if (this.__weakMapData__ !== undefined) { | ||
throw new TypeError(this + " cannot be reinitialized"); | ||
} | ||
var iterable = arguments[0], self; | ||
if (!(this instanceof WeakMapPoly)) throw new TypeError('Constructor requires \'new\''); | ||
if (isNative && setPrototypeOf) self = setPrototypeOf(new WeakMap(), getPrototypeOf(this)); | ||
else self = this; | ||
if (iterable != null) { | ||
if (!isArray(iterable)) iterable = getIterator(iterable); | ||
} | ||
defineProperty(this, '__weakMapData__', d('c', '$weakMap$' + genId())); | ||
if (!iterable) return; | ||
defineProperty(self, '__weakMapData__', d('c', '$weakMap$' + randomUniq())); | ||
if (!iterable) return self; | ||
forOf(iterable, function (val) { | ||
value(val); | ||
this.set(val[0], val[1]); | ||
}, this); | ||
self.set(val[0], val[1]); | ||
}); | ||
return self; | ||
}; | ||
@@ -53,5 +44,2 @@ | ||
Object.defineProperties(WeakMapPoly.prototype, { | ||
clear: d(function () { | ||
defineProperty(this, '__weakMapData__', d('c', '$weakMap$' + genId())); | ||
}), | ||
delete: d(function (key) { | ||
@@ -58,0 +46,0 @@ if (hasOwnProperty.call(object(key), this.__weakMapData__)) { |
@@ -63,4 +63,4 @@ # es6-weak-map | ||
## Tests [![Build Status](https://travis-ci.org/medikoo/es6-weak-map.png)](https://travis-ci.org/medikoo/es6-weak-map) | ||
## Tests [![Build Status](https://travis-ci.org/medikoo/es6-weak-map.svg)](https://travis-ci.org/medikoo/es6-weak-map) | ||
$ npm test |
'use strict'; | ||
module.exports = function (t, a) { a(typeof t(), 'boolean'); }; | ||
var global = require('es5-ext/global') | ||
, polyfill = require('../polyfill'); | ||
module.exports = function (t, a) { | ||
var cache; | ||
a(typeof t(), 'boolean'); | ||
cache = global.WeakMap; | ||
global.WeakMap = polyfill; | ||
a(t(), true); | ||
if (cache === undefined) delete global.WeakMap; | ||
else global.WeakMap = cache; | ||
}; |
@@ -19,5 +19,6 @@ 'use strict'; | ||
a(map.has(y), true, "Has: pre clear"); | ||
map.clear(); | ||
a(map.has(y), false, "Has: after clear"); | ||
a.h1("Empty initialization"); | ||
map = new T(); | ||
map.set(x, 'bar'); | ||
a(map.get(x), 'bar'); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11333
179
3
- Removedes6-symbol@0.1.1(transitive)
Updatedes5-ext@~0.10.6
Updatedes6-iterator@~0.1.3
Updatedes6-symbol@~2.0.1