{"_id":"weak-map","_rev":"4579173","name":"weak-map","description":"A WeakMap shim for Node.js and browsers","dist-tags":{"latest":"1.0.8"},"maintainers":[{"name":"kriskowal","email":""}],"time":{"modified":"2026-04-10T15:53:21.000Z","created":"2013-08-06T20:47:41.478Z","1.0.8":"2022-02-15T02:18:47.392Z","1.0.5":"2014-05-29T02:41:33.030Z","1.0.4":"2014-03-20T19:46:17.861Z","1.0.3":"2014-01-25T07:25:08.468Z","1.0.2":"2014-01-05T20:53:05.925Z","1.0.1":"2013-12-05T02:37:28.164Z","1.0.0":"2013-08-06T20:47:41.478Z"},"users":{"nichoth":true},"author":{"name":"Mark Miller","email":"erights@gmail.com"},"repository":{"type":"git","url":"git://github.com/drses/weak-map.git"},"versions":{"1.0.8":{"name":"weak-map","version":"1.0.8","description":"A WeakMap shim for Node.js and browsers","main":"weak-map.js","repository":{"type":"git","url":"git://github.com/drses/weak-map.git"},"keywords":["weakmap","weak-map","weak","map","collections","es6"],"author":{"name":"Mark Miller","email":"erights@gmail.com"},"maintainer":"Kris Kowal <kris@cixar.com>","license":"Apache-2.0","bugs":{"url":"https://github.com/drses/weak-map/issues"},"scripts":{"test":"npm run test:native; npm run test:shim","test:phantom":"","test:shim":"node test/index.js","test:native":"node --harmony_collections test/index.js"},"devDependencies":{"jasminum":">=2.0.2 <3.0.0"},"gitHead":"35764aa1bbcb8ca31bb2a554ee323acaa19bca27","homepage":"https://github.com/drses/weak-map#readme","_id":"weak-map@1.0.8","_nodeVersion":"14.19.0","_npmVersion":"6.14.16","dist":{"shasum":"394c18a9e8262e790544ed8b55c6a4ddad1cb1a3","size":10956,"noattachment":false,"key":"/weak-map/-/weak-map-1.0.8.tgz","tarball":"http://registry.cnpm.dingdandao.com/weak-map/download/weak-map-1.0.8.tgz"},"_npmUser":{"name":"kriskowal","email":"kris.kowal@cixar.com"},"directories":{},"maintainers":[{"name":"kriskowal","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/weak-map_1.0.8_1644891527218_0.023484311649641487"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-15T02:19:10.744Z","publish_time":1644891527392,"_cnpm_publish_time":1644891527392},"1.0.5":{"name":"weak-map","version":"1.0.5","description":"A WeakMap shim for Node.js and browsers","main":"weak-map.js","repository":{"type":"git","url":"git://github.com/drses/weak-map.git"},"keywords":["weakmap","weak-map","weak","map","collections","es6"],"author":{"name":"Mark Miller","email":"erights@gmail.com"},"maintainer":"Kris Kowal <kris@cixar.com>","license":"Apache 2.0","bugs":{"url":"https://github.com/drses/weak-map/issues"},"files":["weak-map.js"],"scripts":{"test":"npm run test:native; npm run test:shim","test:phantom":"","test:shim":"node test/index.js","test:native":"node --harmony_collections test/index.js"},"devDependencies":{"jasminum":"^2.0.1"},"homepage":"https://github.com/drses/weak-map","_id":"weak-map@1.0.5","dist":{"shasum":"79691584d98607f5070bd3b70a40e6bb22e401eb","size":10920,"noattachment":false,"key":"/weak-map/-/weak-map-1.0.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/weak-map/download/weak-map-1.0.5.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"kriskowal","email":"kris.kowal@cixar.com"},"maintainers":[{"name":"kriskowal","email":""}],"directories":{},"publish_time":1401331293030,"_cnpm_publish_time":1401331293030,"_hasShrinkwrap":false},"1.0.4":{"name":"weak-map","version":"1.0.4","description":"A WeakMap shim for Node.js and browsers","main":"weak-map.js","repository":{"type":"git","url":"git://github.com/drses/weak-map.git"},"keywords":["weakmap","weak-map","weak","map","collections","es6"],"author":{"name":"Mark Miller","email":"erights@gmail.com"},"maintainer":"Kris Kowal <kris@cixar.com>","license":"Apache 2.0","bugs":{"url":"https://github.com/drses/weak-map/issues"},"scripts":{"test":"npm run test:native; npm run test:shim","test:phantom":"","test:shim":"node test/index.js","test:native":"node --harmony_collections test/index.js"},"devDependencies":{"jasminum":"^2.0.1"},"homepage":"https://github.com/drses/weak-map","_id":"weak-map@1.0.4","dist":{"shasum":"1acddee2cc90eb30950860b7415c79cefc5f07c9","size":11927,"noattachment":false,"key":"/weak-map/-/weak-map-1.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/weak-map/download/weak-map-1.0.4.tgz"},"_from":".","_npmVersion":"1.4.4","_npmUser":{"name":"kriskowal","email":"kris.kowal@cixar.com"},"maintainers":[{"name":"kriskowal","email":""}],"directories":{},"publish_time":1395344777861,"_cnpm_publish_time":1395344777861,"_hasShrinkwrap":false},"1.0.3":{"name":"weak-map","version":"1.0.3","description":"A WeakMap shim for Node.js and browsers","main":"weak-map.js","scripts":{"test":"./verify","bench":"matcha bench.js"},"repository":{"type":"git","url":"git://github.com/drses/weak-map.git"},"keywords":["weakmap","weak-map","weak","map","collections","es6"],"author":{"name":"Mark Miller","email":"erights@gmail.com"},"maintainer":"Kris Kowal <kris@cixar.com>","license":"Apache 2.0","bugs":{"url":"https://github.com/drses/weak-map/issues"},"devDependencies":{"matcha":"~0.4.1"},"_id":"weak-map@1.0.3","dist":{"shasum":"42fcaa8e95da551ccb06964a1071693830365b26","size":11251,"noattachment":false,"key":"/weak-map/-/weak-map-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/weak-map/download/weak-map-1.0.3.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"kriskowal","email":"kris.kowal@cixar.com"},"maintainers":[{"name":"kriskowal","email":""}],"directories":{},"publish_time":1390634708468,"_cnpm_publish_time":1390634708468,"_hasShrinkwrap":false},"1.0.2":{"name":"weak-map","version":"1.0.2","description":"A WeakMap shim for Node.js and browsers","main":"weak-map.js","scripts":{"test":"./verify","bench":"matcha bench.js"},"repository":{"type":"git","url":"git://github.com/drses/weak-map.git"},"keywords":["weakmap","weak-map","weak","map","collections","es6"],"author":{"name":"Mark Miller","email":"erights@gmail.com"},"maintainer":"Kris Kowal <kris@cixar.com>","license":"Apache 2.0","bugs":{"url":"https://github.com/drses/weak-map/issues"},"devDependencies":{"matcha":"~0.4.1"},"readmeFilename":"README.md","_id":"weak-map@1.0.2","dist":{"shasum":"17d2a3b5c904fe07f2825f484556722847cb4f66","size":9914,"noattachment":false,"key":"/weak-map/-/weak-map-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/weak-map/download/weak-map-1.0.2.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"kriskowal","email":"kris.kowal@cixar.com"},"maintainers":[{"name":"kriskowal","email":""}],"directories":{},"publish_time":1388955185925,"_cnpm_publish_time":1388955185925,"_hasShrinkwrap":false},"1.0.1":{"name":"weak-map","version":"1.0.1","description":"A WeakMap shim for Node.js and browsers","main":"weak-map.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/drses/weak-map.git"},"keywords":["weakmap","weak-map","weak","map","collections","es6"],"author":{"name":"Mark Miller","email":"erights@gmail.com"},"maintainer":"Kris Kowal <kris@cixar.com>","license":"Apache 2.0","bugs":{"url":"https://github.com/drses/weak-map/issues"},"readmeFilename":"README.md","_id":"weak-map@1.0.1","dist":{"shasum":"337346651f74ff5c7c2e456b2b671b533bba67cf","size":9327,"noattachment":false,"key":"/weak-map/-/weak-map-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/weak-map/download/weak-map-1.0.1.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"kriskowal","email":"kris.kowal@cixar.com"},"maintainers":[{"name":"kriskowal","email":""}],"directories":{},"publish_time":1386211048164,"_cnpm_publish_time":1386211048164,"_hasShrinkwrap":false},"1.0.0":{"name":"weak-map","version":"1.0.0","main":"weak-map.js","_id":"weak-map@1.0.0","dist":{"shasum":"b66e56a9df0bd25a76bbf1b514db129080614a37","size":7722,"noattachment":false,"key":"/weak-map/-/weak-map-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/weak-map/download/weak-map-1.0.0.tgz"},"_from":".","_npmVersion":"1.3.2","_npmUser":{"name":"kriskowal","email":"kris.kowal@cixar.com"},"maintainers":[{"name":"kriskowal","email":""}],"directories":{},"publish_time":1375822061478,"_cnpm_publish_time":1375822061478,"_hasShrinkwrap":false}},"readme":"\n`WeakMap` is a collection slated to be introduced to JavaScript with\nEcmaScript 6.  It provides a mapping from objects to values, but allows\nany entry to be garbage collected if the key is provably lost.\n\nIn order for it to be possible that a key is provably lost, weak maps do\nnot provide a way to access the key list.\n\nThis is a Node Packaged Module (NPM) that provides a shim and patcher\nfor missing or broken WeakMap implementations suitable for use in\nNode.js and browsers that provide the EcmaScript 5 property description\ninterfaces provided that it hosted by a CommonJS loader or bundler like\n[Browserify][], [Montage][], [Mr][], or [Mop][].\n\n[Browserify]: https://github.com/substack/node-browserify\n[Montage]: https://github.com/montagejs/mr\n[Mr]: https://github.com/montagejs/mr\n[Mop]: https://github.com/montagejs/mop\n\n```\nnpm install weak-map --save\n```\n\n```javascript\nvar WeakMap = require(\"weak-map\");\nvar map = new WeakMap();\nvar key = {};\nmap.set(key, \"Hello, World!\");\nmap.get(key) === \"Hello, World!\";\nkey = null;\n// \"Hello, World!\" may be collected\n```\n\nSee [MDN][] for the API details.\n\n[MDN]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap\n\nAt time of writing, prototype implementations of `WeakMap` exist in V8\nand Spidermonkey.  The prototype is available in Node.js v0.10 with the\n`--harmony_collections` V8 option.  In v0.8, it was available with\n`--harmony_weakmaps`.  The purpose of this package is to enable\ndependees to use weak maps regardless of whether they are implemented by\nthe underlying engine, albeit in a way that leaks memory in some\nnon-obvious cases.\n\n### Purpose and limitation\n\nThis shim depends on and modifies ECMAScript 5 property descriptor related\nmethods, `Object.defineProperty`, `Object.getOwnPropertyNames`,\n`Object.isExtensible`, `Object.freeze`, and `Object.seal`.\n\nIn a nutshell, the WeakMap shim emulates a WeakMap by adding a hidden\nproperty to the key that associates the weak map with the retained\nobject. The shim overrides the ECMAScript 5 methods to cover its tracks.\n\nConsider a scenario that only includes a weak map, a key, and a corresponding\nvalue through the weak map. With a proper `WeakMap`, built into the JavaScript\nengine privy to the internals of the garbage collector, the `value` would be\nretained either by the key or the weak map. If *either* the key or the weak map\nare elligible for garbage collection, the value is elligible.\n\nThis is in contrast to to a plain `Map`. In a scenario with a map, a key, and a\nvalue corresponding to the key through the map, neither the key nor the value\nwill be eligible for garbage collection until the map containing them is\nelligible. Thus, if a map is used to establish a relationship between ephemeral\nkeys and values, it will accumulate garbage.\n\nThis shim does its best to approximate a proper `WeakMap` without an intimate\nrelationship with the garbage collector. In the same scenario, the value will\nbecome elligible for garbage collection if the key is elligible. Unlike a proper\nweak map, if the weak map shim becomes elligible for garbage collection but the\nkey is retained by something else, the value will be retained. In this scenario,\nall operations of the weak map take constant time.\n\nHowever, if the key is *frozen*, the weak map retains both the key and the value\nand neither are elligible for collection until the weak map becomes elligible\nitself. This scenario is unfortunately identical to the behavior of a `Map`.\nAdditionally, all operations of the weak map suffer linear time.\n\nAs stated by Mark Miller in the code:\n\n> As with true WeakMaps, in this emulation, a key does not retain maps indexed by\n> that key and (crucially) a map does not retain the keys it indexes. A map by\n> itself also does not retain the values associated with that map.\n>\n> However, the values associated with a key in some map are retained so long as\n> that key is retained and those associations are not overridden. For example,\n> when used to support membranes, all values exported from a given membrane will\n> live for the lifetime they would have had in the absence of an interposed\n> membrane. Even when the membrane is revoked, all objects that would have been\n> reachable in the absence of revocation will still be reachable, as far as the\n> GC can tell, even though they will no longer be relevant to ongoing\n> computation.\n>\n> The API implemented here is approximately the API as implemented\n> in FF6.0a1 and agreed to by MarkM, Andreas Gal, and Dave Herman,\n> rather than the offially approved proposal page.\n>\n> The first difference between the emulation here and that in FF6.0a1 is the\n> presence of non enumerable `get___`, `has___`, `set___`, and `delete___`}\n> methods on WeakMap instances to represent what would be the hidden internal\n> properties of a primitive implementation. Whereas the FF6.0a1 WeakMap.prototype\n> methods require their `this` to be a genuine WeakMap instance (i.e., an object\n> of `[[Class]]` \"WeakMap}), since there is nothing unforgeable about the\n> pseudo-internal method names used here, nothing prevents these emulated\n> prototype methods from being applied to non-WeakMaps with pseudo-internal\n> methods of the same names.\n>\n> Another difference is that our emulated `WeakMap.prototype` is not itself a\n> WeakMap. A problem with the current FF6.0a1 API is that WeakMap.prototype is\n> itself a WeakMap providing ambient mutability and an ambient communications\n> channel. Thus, if a WeakMap is already present and has this problem,\n> repairES5.js wraps it in a safe wrappper in order to prevent access to this\n> channel. (See PATCH_MUTABLE_FROZEN_WEAKMAP_PROTO in repairES5.js).\n\nThis refers to `repairES5.js` as provided by Google Caja.\n\n### Origin and license\n\nThe canonical implementation of `WeakMap` exists in the Google Caja\nSubversion repository at http://google-caja.googlecode.com/svn/trunk.\nIt was written by Mark S. Miller.  It is released by Google with the\nApache 2.0 license.  This package is maintained by Kris Kowal.\n\nThis work began with [Mark Miller’s proposal][Proposal] for `WeakMap` to ECMA’s\nTC-39, where the JavaScript standard is developed.\n\n[Proposal]: http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps\n\n","_attachments":{},"homepage":"https://github.com/drses/weak-map#readme","bugs":{"url":"https://github.com/drses/weak-map/issues"},"license":"Apache-2.0"}