3 var setPrototypeOf = require('es5-ext/object/set-prototype-of')
4 , object = require('es5-ext/object/valid-object')
5 , value = require('es5-ext/object/valid-value')
7 , getIterator = require('es6-iterator/get')
8 , forOf = require('es6-iterator/for-of')
9 , toStringTagSymbol = require('es6-symbol').toStringTag
10 , isNative = require('./is-native-implemented')
12 , isArray = Array.isArray, defineProperty = Object.defineProperty, random = Math.random
13 , hasOwnProperty = Object.prototype.hasOwnProperty
16 genId = (function () {
17 var generated = Object.create(null);
20 do { id = random().toString(36).slice(2); } while (generated[id]);
26 module.exports = WeakMapPoly = function (/*iterable*/) {
27 var iterable = arguments[0];
28 if (!(this instanceof WeakMapPoly)) return new WeakMapPoly(iterable);
29 if (this.__weakMapData__ !== undefined) {
30 throw new TypeError(this + " cannot be reinitialized");
32 if (iterable != null) {
33 if (!isArray(iterable)) iterable = getIterator(iterable);
35 defineProperty(this, '__weakMapData__', d('c', '$weakMap$' + genId()));
36 if (!iterable) return;
37 forOf(iterable, function (val) {
39 this.set(val[0], val[1]);
44 if (setPrototypeOf) setPrototypeOf(WeakMapPoly, WeakMap);
45 WeakMapPoly.prototype = Object.create(WeakMap.prototype, {
46 constructor: d(WeakMapPoly)
50 Object.defineProperties(WeakMapPoly.prototype, {
51 clear: d(function () {
52 defineProperty(this, '__weakMapData__', d('c', '$weakMap$' + genId()));
54 delete: d(function (key) {
55 if (hasOwnProperty.call(object(key), this.__weakMapData__)) {
56 delete key[this.__weakMapData__];
61 get: d(function (key) {
62 if (hasOwnProperty.call(object(key), this.__weakMapData__)) {
63 return key[this.__weakMapData__];
66 has: d(function (key) {
67 return hasOwnProperty.call(object(key), this.__weakMapData__);
69 set: d(function (key, value) {
70 defineProperty(object(key), this.__weakMapData__, d('c', value));
73 toString: d(function () { return '[object WeakMap]'; })
75 defineProperty(WeakMapPoly.prototype, toStringTagSymbol, d('c', 'WeakMap'));