Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
872 bytes
|
Line | |
---|
1 | var isObject = require('../internals/is-object');
|
---|
2 | var isSymbol = require('../internals/is-symbol');
|
---|
3 | var ordinaryToPrimitive = require('../internals/ordinary-to-primitive');
|
---|
4 | var wellKnownSymbol = require('../internals/well-known-symbol');
|
---|
5 |
|
---|
6 | var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
|
---|
7 |
|
---|
8 | // `ToPrimitive` abstract operation
|
---|
9 | // https://tc39.es/ecma262/#sec-toprimitive
|
---|
10 | module.exports = function (input, pref) {
|
---|
11 | if (!isObject(input) || isSymbol(input)) return input;
|
---|
12 | var exoticToPrim = input[TO_PRIMITIVE];
|
---|
13 | var result;
|
---|
14 | if (exoticToPrim !== undefined) {
|
---|
15 | if (pref === undefined) pref = 'default';
|
---|
16 | result = exoticToPrim.call(input, pref);
|
---|
17 | if (!isObject(result) || isSymbol(result)) return result;
|
---|
18 | throw TypeError("Can't convert object to primitive value");
|
---|
19 | }
|
---|
20 | if (pref === undefined) pref = 'number';
|
---|
21 | return ordinaryToPrimitive(input, pref);
|
---|
22 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.