|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.0 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var $TypeError = require('es-errors/type');
|
|---|
| 4 | var isObject = require('es-object-atoms/isObject');
|
|---|
| 5 |
|
|---|
| 6 | var Call = require('./Call');
|
|---|
| 7 | var Get = require('./Get');
|
|---|
| 8 | var IsCallable = require('./IsCallable');
|
|---|
| 9 |
|
|---|
| 10 | var inspect = require('object-inspect');
|
|---|
| 11 |
|
|---|
| 12 | // https://262.ecma-international.org/8.0/#sec-ordinarytoprimitive
|
|---|
| 13 |
|
|---|
| 14 | module.exports = function OrdinaryToPrimitive(O, hint) {
|
|---|
| 15 | if (!isObject(O)) {
|
|---|
| 16 | throw new $TypeError('Assertion failed: Type(O) is not Object');
|
|---|
| 17 | }
|
|---|
| 18 | if (/* typeof hint !== 'string' || */ hint !== 'string' && hint !== 'number') {
|
|---|
| 19 | throw new $TypeError('Assertion failed: `hint` must be "string" or "number"');
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | var methodNames = hint === 'string' ? ['toString', 'valueOf'] : ['valueOf', 'toString'];
|
|---|
| 23 |
|
|---|
| 24 | for (var i = 0; i < methodNames.length; i += 1) {
|
|---|
| 25 | var name = methodNames[i];
|
|---|
| 26 | var method = Get(O, name);
|
|---|
| 27 | if (IsCallable(method)) {
|
|---|
| 28 | var result = Call(method, O);
|
|---|
| 29 | if (!isObject(result)) {
|
|---|
| 30 | return result;
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | throw new $TypeError('No primitive value for ' + inspect(O));
|
|---|
| 36 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.