pax_global_header00006660000000000000000000000064134764757040014533gustar00rootroot0000000000000052 comment=ac5868ab3b511552dca5fca178b1d118fed93653 es6-weak-map-2.0.3/000077500000000000000000000000001347647570400137325ustar00rootroot00000000000000es6-weak-map-2.0.3/.editorconfig000066400000000000000000000004171347647570400164110ustar00rootroot00000000000000# EditorConfig is awesome: http://EditorConfig.org # top-most EditorConfig file root = true # Unix-style newlines with a newline ending every file [*] end_of_line = lf insert_final_newline = true indent_style = tab [{*.json,*.yml}] indent_style = space indent_size = 2es6-weak-map-2.0.3/.gitignore000066400000000000000000000001061347647570400157170ustar00rootroot00000000000000.DS_Store /node_modules /npm-debug.log /.lintcache /package-lock.json es6-weak-map-2.0.3/CHANGELOG.md000066400000000000000000000004271347647570400155460ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. ### [2.0.3](https://github.com/medikoo/es6-weak-map/compare/v2.0.2...v2.0.3) (2019-06-07) es6-weak-map-2.0.3/CHANGES000066400000000000000000000025501347647570400147270ustar00rootroot00000000000000v2.0.2 -- 2017.03.15 * Update dependencies v2.0.1 -- 2015.10.02 * Update to use es6-symbol at v3 v2.0.0 -- 2015.09.04 * Relax native implementation detection, stringification of instance should returm expected result (not necesarily prototype) v1.0.2 -- 2015.05.07 * Add "ponyfill" keyword to meta description. Fixes #7 v1.0.1 -- 2015.04.14 * Fix isNativeImplemented, so it's not affected by #3619 V8 bug * Fix internal prototype resolution, in case where isNativeImplemented was true, and native implementation was shadowed it got into stack overflow v1.0.0 -- 2015.04.13 * It's v0.1.3 republished as v1.0.0 v0.1.4 -- 2015.04.13 * Republish v0.1.2 as v0.1.4 due to breaking changes (v0.1.3 should have been published as next major) v0.1.3 -- 2015.04.12 * Update up to changes in specification (require new, remove clear method) * Improve native implementation validation * Configure lint scripts * Rename LICENCE to LICENSE v0.1.2 -- 2014.09.01 * Use internal random and unique id generator instead of external (time-uuid based). Global uniqueness is not needed in scope of this module. Fixes #1 v0.1.1 -- 2014.05.15 * Improve valid WeakMap detection v0.1.0 -- 2014.04.29 * Assure to depend only npm hosted dependencies * Update to use latest versions of dependencies * Use ES6 symbols internally v0.0.0 -- 2013.10.24 Initial (dev version) es6-weak-map-2.0.3/LICENSE000066400000000000000000000014051347647570400147370ustar00rootroot00000000000000ISC License Copyright (c) 2013-2018, Mariusz Nowak, @medikoo, medikoo.com Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. es6-weak-map-2.0.3/README.md000066400000000000000000000045331347647570400152160ustar00rootroot00000000000000[![Build status][nix-build-image]][nix-build-url] [![Windows status][win-build-image]][win-build-url] ![Transpilation status][transpilation-image] [![npm version][npm-image]][npm-url] # es6-weak-map ## WeakMap collection as specified in ECMAScript6 _Roughly inspired by Mark Miller's and Kris Kowal's [WeakMap implementation](https://github.com/drses/weak-map)_. Differences are: - Assumes compliant ES5 environment (no weird ES3 workarounds or hacks) - Well modularized CJS style - Based on one solution. ### Limitations - Will fail on non extensible objects provided as keys ### Installation $ npm install es6-weak-map To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/) ### Usage If you want to make sure your environment implements `WeakMap`, do: ```javascript require("es6-weak-map/implement"); ``` If you'd like to use native version when it exists and fallback to polyfill if it doesn't, but without implementing `WeakMap` on global scope, do: ```javascript var WeakMap = require("es6-weak-map"); ``` If you strictly want to use polyfill even if native `WeakMap` exists, do: ```javascript var WeakMap = require("es6-weak-map/polyfill"); ``` #### API Best is to refer to [specification](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-weakmap-objects). Still if you want quick look, follow example: ```javascript var WeakMap = require("es6-weak-map"); var map = new WeakMap(); var obj = {}; map.set(obj, "foo"); // map map.get(obj); // 'foo' map.has(obj); // true map.delete(obj); // true map.get(obj); // undefined map.has(obj); // false map.set(obj, "bar"); // map map.has(obj); // false ``` ## Tests $ npm test [nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/es6-weak-map/branches/master/shields_badge.svg [nix-build-url]: https://semaphoreci.com/medikoo-org/es6-weak-map [win-build-image]: https://ci.appveyor.com/api/projects/status/1c73c57pg4s6lwmu?svg=true [win-build-url]: https://ci.appveyor.com/project/medikoo/es6-weak-map [transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg [npm-image]: https://img.shields.io/npm/v/es6-weak-map.svg [npm-url]: https://www.npmjs.com/package/es6-weak-map es6-weak-map-2.0.3/implement.js000066400000000000000000000003361347647570400162640ustar00rootroot00000000000000"use strict"; if (!require("./is-implemented")()) { Object.defineProperty(require("es5-ext/global"), "WeakMap", { value: require("./polyfill"), configurable: true, enumerable: false, writable: true }); } es6-weak-map-2.0.3/index.js000066400000000000000000000001411347647570400153730ustar00rootroot00000000000000"use strict"; module.exports = require("./is-implemented")() ? WeakMap : require("./polyfill"); es6-weak-map-2.0.3/is-implemented.js000066400000000000000000000011551347647570400172060ustar00rootroot00000000000000"use strict"; module.exports = function () { var weakMap, obj; if (typeof WeakMap !== "function") return false; try { // WebKit doesn't support arguments and crashes weakMap = new WeakMap([[obj = {}, "one"], [{}, "two"], [{}, "three"]]); } catch (e) { return false; } if (String(weakMap) !== "[object WeakMap]") 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(obj) !== "one") return false; return true; }; es6-weak-map-2.0.3/is-native-implemented.js000066400000000000000000000004211347647570400204650ustar00rootroot00000000000000// Exports true if environment provides native `WeakMap` implementation, whatever that is. "use strict"; module.exports = (function () { if (typeof WeakMap !== "function") return false; return Object.prototype.toString.call(new WeakMap()) === "[object WeakMap]"; }()); es6-weak-map-2.0.3/is-weak-map.js000066400000000000000000000006231347647570400164040ustar00rootroot00000000000000"use strict"; var toStringTagSymbol = require("es6-symbol").toStringTag , objToString = Object.prototype.toString , id = "[object WeakMap]" , Global = typeof WeakMap === "undefined" ? null : WeakMap; module.exports = function (value) { return (value && ((Global && (value instanceof Global)) || (objToString.call(value) === id) || (value[toStringTagSymbol] === "WeakMap"))) || false; }; es6-weak-map-2.0.3/package.json000066400000000000000000000016031347647570400162200ustar00rootroot00000000000000{ "name": "es6-weak-map", "version": "2.0.3", "description": "ECMAScript6 WeakMap polyfill", "author": "Mariusz Nowak (http://www.medikoo.com/)", "keywords": [ "map", "weakmap", "collection", "es6", "harmony", "list", "hash", "gc", "ponyfill" ], "repository": { "type": "git", "url": "git://github.com/medikoo/es6-weak-map.git" }, "dependencies": { "d": "1", "es5-ext": "^0.10.46", "es6-iterator": "^2.0.3", "es6-symbol": "^3.1.1" }, "devDependencies": { "eslint": "^5.5", "eslint-config-medikoo-es5": "^1.7", "tad": "^0.2.8" }, "eslintConfig": { "extends": "medikoo-es5", "root": true, "globals": { "WeakMap": true } }, "scripts": { "lint": "eslint --ignore-path=.gitignore .", "test": "node ./node_modules/tad/bin/tad" }, "license": "ISC" } es6-weak-map-2.0.3/polyfill.js000066400000000000000000000043561347647570400161320ustar00rootroot00000000000000"use strict"; var isValue = require("es5-ext/object/is-value") , setPrototypeOf = require("es5-ext/object/set-prototype-of") , object = require("es5-ext/object/valid-object") , ensureValue = require("es5-ext/object/valid-value") , randomUniq = require("es5-ext/string/random-uniq") , d = require("d") , getIterator = require("es6-iterator/get") , forOf = require("es6-iterator/for-of") , toStringTagSymbol = require("es6-symbol").toStringTag , isNative = require("./is-native-implemented") , isArray = Array.isArray, defineProperty = Object.defineProperty , objHasOwnProperty = Object.prototype.hasOwnProperty, getPrototypeOf = Object.getPrototypeOf , WeakMapPoly; module.exports = WeakMapPoly = function (/* Iterable*/) { var iterable = arguments[0], self; if (!(this instanceof WeakMapPoly)) throw new TypeError("Constructor requires 'new'"); self = isNative && setPrototypeOf && (WeakMap !== WeakMapPoly) ? setPrototypeOf(new WeakMap(), getPrototypeOf(this)) : this; if (isValue(iterable)) { if (!isArray(iterable)) iterable = getIterator(iterable); } defineProperty(self, "__weakMapData__", d("c", "$weakMap$" + randomUniq())); if (!iterable) return self; forOf(iterable, function (val) { ensureValue(val); self.set(val[0], val[1]); }); return self; }; if (isNative) { if (setPrototypeOf) setPrototypeOf(WeakMapPoly, WeakMap); WeakMapPoly.prototype = Object.create(WeakMap.prototype, { constructor: d(WeakMapPoly) }); } Object.defineProperties(WeakMapPoly.prototype, { delete: d(function (key) { if (objHasOwnProperty.call(object(key), this.__weakMapData__)) { delete key[this.__weakMapData__]; return true; } return false; }), get: d(function (key) { if (!objHasOwnProperty.call(object(key), this.__weakMapData__)) return undefined; return key[this.__weakMapData__]; }), has: d(function (key) { return objHasOwnProperty.call(object(key), this.__weakMapData__); }), set: d(function (key, value) { defineProperty(object(key), this.__weakMapData__, d("c", value)); return this; }), toString: d(function () { return "[object WeakMap]"; }) }); defineProperty(WeakMapPoly.prototype, toStringTagSymbol, d("c", "WeakMap")); es6-weak-map-2.0.3/test/000077500000000000000000000000001347647570400147115ustar00rootroot00000000000000es6-weak-map-2.0.3/test/implement.js000066400000000000000000000001251347647570400172370ustar00rootroot00000000000000"use strict"; module.exports = function (t, a) { a(typeof WeakMap, "function"); }; es6-weak-map-2.0.3/test/index.js000066400000000000000000000001621347647570400163550ustar00rootroot00000000000000"use strict"; module.exports = function (T, a) { var obj = {}; a((new T([[obj, "foo"]])).get(obj), "foo"); }; es6-weak-map-2.0.3/test/is-implemented.js000066400000000000000000000005171347647570400201660ustar00rootroot00000000000000"use strict"; var globalObj = require("es5-ext/global") , polyfill = require("../polyfill"); module.exports = function (t, a) { var cache; a(typeof t(), "boolean"); cache = globalObj.WeakMap; globalObj.WeakMap = polyfill; a(t(), true); if (cache === undefined) delete globalObj.WeakMap; else globalObj.WeakMap = cache; }; es6-weak-map-2.0.3/test/is-native-implemented.js000066400000000000000000000001161347647570400214450ustar00rootroot00000000000000"use strict"; module.exports = function (t, a) { a(typeof t, "boolean"); }; es6-weak-map-2.0.3/test/is-weak-map.js000066400000000000000000000006261347647570400173660ustar00rootroot00000000000000"use strict"; var WeakMapPoly = require("../polyfill"); module.exports = function (t, a) { a(t(undefined), false, "Undefined"); a(t(null), false, "Null"); a(t(true), false, "Primitive"); a(t("raz"), false, "String"); a(t({}), false, "Object"); a(t([]), false, "Array"); if (typeof WeakMap !== "undefined") { a(t(new WeakMap()), true, "Native"); } a(t(new WeakMapPoly()), true, "Polyfill"); }; es6-weak-map-2.0.3/test/polyfill.js000066400000000000000000000013251347647570400171020ustar00rootroot00000000000000"use strict"; module.exports = function (T, a) { var obj1 = {}, obj2 = {}, obj3 = {}, arr = [[obj1, "raz"], [obj2, "dwa"]], map = new T(arr); a(map instanceof T, true, "WeakMap"); a(map.has(obj1), true, "Has: true"); a(map.get(obj1), "raz", "Get: contains"); a(map.has(obj3), false, "Has: false"); a(map.get(obj3), undefined, "Get: doesn't contain"); a(map.set(obj3, "trzy"), map, "Set: return"); a(map.has(obj3), true, "Add"); a(map.delete({}), false, "Delete: false"); a(map.delete(obj1), true, "Delete: true"); a(map.get(obj1), undefined, "Get: after delete"); a(map.has(obj1), false, "Has: after delete"); a.h1("Empty initialization"); map = new T(); map.set(obj1, "bar"); a(map.get(obj1), "bar"); }; es6-weak-map-2.0.3/test/valid-weak-map.js000066400000000000000000000011621347647570400200460ustar00rootroot00000000000000"use strict"; var WeakMapPoly = require("../polyfill"); module.exports = function (t, a) { var map; a.throws(function () { t(undefined); }, TypeError, "Undefined"); a.throws(function () { t(null); }, TypeError, "Null"); a.throws(function () { t(true); }, TypeError, "Primitive"); a.throws(function () { t("raz"); }, TypeError, "String"); a.throws(function () { t({}); }, TypeError, "Object"); a.throws(function () { t([]); }, TypeError, "Array"); if (typeof WeakMap !== "undefined") { map = new WeakMap(); a(t(map), map, "Native"); } map = new WeakMapPoly(); a(t(map), map, "Polyfill"); }; es6-weak-map-2.0.3/valid-weak-map.js000066400000000000000000000002721347647570400170700ustar00rootroot00000000000000"use strict"; var isWeakMap = require("./is-weak-map"); module.exports = function (value) { if (!isWeakMap(value)) throw new TypeError(value + " is not a WeakMap"); return value; };