1 | 'use strict';
|
2 | var $ = require('../internals/export');
|
3 | var uncurryThis = require('../internals/function-uncurry-this');
|
4 | var hiddenKeys = require('../internals/hidden-keys');
|
5 | var isObject = require('../internals/is-object');
|
6 | var hasOwn = require('../internals/has-own-property');
|
7 | var defineProperty = require('../internals/object-define-property').f;
|
8 | var getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');
|
9 | var getOwnPropertyNamesExternalModule = require('../internals/object-get-own-property-names-external');
|
10 | var isExtensible = require('../internals/object-is-extensible');
|
11 | var uid = require('../internals/uid');
|
12 | var FREEZING = require('../internals/freezing');
|
13 |
|
14 | var REQUIRED = false;
|
15 | var METADATA = uid('meta');
|
16 | var id = 0;
|
17 |
|
18 | var setMetadata = function (it) {
|
19 | defineProperty(it, METADATA, { value: {
|
20 | objectID: 'O' + id++,
|
21 | weakData: {}
|
22 | } });
|
23 | };
|
24 |
|
25 | var fastKey = function (it, create) {
|
26 |
|
27 | if (!isObject(it)) return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it;
|
28 | if (!hasOwn(it, METADATA)) {
|
29 |
|
30 | if (!isExtensible(it)) return 'F';
|
31 |
|
32 | if (!create) return 'E';
|
33 |
|
34 | setMetadata(it);
|
35 |
|
36 | } return it[METADATA].objectID;
|
37 | };
|
38 |
|
39 | var getWeakData = function (it, create) {
|
40 | if (!hasOwn(it, METADATA)) {
|
41 |
|
42 | if (!isExtensible(it)) return true;
|
43 |
|
44 | if (!create) return false;
|
45 |
|
46 | setMetadata(it);
|
47 |
|
48 | } return it[METADATA].weakData;
|
49 | };
|
50 |
|
51 |
|
52 | var onFreeze = function (it) {
|
53 | if (FREEZING && REQUIRED && isExtensible(it) && !hasOwn(it, METADATA)) setMetadata(it);
|
54 | return it;
|
55 | };
|
56 |
|
57 | var enable = function () {
|
58 | meta.enable = function () { };
|
59 | REQUIRED = true;
|
60 | var getOwnPropertyNames = getOwnPropertyNamesModule.f;
|
61 | var splice = uncurryThis([].splice);
|
62 | var test = {};
|
63 | test[METADATA] = 1;
|
64 |
|
65 |
|
66 | if (getOwnPropertyNames(test).length) {
|
67 | getOwnPropertyNamesModule.f = function (it) {
|
68 | var result = getOwnPropertyNames(it);
|
69 | for (var i = 0, length = result.length; i < length; i++) {
|
70 | if (result[i] === METADATA) {
|
71 | splice(result, i, 1);
|
72 | break;
|
73 | }
|
74 | } return result;
|
75 | };
|
76 |
|
77 | $({ target: 'Object', stat: true, forced: true }, {
|
78 | getOwnPropertyNames: getOwnPropertyNamesExternalModule.f
|
79 | });
|
80 | }
|
81 | };
|
82 |
|
83 | var meta = module.exports = {
|
84 | enable: enable,
|
85 | fastKey: fastKey,
|
86 | getWeakData: getWeakData,
|
87 | onFreeze: onFreeze
|
88 | };
|
89 |
|
90 | hiddenKeys[METADATA] = true;
|