| | |
| | | var $ = require('../internals/export'); |
| | | var DESCRIPTORS = require('../internals/descriptors'); |
| | | var global = require('../internals/global'); |
| | | var uncurryThis = require('../internals/function-uncurry-this'); |
| | | var hasOwn = require('../internals/has-own-property'); |
| | | var isCallable = require('../internals/is-callable'); |
| | | var isObject = require('../internals/is-object'); |
| | | var isPrototypeOf = require('../internals/object-is-prototype-of'); |
| | | var toString = require('../internals/to-string'); |
| | | var defineProperty = require('../internals/object-define-property').f; |
| | | var copyConstructorProperties = require('../internals/copy-constructor-properties'); |
| | | |
| | | var NativeSymbol = global.Symbol; |
| | | var SymbolPrototype = NativeSymbol && NativeSymbol.prototype; |
| | | |
| | | if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in NativeSymbol.prototype) || |
| | | if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in SymbolPrototype) || |
| | | // Safari 12 bug |
| | | NativeSymbol().description !== undefined |
| | | )) { |
| | | var EmptyStringDescriptionStore = {}; |
| | | // wrap Symbol constructor for correct work with undefined description |
| | | var SymbolWrapper = function Symbol() { |
| | | var description = arguments.length < 1 || arguments[0] === undefined ? undefined : String(arguments[0]); |
| | | var result = this instanceof SymbolWrapper |
| | | var description = arguments.length < 1 || arguments[0] === undefined ? undefined : toString(arguments[0]); |
| | | var result = isPrototypeOf(SymbolPrototype, this) |
| | | ? new NativeSymbol(description) |
| | | // in Edge 13, String(Symbol(undefined)) === 'Symbol(undefined)' |
| | | : description === undefined ? NativeSymbol() : NativeSymbol(description); |
| | | if (description === '') EmptyStringDescriptionStore[result] = true; |
| | | return result; |
| | | }; |
| | | copyConstructorProperties(SymbolWrapper, NativeSymbol); |
| | | var symbolPrototype = SymbolWrapper.prototype = NativeSymbol.prototype; |
| | | symbolPrototype.constructor = SymbolWrapper; |
| | | |
| | | var symbolToString = symbolPrototype.toString; |
| | | var nativeSymbol = String(NativeSymbol('test')) == 'Symbol(test)'; |
| | | copyConstructorProperties(SymbolWrapper, NativeSymbol); |
| | | SymbolWrapper.prototype = SymbolPrototype; |
| | | SymbolPrototype.constructor = SymbolWrapper; |
| | | |
| | | var NATIVE_SYMBOL = String(NativeSymbol('test')) == 'Symbol(test)'; |
| | | var symbolToString = uncurryThis(SymbolPrototype.toString); |
| | | var symbolValueOf = uncurryThis(SymbolPrototype.valueOf); |
| | | var regexp = /^Symbol\((.*)\)[^)]+$/; |
| | | defineProperty(symbolPrototype, 'description', { |
| | | var replace = uncurryThis(''.replace); |
| | | var stringSlice = uncurryThis(''.slice); |
| | | |
| | | defineProperty(SymbolPrototype, 'description', { |
| | | configurable: true, |
| | | get: function description() { |
| | | var symbol = isObject(this) ? this.valueOf() : this; |
| | | var string = symbolToString.call(symbol); |
| | | var symbol = symbolValueOf(this); |
| | | var string = symbolToString(symbol); |
| | | if (hasOwn(EmptyStringDescriptionStore, symbol)) return ''; |
| | | var desc = nativeSymbol ? string.slice(7, -1) : string.replace(regexp, '$1'); |
| | | var desc = NATIVE_SYMBOL ? stringSlice(string, 7, -1) : replace(string, regexp, '$1'); |
| | | return desc === '' ? undefined : desc; |
| | | } |
| | | }); |
| | | |
| | | $({ global: true, forced: true }, { |
| | | $({ global: true, constructor: true, forced: true }, { |
| | | Symbol: SymbolWrapper |
| | | }); |
| | | } |