main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 |
|
---|
5 | var callBound = require('call-bind/callBound');
|
---|
6 |
|
---|
7 | var $SyntaxError = require('es-errors/syntax');
|
---|
8 | var getGlobalSymbolDescription = GetIntrinsic('%Symbol.keyFor%', true);
|
---|
9 | var thisSymbolValue = callBound('%Symbol.prototype.valueOf%', true);
|
---|
10 | var symToStr = callBound('Symbol.prototype.toString', true);
|
---|
11 | var $strSlice = callBound('String.prototype.slice');
|
---|
12 |
|
---|
13 | var getInferredName = require('./getInferredName');
|
---|
14 |
|
---|
15 | /* eslint-disable consistent-return */
|
---|
16 | module.exports = callBound('%Symbol.prototype.description%', true) || function getSymbolDescription(symbol) {
|
---|
17 | if (!thisSymbolValue) {
|
---|
18 | throw new $SyntaxError('Symbols are not supported in this environment');
|
---|
19 | }
|
---|
20 |
|
---|
21 | // will throw if not a symbol primitive or wrapper object
|
---|
22 | var sym = thisSymbolValue(symbol);
|
---|
23 |
|
---|
24 | if (getInferredName) {
|
---|
25 | var name = getInferredName(sym);
|
---|
26 | if (name === '') {
|
---|
27 | return;
|
---|
28 | }
|
---|
29 | return name.slice(1, -1); // name.slice('['.length, -']'.length);
|
---|
30 | }
|
---|
31 |
|
---|
32 | var desc;
|
---|
33 | if (getGlobalSymbolDescription) {
|
---|
34 | desc = getGlobalSymbolDescription(sym);
|
---|
35 | if (typeof desc === 'string') {
|
---|
36 | return desc;
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | desc = $strSlice(symToStr(sym), 7, -1); // str.slice('Symbol('.length, -')'.length);
|
---|
41 | if (desc) {
|
---|
42 | return desc;
|
---|
43 | }
|
---|
44 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.