Ignore:
Timestamp:
12/12/24 17:06:06 (5 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
d565449
Message:

Pred finalna verzija

Location:
imaps-frontend/node_modules/es-to-primitive/test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/node_modules/es-to-primitive/test/es2015.js

    rd565449 r0c6b92a  
    44var toPrimitive = require('../es2015');
    55var is = require('object-is');
    6 var forEach = require('foreach');
     6var forEach = require('for-each');
    77var functionName = require('function.prototype.name');
    88var debug = require('object-inspect');
     9var v = require('es-value-fixtures');
    910
    10 var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';
    11 var hasSymbolToPrimitive = hasSymbols && typeof Symbol.toPrimitive === 'symbol';
     11/** @typedef {{ toString?: unknown, valueOf?: unknown, [Symbol.toPrimitive]?: unknown }} Coercible */
    1212
    1313test('function properties', function (t) {
     
    1818});
    1919
    20 var primitives = [null, undefined, true, false, 0, -0, 42, NaN, Infinity, -Infinity, '', 'abc'];
    21 
    2220test('primitives', function (t) {
    23         forEach(primitives, function (i) {
     21        forEach(v.primitives, function (i) {
    2422                t.ok(is(toPrimitive(i), i), 'toPrimitive(' + debug(i) + ') returns the same value');
    2523                t.ok(is(toPrimitive(i, String), i), 'toPrimitive(' + debug(i) + ', String) returns the same value');
     
    2927});
    3028
    31 test('Symbols', { skip: !hasSymbols }, function (t) {
    32         var symbols = [
    33                 Symbol('foo'),
    34                 Symbol.iterator,
    35                 Symbol['for']('foo') // eslint-disable-line no-restricted-properties
    36         ];
    37         forEach(symbols, function (sym) {
     29test('Symbols', { skip: !v.hasSymbols }, function (t) {
     30        forEach(v.symbols, function (sym) {
    3831                t.equal(toPrimitive(sym), sym, 'toPrimitive(' + debug(sym) + ') returns the same value');
    3932                t.equal(toPrimitive(sym, String), sym, 'toPrimitive(' + debug(sym) + ', String) returns the same value');
     
    6962});
    7063
    71 var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } };
    72 var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } };
    73 var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } };
    74 var coercibleFnObject = {
    75         valueOf: function () { return function valueOfFn() {}; },
    76         toString: function () { return 42; }
    77 };
    78 var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } };
    79 var uncoercibleFnObject = {
    80         valueOf: function () { return function valueOfFn() {}; },
    81         toString: function () { return function toStrFn() {}; }
    82 };
     64test('Objects', function (t) {
     65        t.equal(toPrimitive(v.coercibleObject), v.coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf');
     66        t.equal(toPrimitive(v.coercibleObject, Number), v.coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf');
     67        t.equal(toPrimitive(v.coercibleObject, String), v.coercibleObject.toString(), 'coercibleObject with hint String coerces to non-stringified toString');
    8368
    84 test('Objects', function (t) {
    85         t.equal(toPrimitive(coercibleObject), coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf');
    86         t.equal(toPrimitive(coercibleObject, Number), coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf');
    87         t.equal(toPrimitive(coercibleObject, String), coercibleObject.toString(), 'coercibleObject with hint String coerces to non-stringified toString');
    88 
    89         t.equal(toPrimitive(coercibleFnObject), coercibleFnObject.toString(), 'coercibleFnObject coerces to non-stringified toString');
    90         t.equal(toPrimitive(coercibleFnObject, Number), coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to non-stringified toString');
    91         t.equal(toPrimitive(coercibleFnObject, String), coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to non-stringified toString');
     69        t.equal(toPrimitive(v.coercibleFnObject), v.coercibleFnObject.toString(), 'coercibleFnObject coerces to non-stringified toString');
     70        t.equal(toPrimitive(v.coercibleFnObject, Number), v.coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to non-stringified toString');
     71        t.equal(toPrimitive(v.coercibleFnObject, String), v.coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to non-stringified toString');
    9272
    9373        t.equal(toPrimitive({}), '[object Object]', '{} with no hint coerces to Object#toString');
     
    9575        t.equal(toPrimitive({}, String), '[object Object]', '{} with hint String coerces to Object#toString');
    9676
    97         t.equal(toPrimitive(toStringOnlyObject), toStringOnlyObject.toString(), 'toStringOnlyObject returns non-stringified toString');
    98         t.equal(toPrimitive(toStringOnlyObject, Number), toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns non-stringified toString');
    99         t.equal(toPrimitive(toStringOnlyObject, String), toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns non-stringified toString');
     77        t.equal(toPrimitive(v.toStringOnlyObject), v.toStringOnlyObject.toString(), 'toStringOnlyObject returns non-stringified toString');
     78        t.equal(toPrimitive(v.toStringOnlyObject, Number), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns non-stringified toString');
     79        t.equal(toPrimitive(v.toStringOnlyObject, String), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns non-stringified toString');
    10080
    101         t.equal(toPrimitive(valueOfOnlyObject), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');
    102         t.equal(toPrimitive(valueOfOnlyObject, Number), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');
    103         t.equal(toPrimitive(valueOfOnlyObject, String), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns non-stringified valueOf');
     81        t.equal(toPrimitive(v.valueOfOnlyObject), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');
     82        t.equal(toPrimitive(v.valueOfOnlyObject, Number), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');
     83        t.equal(toPrimitive(v.valueOfOnlyObject, String), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns non-stringified valueOf');
    10484
    105         t.test('Symbol.toPrimitive', { skip: !hasSymbolToPrimitive }, function (st) {
     85        t.test('Symbol.toPrimitive', { skip: !v.hasSymbols || !Symbol.toPrimitive }, function (st) {
     86                /** @type {Coercible} */
    10687                var overriddenObject = { toString: st.fail, valueOf: st.fail };
    107                 overriddenObject[Symbol.toPrimitive] = function (hint) { return String(hint); };
     88                overriddenObject[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) {
     89                        return String(hint);
     90                };
    10891
    10992                st.equal(toPrimitive(overriddenObject), 'default', 'object with Symbol.toPrimitive + no hint invokes that');
     
    11194                st.equal(toPrimitive(overriddenObject, String), 'string', 'object with Symbol.toPrimitive + hint String invokes that');
    11295
    113                 var nullToPrimitive = { toString: coercibleObject.toString, valueOf: coercibleObject.valueOf };
     96                /** @type {Coercible} */
     97                var nullToPrimitive = { toString: v.coercibleObject.toString, valueOf: v.coercibleObject.valueOf };
    11498                nullToPrimitive[Symbol.toPrimitive] = null;
    115                 st.equal(toPrimitive(nullToPrimitive), toPrimitive(coercibleObject), 'object with no hint + null Symbol.toPrimitive ignores it');
    116                 st.equal(toPrimitive(nullToPrimitive, Number), toPrimitive(coercibleObject, Number), 'object with hint Number + null Symbol.toPrimitive ignores it');
    117                 st.equal(toPrimitive(nullToPrimitive, String), toPrimitive(coercibleObject, String), 'object with hint String + null Symbol.toPrimitive ignores it');
     99                st.equal(toPrimitive(nullToPrimitive), toPrimitive(v.coercibleObject), 'object with no hint + null Symbol.toPrimitive ignores it');
     100                st.equal(toPrimitive(nullToPrimitive, Number), toPrimitive(v.coercibleObject, Number), 'object with hint Number + null Symbol.toPrimitive ignores it');
     101                st.equal(toPrimitive(nullToPrimitive, String), toPrimitive(v.coercibleObject, String), 'object with hint String + null Symbol.toPrimitive ignores it');
    118102
    119103                st.test('exceptions', function (sst) {
     104                        /** @type {Coercible} */
    120105                        var nonFunctionToPrimitive = { toString: sst.fail, valueOf: sst.fail };
    121106                        nonFunctionToPrimitive[Symbol.toPrimitive] = {};
    122107                        sst['throws'](toPrimitive.bind(null, nonFunctionToPrimitive), TypeError, 'Symbol.toPrimitive returning a non-function throws');
    123108
     109                        /** @type {Coercible} */
    124110                        var uncoercibleToPrimitive = { toString: sst.fail, valueOf: sst.fail };
    125                         uncoercibleToPrimitive[Symbol.toPrimitive] = function (hint) {
     111                        uncoercibleToPrimitive[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) {
    126112                                return { toString: function () { return hint; } };
    127113                        };
    128114                        sst['throws'](toPrimitive.bind(null, uncoercibleToPrimitive), TypeError, 'Symbol.toPrimitive returning an object throws');
    129115
     116                        /** @type {Coercible} */
    130117                        var throwingToPrimitive = { toString: sst.fail, valueOf: sst.fail };
    131                         throwingToPrimitive[Symbol.toPrimitive] = function (hint) { throw new RangeError(hint); };
     118                        throwingToPrimitive[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) {
     119                                throw new RangeError(hint);
     120                        };
    132121                        sst['throws'](toPrimitive.bind(null, throwingToPrimitive), RangeError, 'Symbol.toPrimitive throwing throws');
    133122
     
    139128
    140129        t.test('exceptions', function (st) {
    141                 st['throws'](toPrimitive.bind(null, uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');
    142                 st['throws'](toPrimitive.bind(null, uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');
    143                 st['throws'](toPrimitive.bind(null, uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');
     130                st['throws'](toPrimitive.bind(null, v.uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');
     131                st['throws'](toPrimitive.bind(null, v.uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');
     132                st['throws'](toPrimitive.bind(null, v.uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');
    144133
    145                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');
    146                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');
    147                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');
     134                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');
     135                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');
     136                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');
    148137                st.end();
    149138        });
  • imaps-frontend/node_modules/es-to-primitive/test/es5.js

    rd565449 r0c6b92a  
    44var toPrimitive = require('../es5');
    55var is = require('object-is');
    6 var forEach = require('foreach');
     6var forEach = require('for-each');
    77var functionName = require('function.prototype.name');
    88var debug = require('object-inspect');
    9 var hasSymbols = require('has-symbols')();
     9var v = require('es-value-fixtures');
    1010
    1111test('function properties', function (t) {
     
    1616});
    1717
    18 var primitives = [null, undefined, true, false, 0, -0, 42, NaN, Infinity, -Infinity, '', 'abc'];
    19 
    2018test('primitives', function (t) {
    21         forEach(primitives, function (i) {
     19        forEach(v.primitives, function (i) {
    2220                t.ok(is(toPrimitive(i), i), 'toPrimitive(' + debug(i) + ') returns the same value');
    2321                t.ok(is(toPrimitive(i, String), i), 'toPrimitive(' + debug(i) + ', String) returns the same value');
     
    2725});
    2826
    29 test('Symbols', { skip: !hasSymbols }, function (t) {
    30         var symbols = [
    31                 Symbol('foo'),
    32                 Symbol.iterator,
    33                 Symbol['for']('foo') // eslint-disable-line no-restricted-properties
    34         ];
    35         forEach(symbols, function (sym) {
     27test('Symbols', { skip: !v.hasSymbols }, function (t) {
     28        forEach(v.symbols, function (sym) {
    3629                t.equal(toPrimitive(sym), sym, 'toPrimitive(' + debug(sym) + ') returns the same value');
    3730                t.equal(toPrimitive(sym, String), sym, 'toPrimitive(' + debug(sym) + ', String) returns the same value');
     
    7063});
    7164
    72 var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } };
    73 var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } };
    74 var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } };
    75 var coercibleFnObject = {
    76         valueOf: function () { return function valueOfFn() {}; },
    77         toString: function () { return 42; }
    78 };
    79 var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } };
    80 var uncoercibleFnObject = {
    81         valueOf: function () { return function valueOfFn() {}; },
    82         toString: function () { return function toStrFn() {}; }
    83 };
     65test('Objects', function (t) {
     66        t.equal(toPrimitive(v.coercibleObject), v.coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf');
     67        t.equal(toPrimitive(v.coercibleObject, String), v.coercibleObject.toString(), 'coercibleObject with hint String coerces to toString');
     68        t.equal(toPrimitive(v.coercibleObject, Number), v.coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf');
    8469
    85 test('Objects', function (t) {
    86         t.equal(toPrimitive(coercibleObject), coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf');
    87         t.equal(toPrimitive(coercibleObject, String), coercibleObject.toString(), 'coercibleObject with hint String coerces to toString');
    88         t.equal(toPrimitive(coercibleObject, Number), coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf');
    89 
    90         t.equal(toPrimitive(coercibleFnObject), coercibleFnObject.toString(), 'coercibleFnObject coerces to toString');
    91         t.equal(toPrimitive(coercibleFnObject, String), coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to toString');
    92         t.equal(toPrimitive(coercibleFnObject, Number), coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to toString');
     70        t.equal(toPrimitive(v.coercibleFnObject), v.coercibleFnObject.toString(), 'coercibleFnObject coerces to toString');
     71        t.equal(toPrimitive(v.coercibleFnObject, String), v.coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to toString');
     72        t.equal(toPrimitive(v.coercibleFnObject, Number), v.coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to toString');
    9373
    9474        t.ok(is(toPrimitive({}), '[object Object]'), '{} with no hint coerces to Object#toString');
     
    9676        t.ok(is(toPrimitive({}, Number), '[object Object]'), '{} with hint Number coerces to Object#toString');
    9777
    98         t.equal(toPrimitive(toStringOnlyObject), toStringOnlyObject.toString(), 'toStringOnlyObject returns toString');
    99         t.equal(toPrimitive(toStringOnlyObject, String), toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns toString');
    100         t.equal(toPrimitive(toStringOnlyObject, Number), toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns toString');
     78        t.equal(toPrimitive(v.toStringOnlyObject), v.toStringOnlyObject.toString(), 'toStringOnlyObject returns toString');
     79        t.equal(toPrimitive(v.toStringOnlyObject, String), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns toString');
     80        t.equal(toPrimitive(v.toStringOnlyObject, Number), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns toString');
    10181
    102         t.equal(toPrimitive(valueOfOnlyObject), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');
    103         t.equal(toPrimitive(valueOfOnlyObject, String), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns valueOf');
    104         t.equal(toPrimitive(valueOfOnlyObject, Number), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');
     82        t.equal(toPrimitive(v.valueOfOnlyObject), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');
     83        t.equal(toPrimitive(v.valueOfOnlyObject, String), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns valueOf');
     84        t.equal(toPrimitive(v.valueOfOnlyObject, Number), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');
    10585
    10686        t.test('exceptions', function (st) {
    107                 st['throws'](toPrimitive.bind(null, uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');
    108                 st['throws'](toPrimitive.bind(null, uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');
    109                 st['throws'](toPrimitive.bind(null, uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');
     87                st['throws'](toPrimitive.bind(null, v.uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');
     88                st['throws'](toPrimitive.bind(null, v.uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');
     89                st['throws'](toPrimitive.bind(null, v.uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');
    11090
    111                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');
    112                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');
    113                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');
     91                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');
     92                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');
     93                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');
    11494                st.end();
    11595        });
  • imaps-frontend/node_modules/es-to-primitive/test/es6.js

    rd565449 r0c6b92a  
    44var toPrimitive = require('../es6');
    55var is = require('object-is');
    6 var forEach = require('foreach');
     6var forEach = require('for-each');
    77var functionName = require('function.prototype.name');
    88var debug = require('object-inspect');
     9var v = require('es-value-fixtures');
    910
    10 var hasSymbols = require('has-symbols')();
    11 var hasSymbolToPrimitive = hasSymbols && typeof Symbol.toPrimitive === 'symbol';
     11/** @typedef {{ toString?: unknown, valueOf?: unknown, [Symbol.toPrimitive]?: unknown }} Coercible */
    1212
    1313test('function properties', function (t) {
     
    1818});
    1919
    20 var primitives = [null, undefined, true, false, 0, -0, 42, NaN, Infinity, -Infinity, '', 'abc'];
    21 
    2220test('primitives', function (t) {
    23         forEach(primitives, function (i) {
     21        forEach(v.primitives, function (i) {
    2422                t.ok(is(toPrimitive(i), i), 'toPrimitive(' + debug(i) + ') returns the same value');
    2523                t.ok(is(toPrimitive(i, String), i), 'toPrimitive(' + debug(i) + ', String) returns the same value');
     
    2927});
    3028
    31 test('Symbols', { skip: !hasSymbols }, function (t) {
    32         var symbols = [
    33                 Symbol('foo'),
    34                 Symbol.iterator,
    35                 Symbol['for']('foo') // eslint-disable-line no-restricted-properties
    36         ];
    37         forEach(symbols, function (sym) {
     29test('Symbols', { skip: !v.hasSymbols }, function (t) {
     30        forEach(v.symbols, function (sym) {
    3831                t.equal(toPrimitive(sym), sym, 'toPrimitive(' + debug(sym) + ') returns the same value');
    3932                t.equal(toPrimitive(sym, String), sym, 'toPrimitive(' + debug(sym) + ', String) returns the same value');
     
    6962});
    7063
    71 var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } };
    72 var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } };
    73 var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } };
    74 var coercibleFnObject = {
    75         valueOf: function () { return function valueOfFn() {}; },
    76         toString: function () { return 42; }
    77 };
    78 var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } };
    79 var uncoercibleFnObject = {
    80         valueOf: function () { return function valueOfFn() {}; },
    81         toString: function () { return function toStrFn() {}; }
    82 };
     64test('Objects', function (t) {
     65        t.equal(toPrimitive(v.coercibleObject), v.coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf');
     66        t.equal(toPrimitive(v.coercibleObject, Number), v.coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf');
     67        t.equal(toPrimitive(v.coercibleObject, String), v.coercibleObject.toString(), 'coercibleObject with hint String coerces to non-stringified toString');
    8368
    84 test('Objects', function (t) {
    85         t.equal(toPrimitive(coercibleObject), coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf');
    86         t.equal(toPrimitive(coercibleObject, Number), coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf');
    87         t.equal(toPrimitive(coercibleObject, String), coercibleObject.toString(), 'coercibleObject with hint String coerces to non-stringified toString');
    88 
    89         t.equal(toPrimitive(coercibleFnObject), coercibleFnObject.toString(), 'coercibleFnObject coerces to non-stringified toString');
    90         t.equal(toPrimitive(coercibleFnObject, Number), coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to non-stringified toString');
    91         t.equal(toPrimitive(coercibleFnObject, String), coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to non-stringified toString');
     69        t.equal(toPrimitive(v.coercibleFnObject), v.coercibleFnObject.toString(), 'coercibleFnObject coerces to non-stringified toString');
     70        t.equal(toPrimitive(v.coercibleFnObject, Number), v.coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to non-stringified toString');
     71        t.equal(toPrimitive(v.coercibleFnObject, String), v.coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to non-stringified toString');
    9272
    9373        t.equal(toPrimitive({}), '[object Object]', '{} with no hint coerces to Object#toString');
     
    9575        t.equal(toPrimitive({}, String), '[object Object]', '{} with hint String coerces to Object#toString');
    9676
    97         t.equal(toPrimitive(toStringOnlyObject), toStringOnlyObject.toString(), 'toStringOnlyObject returns non-stringified toString');
    98         t.equal(toPrimitive(toStringOnlyObject, Number), toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns non-stringified toString');
    99         t.equal(toPrimitive(toStringOnlyObject, String), toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns non-stringified toString');
     77        t.equal(toPrimitive(v.toStringOnlyObject), v.toStringOnlyObject.toString(), 'toStringOnlyObject returns non-stringified toString');
     78        t.equal(toPrimitive(v.toStringOnlyObject, Number), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns non-stringified toString');
     79        t.equal(toPrimitive(v.toStringOnlyObject, String), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns non-stringified toString');
    10080
    101         t.equal(toPrimitive(valueOfOnlyObject), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');
    102         t.equal(toPrimitive(valueOfOnlyObject, Number), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');
    103         t.equal(toPrimitive(valueOfOnlyObject, String), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns non-stringified valueOf');
     81        t.equal(toPrimitive(v.valueOfOnlyObject), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');
     82        t.equal(toPrimitive(v.valueOfOnlyObject, Number), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');
     83        t.equal(toPrimitive(v.valueOfOnlyObject, String), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns non-stringified valueOf');
    10484
    105         t.test('Symbol.toPrimitive', { skip: !hasSymbolToPrimitive }, function (st) {
     85        t.test('Symbol.toPrimitive', { skip: !v.hasSymbols || !Symbol.toPrimitive }, function (st) {
     86                /** @type {Coercible} */
    10687                var overriddenObject = { toString: st.fail, valueOf: st.fail };
    107                 overriddenObject[Symbol.toPrimitive] = function (hint) { return String(hint); };
     88                overriddenObject[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) {
     89                        return String(hint);
     90                };
    10891
    10992                st.equal(toPrimitive(overriddenObject), 'default', 'object with Symbol.toPrimitive + no hint invokes that');
     
    11194                st.equal(toPrimitive(overriddenObject, String), 'string', 'object with Symbol.toPrimitive + hint String invokes that');
    11295
    113                 var nullToPrimitive = { toString: coercibleObject.toString, valueOf: coercibleObject.valueOf };
     96                /** @type {Coercible} */
     97                var nullToPrimitive = { toString: v.coercibleObject.toString, valueOf: v.coercibleObject.valueOf };
    11498                nullToPrimitive[Symbol.toPrimitive] = null;
    115                 st.equal(toPrimitive(nullToPrimitive), toPrimitive(coercibleObject), 'object with no hint + null Symbol.toPrimitive ignores it');
    116                 st.equal(toPrimitive(nullToPrimitive, Number), toPrimitive(coercibleObject, Number), 'object with hint Number + null Symbol.toPrimitive ignores it');
    117                 st.equal(toPrimitive(nullToPrimitive, String), toPrimitive(coercibleObject, String), 'object with hint String + null Symbol.toPrimitive ignores it');
     99                st.equal(toPrimitive(nullToPrimitive), toPrimitive(v.coercibleObject), 'object with no hint + null Symbol.toPrimitive ignores it');
     100                st.equal(toPrimitive(nullToPrimitive, Number), toPrimitive(v.coercibleObject, Number), 'object with hint Number + null Symbol.toPrimitive ignores it');
     101                st.equal(toPrimitive(nullToPrimitive, String), toPrimitive(v.coercibleObject, String), 'object with hint String + null Symbol.toPrimitive ignores it');
    118102
    119103                st.test('exceptions', function (sst) {
     104                        /** @type {Coercible} */
    120105                        var nonFunctionToPrimitive = { toString: sst.fail, valueOf: sst.fail };
    121106                        nonFunctionToPrimitive[Symbol.toPrimitive] = {};
    122107                        sst['throws'](toPrimitive.bind(null, nonFunctionToPrimitive), TypeError, 'Symbol.toPrimitive returning a non-function throws');
    123108
     109                        /** @type {Coercible} */
    124110                        var uncoercibleToPrimitive = { toString: sst.fail, valueOf: sst.fail };
    125                         uncoercibleToPrimitive[Symbol.toPrimitive] = function (hint) {
     111                        uncoercibleToPrimitive[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) {
    126112                                return { toString: function () { return hint; } };
    127113                        };
    128114                        sst['throws'](toPrimitive.bind(null, uncoercibleToPrimitive), TypeError, 'Symbol.toPrimitive returning an object throws');
    129115
     116                        /** @type {Coercible} */
    130117                        var throwingToPrimitive = { toString: sst.fail, valueOf: sst.fail };
    131                         throwingToPrimitive[Symbol.toPrimitive] = function (hint) { throw new RangeError(hint); };
     118                        throwingToPrimitive[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) {
     119                                throw new RangeError(hint);
     120                        };
    132121                        sst['throws'](toPrimitive.bind(null, throwingToPrimitive), RangeError, 'Symbol.toPrimitive throwing throws');
    133122
     
    139128
    140129        t.test('exceptions', function (st) {
    141                 st['throws'](toPrimitive.bind(null, uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');
    142                 st['throws'](toPrimitive.bind(null, uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');
    143                 st['throws'](toPrimitive.bind(null, uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');
     130                st['throws'](toPrimitive.bind(null, v.uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');
     131                st['throws'](toPrimitive.bind(null, v.uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');
     132                st['throws'](toPrimitive.bind(null, v.uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');
    144133
    145                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');
    146                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');
    147                 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');
     134                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');
     135                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');
     136                st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');
    148137                st.end();
    149138        });
Note: See TracChangeset for help on using the changeset viewer.