1 // `Symbol.prototype.description` getter
2 // https://tc39.es/ecma262/#sec-symbol.prototype.description
4 var $ = require('../internals/export');
5 var DESCRIPTORS = require('../internals/descriptors');
6 var global = require('../internals/global');
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 defineProperty = require('../internals/object-define-property').f;
13 var copyConstructorProperties = require('../internals/copy-constructor-properties');
15 var NativeSymbol = global.Symbol;
16 var SymbolPrototype = NativeSymbol && NativeSymbol.prototype;
18 if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in SymbolPrototype) ||
20 NativeSymbol().description !== undefined
22 var EmptyStringDescriptionStore = {};
23 // wrap Symbol constructor for correct work with undefined description
24 var SymbolWrapper = function Symbol() {
25 var description = arguments.length < 1 || arguments[0] === undefined ? undefined : toString(arguments[0]);
26 var result = isPrototypeOf(SymbolPrototype, this)
27 ? new NativeSymbol(description)
28 // in Edge 13, String(Symbol(undefined)) === 'Symbol(undefined)'
29 : description === undefined ? NativeSymbol() : NativeSymbol(description);
30 if (description === '') EmptyStringDescriptionStore[result] = true;
34 copyConstructorProperties(SymbolWrapper, NativeSymbol);
35 SymbolWrapper.prototype = SymbolPrototype;
36 SymbolPrototype.constructor = SymbolWrapper;
38 var NATIVE_SYMBOL = String(NativeSymbol('test')) == 'Symbol(test)';
39 var symbolToString = uncurryThis(SymbolPrototype.toString);
40 var symbolValueOf = uncurryThis(SymbolPrototype.valueOf);
41 var regexp = /^Symbol\((.*)\)[^)]+$/;
42 var replace = uncurryThis(''.replace);
43 var stringSlice = uncurryThis(''.slice);
45 defineProperty(SymbolPrototype, 'description', {
47 get: function description() {
48 var symbol = symbolValueOf(this);
49 var string = symbolToString(symbol);
50 if (hasOwn(EmptyStringDescriptionStore, symbol)) return '';
51 var desc = NATIVE_SYMBOL ? stringSlice(string, 7, -1) : replace(string, regexp, '$1');
52 return desc === '' ? undefined : desc;
56 $({ global: true, forced: true }, {