UNPKG

symbol.prototype.description

Version:

Spec-compliant shim for Symbol.prototype.description proposal.

26 lines (20 loc) 678 B
'use strict'; var hasSymbols = require('has-symbols')(); var implementation = require('./implementation'); var gOPD = require('gopd'); /** @type {import('./polyfill')} */ module.exports = function descriptionPolyfill() { if (!hasSymbols || typeof gOPD !== 'function') { return implementation; } var desc = gOPD(Symbol.prototype, 'description'); if (!desc || typeof desc.get !== 'function') { return implementation; } var emptySymbolDesc = desc.get.call(Symbol()); var emptyDescValid = typeof emptySymbolDesc === 'undefined' || emptySymbolDesc === ''; if (!emptyDescValid || desc.get.call(Symbol('a')) !== 'a') { return implementation; } return desc.get; };