source: trip-planner-front/node_modules/core-js/internals/internal-metadata.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.7 KB
Line 
1var $ = require('../internals/export');
2var hiddenKeys = require('../internals/hidden-keys');
3var isObject = require('../internals/is-object');
4var has = require('../internals/has');
5var defineProperty = require('../internals/object-define-property').f;
6var getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');
7var getOwnPropertyNamesExternalModule = require('../internals/object-get-own-property-names-external');
8var uid = require('../internals/uid');
9var FREEZING = require('../internals/freezing');
10
11var REQUIRED = false;
12var METADATA = uid('meta');
13var id = 0;
14
15// eslint-disable-next-line es/no-object-isextensible -- safe
16var isExtensible = Object.isExtensible || function () {
17 return true;
18};
19
20var setMetadata = function (it) {
21 defineProperty(it, METADATA, { value: {
22 objectID: 'O' + id++, // object ID
23 weakData: {} // weak collections IDs
24 } });
25};
26
27var fastKey = function (it, create) {
28 // return a primitive with prefix
29 if (!isObject(it)) return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it;
30 if (!has(it, METADATA)) {
31 // can't set metadata to uncaught frozen object
32 if (!isExtensible(it)) return 'F';
33 // not necessary to add metadata
34 if (!create) return 'E';
35 // add missing metadata
36 setMetadata(it);
37 // return object ID
38 } return it[METADATA].objectID;
39};
40
41var getWeakData = function (it, create) {
42 if (!has(it, METADATA)) {
43 // can't set metadata to uncaught frozen object
44 if (!isExtensible(it)) return true;
45 // not necessary to add metadata
46 if (!create) return false;
47 // add missing metadata
48 setMetadata(it);
49 // return the store of weak collections IDs
50 } return it[METADATA].weakData;
51};
52
53// add metadata on freeze-family methods calling
54var onFreeze = function (it) {
55 if (FREEZING && REQUIRED && isExtensible(it) && !has(it, METADATA)) setMetadata(it);
56 return it;
57};
58
59var enable = function () {
60 meta.enable = function () { /* empty */ };
61 REQUIRED = true;
62 var getOwnPropertyNames = getOwnPropertyNamesModule.f;
63 var splice = [].splice;
64 var test = {};
65 test[METADATA] = 1;
66
67 // prevent exposing of metadata key
68 if (getOwnPropertyNames(test).length) {
69 getOwnPropertyNamesModule.f = function (it) {
70 var result = getOwnPropertyNames(it);
71 for (var i = 0, length = result.length; i < length; i++) {
72 if (result[i] === METADATA) {
73 splice.call(result, i, 1);
74 break;
75 }
76 } return result;
77 };
78
79 $({ target: 'Object', stat: true, forced: true }, {
80 getOwnPropertyNames: getOwnPropertyNamesExternalModule.f
81 });
82 }
83};
84
85var meta = module.exports = {
86 enable: enable,
87 fastKey: fastKey,
88 getWeakData: getWeakData,
89 onFreeze: onFreeze
90};
91
92hiddenKeys[METADATA] = true;
Note: See TracBrowser for help on using the repository browser.