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.

es.symbol.description.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // `Symbol.prototype.description` getter
  2. // https://tc39.es/ecma262/#sec-symbol.prototype.description
  3. 'use strict';
  4. var $ = require('../internals/export');
  5. var DESCRIPTORS = require('../internals/descriptors');
  6. var globalThis = require('../internals/global-this');
  7. var uncurryThis = require('../internals/function-uncurry-this');
  8. var hasOwn = require('../internals/has-own-property');
  9. var isCallable = require('../internals/is-callable');
  10. var isPrototypeOf = require('../internals/object-is-prototype-of');
  11. var toString = require('../internals/to-string');
  12. var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
  13. var copyConstructorProperties = require('../internals/copy-constructor-properties');
  14. var NativeSymbol = globalThis.Symbol;
  15. var SymbolPrototype = NativeSymbol && NativeSymbol.prototype;
  16. if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in SymbolPrototype) ||
  17. // Safari 12 bug
  18. NativeSymbol().description !== undefined
  19. )) {
  20. var EmptyStringDescriptionStore = {};
  21. // wrap Symbol constructor for correct work with undefined description
  22. var SymbolWrapper = function Symbol() {
  23. var description = arguments.length < 1 || arguments[0] === undefined ? undefined : toString(arguments[0]);
  24. var result = isPrototypeOf(SymbolPrototype, this)
  25. // eslint-disable-next-line sonar/inconsistent-function-call -- ok
  26. ? new NativeSymbol(description)
  27. // in Edge 13, String(Symbol(undefined)) === 'Symbol(undefined)'
  28. : description === undefined ? NativeSymbol() : NativeSymbol(description);
  29. if (description === '') EmptyStringDescriptionStore[result] = true;
  30. return result;
  31. };
  32. copyConstructorProperties(SymbolWrapper, NativeSymbol);
  33. SymbolWrapper.prototype = SymbolPrototype;
  34. SymbolPrototype.constructor = SymbolWrapper;
  35. var NATIVE_SYMBOL = String(NativeSymbol('description detection')) === 'Symbol(description detection)';
  36. var thisSymbolValue = uncurryThis(SymbolPrototype.valueOf);
  37. var symbolDescriptiveString = uncurryThis(SymbolPrototype.toString);
  38. var regexp = /^Symbol\((.*)\)[^)]+$/;
  39. var replace = uncurryThis(''.replace);
  40. var stringSlice = uncurryThis(''.slice);
  41. defineBuiltInAccessor(SymbolPrototype, 'description', {
  42. configurable: true,
  43. get: function description() {
  44. var symbol = thisSymbolValue(this);
  45. if (hasOwn(EmptyStringDescriptionStore, symbol)) return '';
  46. var string = symbolDescriptiveString(symbol);
  47. var desc = NATIVE_SYMBOL ? stringSlice(string, 7, -1) : replace(string, regexp, '$1');
  48. return desc === '' ? undefined : desc;
  49. }
  50. });
  51. $({ global: true, constructor: true, forced: true }, {
  52. Symbol: SymbolWrapper
  53. });
  54. }