main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1019 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var call = require('../internals/function-call');
|
---|
3 | var isObject = require('../internals/is-object');
|
---|
4 | var isSymbol = require('../internals/is-symbol');
|
---|
5 | var getMethod = require('../internals/get-method');
|
---|
6 | var ordinaryToPrimitive = require('../internals/ordinary-to-primitive');
|
---|
7 | var wellKnownSymbol = require('../internals/well-known-symbol');
|
---|
8 |
|
---|
9 | var $TypeError = TypeError;
|
---|
10 | var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
|
---|
11 |
|
---|
12 | // `ToPrimitive` abstract operation
|
---|
13 | // https://tc39.es/ecma262/#sec-toprimitive
|
---|
14 | module.exports = function (input, pref) {
|
---|
15 | if (!isObject(input) || isSymbol(input)) return input;
|
---|
16 | var exoticToPrim = getMethod(input, TO_PRIMITIVE);
|
---|
17 | var result;
|
---|
18 | if (exoticToPrim) {
|
---|
19 | if (pref === undefined) pref = 'default';
|
---|
20 | result = call(exoticToPrim, input, pref);
|
---|
21 | if (!isObject(result) || isSymbol(result)) return result;
|
---|
22 | throw new $TypeError("Can't convert object to primitive value");
|
---|
23 | }
|
---|
24 | if (pref === undefined) pref = 'number';
|
---|
25 | return ordinaryToPrimitive(input, pref);
|
---|
26 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.