Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

internal-metadata.js 2.8KB

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