thisSymbolValue.js 533 B

123456789101112131415161718
  1. 'use strict';
  2. var $SyntaxError = require('es-errors/syntax');
  3. var callBound = require('call-bind/callBound');
  4. var $SymbolValueOf = callBound('Symbol.prototype.valueOf', true);
  5. // https://262.ecma-international.org/9.0/#sec-thissymbolvalue
  6. module.exports = function thisSymbolValue(value) {
  7. if (!$SymbolValueOf) {
  8. throw new $SyntaxError('Symbols are not supported; thisSymbolValue requires that `value` be a Symbol or a Symbol object');
  9. }
  10. if (typeof value === 'symbol') {
  11. return value;
  12. }
  13. return $SymbolValueOf(value);
  14. };