var $ = require('../internals/export');
var DESCRIPTORS = require('../internals/descriptors');
var global = require('../internals/global');
-var has = require('../internals/has');
-var isObject = require('../internals/is-object');
+var uncurryThis = require('../internals/function-uncurry-this');
+var hasOwn = require('../internals/has-own-property');
+var isCallable = require('../internals/is-callable');
+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 && typeof NativeSymbol == 'function' && (!('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;
+ SymbolWrapper.prototype = SymbolPrototype;
+ SymbolPrototype.constructor = SymbolWrapper;
- var symbolToString = symbolPrototype.toString;
- var native = String(NativeSymbol('test')) == 'Symbol(test)';
+ 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);
- if (has(EmptyStringDescriptionStore, symbol)) return '';
- var desc = native ? string.slice(7, -1) : string.replace(regexp, '$1');
+ var symbol = symbolValueOf(this);
+ var string = symbolToString(symbol);
+ if (hasOwn(EmptyStringDescriptionStore, symbol)) return '';
+ var desc = NATIVE_SYMBOL ? stringSlice(string, 7, -1) : replace(string, regexp, '$1');
return desc === '' ? undefined : desc;
}
});