You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
705 B
15 lines
705 B
var call = require('../internals/function-call');
|
|
var isCallable = require('../internals/is-callable');
|
|
var isObject = require('../internals/is-object');
|
|
|
|
var $TypeError = TypeError;
|
|
|
|
// `OrdinaryToPrimitive` abstract operation
|
|
// https://tc39.es/ecma262/#sec-ordinarytoprimitive
|
|
module.exports = function (input, pref) {
|
|
var fn, val;
|
|
if (pref === 'string' && isCallable(fn = input.toString) && !isObject(val = call(fn, input))) return val;
|
|
if (isCallable(fn = input.valueOf) && !isObject(val = call(fn, input))) return val;
|
|
if (pref !== 'string' && isCallable(fn = input.toString) && !isObject(val = call(fn, input))) return val;
|
|
throw $TypeError("Can't convert object to primitive value");
|
|
};
|
|
|