source: frontend/node_modules/core-js/modules/es.symbol.description.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.0 KB
Line 
1// `Symbol.prototype.description` getter
2// https://tc39.es/ecma262/#sec-symbol.prototype.description
3'use strict';
4var $ = require('../internals/export');
5var DESCRIPTORS = require('../internals/descriptors');
6var globalThis = require('../internals/global-this');
7var call = require('../internals/function-call');
8var uncurryThis = require('../internals/function-uncurry-this');
9var hasOwn = require('../internals/has-own-property');
10var isCallable = require('../internals/is-callable');
11var isPrototypeOf = require('../internals/object-is-prototype-of');
12var toString = require('../internals/to-string');
13var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
14var copyConstructorProperties = require('../internals/copy-constructor-properties');
15
16var NativeSymbol = globalThis.Symbol;
17var SymbolPrototype = NativeSymbol && NativeSymbol.prototype;
18
19if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in SymbolPrototype) ||
20 // Safari 12 bug
21 NativeSymbol().description !== undefined
22)) {
23 var EmptyStringDescriptionStore = {};
24 // wrap Symbol constructor for correct work with undefined description
25 var SymbolWrapper = function Symbol() {
26 var description = arguments.length < 1 || arguments[0] === undefined ? undefined : toString(arguments[0]);
27 var result = isPrototypeOf(SymbolPrototype, this)
28 // eslint-disable-next-line sonarjs/inconsistent-function-call -- ok
29 ? new NativeSymbol(description)
30 // in Edge 13, String(Symbol(undefined)) === 'Symbol(undefined)'
31 : description === undefined ? NativeSymbol() : NativeSymbol(description);
32 if (description === '') EmptyStringDescriptionStore[result] = true;
33 return result;
34 };
35
36 copyConstructorProperties(SymbolWrapper, NativeSymbol);
37 // wrap Symbol.for for correct handling of empty string descriptions
38 var nativeFor = SymbolWrapper['for'];
39 SymbolWrapper['for'] = { 'for': function (key) {
40 var stringKey = toString(key);
41 var symbol = call(nativeFor, this, stringKey);
42 if (stringKey === '') EmptyStringDescriptionStore[symbol] = true;
43 return symbol;
44 } }['for'];
45 SymbolWrapper.prototype = SymbolPrototype;
46 SymbolPrototype.constructor = SymbolWrapper;
47
48 var NATIVE_SYMBOL = String(NativeSymbol('description detection')) === 'Symbol(description detection)';
49 var thisSymbolValue = uncurryThis(SymbolPrototype.valueOf);
50 var symbolDescriptiveString = uncurryThis(SymbolPrototype.toString);
51 var regexp = /^Symbol\((.*)\)[^)]+$/;
52 var replace = uncurryThis(''.replace);
53 var stringSlice = uncurryThis(''.slice);
54
55 defineBuiltInAccessor(SymbolPrototype, 'description', {
56 configurable: true,
57 get: function description() {
58 var symbol = thisSymbolValue(this);
59 if (hasOwn(EmptyStringDescriptionStore, symbol)) return '';
60 var string = symbolDescriptiveString(symbol);
61 var desc = NATIVE_SYMBOL ? stringSlice(string, 7, -1) : replace(string, regexp, '$1');
62 return desc === '' ? undefined : desc;
63 }
64 });
65
66 $({ global: true, constructor: true, forced: true }, {
67 Symbol: SymbolWrapper
68 });
69}
Note: See TracBrowser for help on using the repository browser.