[79a0317] | 1 | 'use strict';
|
---|
| 2 | // TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env`
|
---|
| 3 | require('../modules/es.map');
|
---|
| 4 | require('../modules/es.weak-map');
|
---|
| 5 | var getBuiltIn = require('../internals/get-built-in');
|
---|
| 6 | var uncurryThis = require('../internals/function-uncurry-this');
|
---|
| 7 | var shared = require('../internals/shared');
|
---|
| 8 |
|
---|
| 9 | var Map = getBuiltIn('Map');
|
---|
| 10 | var WeakMap = getBuiltIn('WeakMap');
|
---|
| 11 | var push = uncurryThis([].push);
|
---|
| 12 |
|
---|
| 13 | var metadata = shared('metadata');
|
---|
| 14 | var store = metadata.store || (metadata.store = new WeakMap());
|
---|
| 15 |
|
---|
| 16 | var getOrCreateMetadataMap = function (target, targetKey, create) {
|
---|
| 17 | var targetMetadata = store.get(target);
|
---|
| 18 | if (!targetMetadata) {
|
---|
| 19 | if (!create) return;
|
---|
| 20 | store.set(target, targetMetadata = new Map());
|
---|
| 21 | }
|
---|
| 22 | var keyMetadata = targetMetadata.get(targetKey);
|
---|
| 23 | if (!keyMetadata) {
|
---|
| 24 | if (!create) return;
|
---|
| 25 | targetMetadata.set(targetKey, keyMetadata = new Map());
|
---|
| 26 | } return keyMetadata;
|
---|
| 27 | };
|
---|
| 28 |
|
---|
| 29 | var ordinaryHasOwnMetadata = function (MetadataKey, O, P) {
|
---|
| 30 | var metadataMap = getOrCreateMetadataMap(O, P, false);
|
---|
| 31 | return metadataMap === undefined ? false : metadataMap.has(MetadataKey);
|
---|
| 32 | };
|
---|
| 33 |
|
---|
| 34 | var ordinaryGetOwnMetadata = function (MetadataKey, O, P) {
|
---|
| 35 | var metadataMap = getOrCreateMetadataMap(O, P, false);
|
---|
| 36 | return metadataMap === undefined ? undefined : metadataMap.get(MetadataKey);
|
---|
| 37 | };
|
---|
| 38 |
|
---|
| 39 | var ordinaryDefineOwnMetadata = function (MetadataKey, MetadataValue, O, P) {
|
---|
| 40 | getOrCreateMetadataMap(O, P, true).set(MetadataKey, MetadataValue);
|
---|
| 41 | };
|
---|
| 42 |
|
---|
| 43 | var ordinaryOwnMetadataKeys = function (target, targetKey) {
|
---|
| 44 | var metadataMap = getOrCreateMetadataMap(target, targetKey, false);
|
---|
| 45 | var keys = [];
|
---|
| 46 | if (metadataMap) metadataMap.forEach(function (_, key) { push(keys, key); });
|
---|
| 47 | return keys;
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 | var toMetadataKey = function (it) {
|
---|
| 51 | return it === undefined || typeof it == 'symbol' ? it : String(it);
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 | module.exports = {
|
---|
| 55 | store: store,
|
---|
| 56 | getMap: getOrCreateMetadataMap,
|
---|
| 57 | has: ordinaryHasOwnMetadata,
|
---|
| 58 | get: ordinaryGetOwnMetadata,
|
---|
| 59 | set: ordinaryDefineOwnMetadata,
|
---|
| 60 | keys: ordinaryOwnMetadataKeys,
|
---|
| 61 | toKey: toMetadataKey
|
---|
| 62 | };
|
---|