1 |
|
2 |
|
3 | 'use strict';
|
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');
|
11 |
|
12 | var NativeSymbol = global.Symbol;
|
13 |
|
14 | if (DESCRIPTORS && typeof NativeSymbol == 'function' && (!('description' in NativeSymbol.prototype) ||
|
15 |
|
16 | NativeSymbol().description !== undefined
|
17 | )) {
|
18 | var EmptyStringDescriptionStore = {};
|
19 |
|
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 |
|
25 | : description === undefined ? NativeSymbol() : NativeSymbol(description);
|
26 | if (description === '') EmptyStringDescriptionStore[result] = true;
|
27 | return result;
|
28 | };
|
29 | copyConstructorProperties(SymbolWrapper, NativeSymbol);
|
30 | var symbolPrototype = SymbolWrapper.prototype = NativeSymbol.prototype;
|
31 | symbolPrototype.constructor = SymbolWrapper;
|
32 |
|
33 | var symbolToString = symbolPrototype.toString;
|
34 | var native = String(NativeSymbol('test')) == 'Symbol(test)';
|
35 | var regexp = /^Symbol\((.*)\)[^)]+$/;
|
36 | defineProperty(symbolPrototype, 'description', {
|
37 | configurable: true,
|
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;
|
44 | }
|
45 | });
|
46 |
|
47 | $({ global: true, forced: true }, {
|
48 | Symbol: SymbolWrapper
|
49 | });
|
50 | }
|