1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5 6[ 7 setTimeout(common.mustNotCall(), 1), 8 setInterval(common.mustNotCall(), 1), 9].forEach((timeout) => { 10 assert.strictEqual(Number.isNaN(+timeout), false); 11 assert.strictEqual(+timeout, timeout[Symbol.toPrimitive]()); 12 assert.strictEqual(`${timeout}`, timeout[Symbol.toPrimitive]().toString()); 13 assert.deepStrictEqual(Object.keys({ [timeout]: timeout }), [`${timeout}`]); 14 clearTimeout(+timeout); 15}); 16 17{ 18 // Check that clearTimeout works with number id. 19 const timeout = setTimeout(common.mustNotCall(), 1); 20 const id = +timeout; 21 clearTimeout(id); 22} 23 24{ 25 // Check that clearTimeout works with string id. 26 const timeout = setTimeout(common.mustNotCall(), 1); 27 const id = `${timeout}`; 28 clearTimeout(id); 29} 30