1 // TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env`
2 require('../modules/es.map');
3 require('../modules/es.weak-map');
4 var getBuiltIn = require('../internals/get-built-in');
5 var uncurryThis = require('../internals/function-uncurry-this');
6 var shared = require('../internals/shared');
8 var Map = getBuiltIn('Map');
9 var WeakMap = getBuiltIn('WeakMap');
10 var push = uncurryThis([].push);
12 var metadata = shared('metadata');
13 var store = metadata.store || (metadata.store = new WeakMap());
15 var getOrCreateMetadataMap = function (target, targetKey, create) {
16 var targetMetadata = store.get(target);
17 if (!targetMetadata) {
19 store.set(target, targetMetadata = new Map());
21 var keyMetadata = targetMetadata.get(targetKey);
24 targetMetadata.set(targetKey, keyMetadata = new Map());
28 var ordinaryHasOwnMetadata = function (MetadataKey, O, P) {
29 var metadataMap = getOrCreateMetadataMap(O, P, false);
30 return metadataMap === undefined ? false : metadataMap.has(MetadataKey);
33 var ordinaryGetOwnMetadata = function (MetadataKey, O, P) {
34 var metadataMap = getOrCreateMetadataMap(O, P, false);
35 return metadataMap === undefined ? undefined : metadataMap.get(MetadataKey);
38 var ordinaryDefineOwnMetadata = function (MetadataKey, MetadataValue, O, P) {
39 getOrCreateMetadataMap(O, P, true).set(MetadataKey, MetadataValue);
42 var ordinaryOwnMetadataKeys = function (target, targetKey) {
43 var metadataMap = getOrCreateMetadataMap(target, targetKey, false);
45 if (metadataMap) metadataMap.forEach(function (_, key) { push(keys, key); });
49 var toMetadataKey = function (it) {
50 return it === undefined || typeof it == 'symbol' ? it : String(it);
55 getMap: getOrCreateMetadataMap,
56 has: ordinaryHasOwnMetadata,
57 get: ordinaryGetOwnMetadata,
58 set: ordinaryDefineOwnMetadata,
59 keys: ordinaryOwnMetadataKeys,