1 var hiddenKeys = require('../internals/hidden-keys');
2 var isObject = require('../internals/is-object');
3 var has = require('../internals/has');
4 var defineProperty = require('../internals/object-define-property').f;
5 var uid = require('../internals/uid');
6 var FREEZING = require('../internals/freezing');
8 var METADATA = uid('meta');
11 var isExtensible = Object.isExtensible || function () {
15 var setMetadata = function (it) {
16 defineProperty(it, METADATA, { value: {
17 objectID: 'O' + ++id, // object ID
18 weakData: {} // weak collections IDs
22 var fastKey = function (it, create) {
23 // return a primitive with prefix
24 if (!isObject(it)) return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it;
25 if (!has(it, METADATA)) {
26 // can't set metadata to uncaught frozen object
27 if (!isExtensible(it)) return 'F';
28 // not necessary to add metadata
29 if (!create) return 'E';
30 // add missing metadata
33 } return it[METADATA].objectID;
36 var getWeakData = function (it, create) {
37 if (!has(it, METADATA)) {
38 // can't set metadata to uncaught frozen object
39 if (!isExtensible(it)) return true;
40 // not necessary to add metadata
41 if (!create) return false;
42 // add missing metadata
44 // return the store of weak collections IDs
45 } return it[METADATA].weakData;
48 // add metadata on freeze-family methods calling
49 var onFreeze = function (it) {
50 if (FREEZING && meta.REQUIRED && isExtensible(it) && !has(it, METADATA)) setMetadata(it);
54 var meta = module.exports = {
57 getWeakData: getWeakData,
61 hiddenKeys[METADATA] = true;