main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
723 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | 'use strict';
|
---|
| 2 | var call = require('../internals/function-call');
|
---|
| 3 | var isCallable = require('../internals/is-callable');
|
---|
| 4 | var isObject = require('../internals/is-object');
|
---|
| 5 |
|
---|
| 6 | var $TypeError = TypeError;
|
---|
| 7 |
|
---|
| 8 | // `OrdinaryToPrimitive` abstract operation
|
---|
| 9 | // https://tc39.es/ecma262/#sec-ordinarytoprimitive
|
---|
| 10 | module.exports = function (input, pref) {
|
---|
| 11 | var fn, val;
|
---|
| 12 | if (pref === 'string' && isCallable(fn = input.toString) && !isObject(val = call(fn, input))) return val;
|
---|
| 13 | if (isCallable(fn = input.valueOf) && !isObject(val = call(fn, input))) return val;
|
---|
| 14 | if (pref !== 'string' && isCallable(fn = input.toString) && !isObject(val = call(fn, input))) return val;
|
---|
| 15 | throw new $TypeError("Can't convert object to primitive value");
|
---|
| 16 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.