ThisSymbolValue.js 536 B

1234567891011121314151617181920
  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/15.0/#sec-thissymbolvalue
  6. module.exports = function ThisSymbolValue(value) {
  7. if (typeof value === 'symbol') {
  8. return value;
  9. }
  10. if (!$SymbolValueOf) {
  11. throw new $SyntaxError('Symbols are not supported; thisSymbolValue requires that `value` be a Symbol or a Symbol object');
  12. }
  13. return $SymbolValueOf(value);
  14. };