Version 1
[yaffs-website] / node_modules / core-js / library / modules / _metadata.js
1 var Map     = require('./es6.map')
2   , $export = require('./_export')
3   , shared  = require('./_shared')('metadata')
4   , store   = shared.store || (shared.store = new (require('./es6.weak-map')));
5
6 var getOrCreateMetadataMap = function(target, targetKey, create){
7   var targetMetadata = store.get(target);
8   if(!targetMetadata){
9     if(!create)return undefined;
10     store.set(target, targetMetadata = new Map);
11   }
12   var keyMetadata = targetMetadata.get(targetKey);
13   if(!keyMetadata){
14     if(!create)return undefined;
15     targetMetadata.set(targetKey, keyMetadata = new Map);
16   } return keyMetadata;
17 };
18 var ordinaryHasOwnMetadata = function(MetadataKey, O, P){
19   var metadataMap = getOrCreateMetadataMap(O, P, false);
20   return metadataMap === undefined ? false : metadataMap.has(MetadataKey);
21 };
22 var ordinaryGetOwnMetadata = function(MetadataKey, O, P){
23   var metadataMap = getOrCreateMetadataMap(O, P, false);
24   return metadataMap === undefined ? undefined : metadataMap.get(MetadataKey);
25 };
26 var ordinaryDefineOwnMetadata = function(MetadataKey, MetadataValue, O, P){
27   getOrCreateMetadataMap(O, P, true).set(MetadataKey, MetadataValue);
28 };
29 var ordinaryOwnMetadataKeys = function(target, targetKey){
30   var metadataMap = getOrCreateMetadataMap(target, targetKey, false)
31     , keys        = [];
32   if(metadataMap)metadataMap.forEach(function(_, key){ keys.push(key); });
33   return keys;
34 };
35 var toMetaKey = function(it){
36   return it === undefined || typeof it == 'symbol' ? it : String(it);
37 };
38 var exp = function(O){
39   $export($export.S, 'Reflect', O);
40 };
41
42 module.exports = {
43   store: store,
44   map: getOrCreateMetadataMap,
45   has: ordinaryHasOwnMetadata,
46   get: ordinaryGetOwnMetadata,
47   set: ordinaryDefineOwnMetadata,
48   keys: ordinaryOwnMetadataKeys,
49   key: toMetaKey,
50   exp: exp
51 };