symbol-define-to-primitive.js 810 B

1234567891011121314151617181920
  1. var call = require('../internals/function-call');
  2. var getBuiltIn = require('../internals/get-built-in');
  3. var wellKnownSymbol = require('../internals/well-known-symbol');
  4. var redefine = require('../internals/redefine');
  5. module.exports = function () {
  6. var Symbol = getBuiltIn('Symbol');
  7. var SymbolPrototype = Symbol && Symbol.prototype;
  8. var valueOf = SymbolPrototype && SymbolPrototype.valueOf;
  9. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  10. if (SymbolPrototype && !SymbolPrototype[TO_PRIMITIVE]) {
  11. // `Symbol.prototype[@@toPrimitive]` method
  12. // https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive
  13. // eslint-disable-next-line no-unused-vars -- required for .length
  14. redefine(SymbolPrototype, TO_PRIMITIVE, function (hint) {
  15. return call(valueOf, this);
  16. });
  17. }
  18. };