es7.reflect.delete-metadata.js 704 B

123456789101112131415
  1. var metadata = require('./_metadata');
  2. var anObject = require('./_an-object');
  3. var toMetaKey = metadata.key;
  4. var getOrCreateMetadataMap = metadata.map;
  5. var store = metadata.store;
  6. metadata.exp({ deleteMetadata: function deleteMetadata(metadataKey, target /* , targetKey */) {
  7. var targetKey = arguments.length < 3 ? undefined : toMetaKey(arguments[2]);
  8. var metadataMap = getOrCreateMetadataMap(anObject(target), targetKey, false);
  9. if (metadataMap === undefined || !metadataMap['delete'](metadataKey)) return false;
  10. if (metadataMap.size) return true;
  11. var targetMetadata = store.get(target);
  12. targetMetadata['delete'](targetKey);
  13. return !!targetMetadata.size || store['delete'](target);
  14. } });