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 has = require('../internals/has');
8 var isObject = require('../internals/is-object');
9 var defineProperty = require('../internals/object-define-property').f;
10 var copyConstructorProperties = require('../internals/copy-constructor-properties');
12 var NativeSymbol = global.Symbol;
14 if (DESCRIPTORS && typeof NativeSymbol == 'function' && (!('description' in NativeSymbol.prototype) ||
16 NativeSymbol().description !== undefined
18 var EmptyStringDescriptionStore = {};
19 // wrap Symbol constructor for correct work with undefined description
20 var SymbolWrapper = function Symbol() {
21 var description = arguments.length < 1 || arguments[0] === undefined ? undefined : String(arguments[0]);
22 var result = this instanceof SymbolWrapper
23 ? new NativeSymbol(description)
24 // in Edge 13, String(Symbol(undefined)) === 'Symbol(undefined)'
25 : description === undefined ? NativeSymbol() : NativeSymbol(description);
26 if (description === '') EmptyStringDescriptionStore[result] = true;
29 copyConstructorProperties(SymbolWrapper, NativeSymbol);
30 var symbolPrototype = SymbolWrapper.prototype = NativeSymbol.prototype;
31 symbolPrototype.constructor = SymbolWrapper;
33 var symbolToString = symbolPrototype.toString;
34 var native = String(NativeSymbol('test')) == 'Symbol(test)';
35 var regexp = /^Symbol\((.*)\)[^)]+$/;
36 defineProperty(symbolPrototype, 'description', {
38 get: function description() {
39 var symbol = isObject(this) ? this.valueOf() : this;
40 var string = symbolToString.call(symbol);
41 if (has(EmptyStringDescriptionStore, symbol)) return '';
42 var desc = native ? string.slice(7, -1) : string.replace(regexp, '$1');
43 return desc === '' ? undefined : desc;
47 $({ global: true, forced: true }, {