• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2require('../common');
3const assert = require('assert');
4const active = require('timers').active;
5
6// active() should create timers for these
7const legitTimers = [
8  { _idleTimeout: 0 },
9  { _idleTimeout: 1 },
10];
11
12legitTimers.forEach(function(legit) {
13  const savedTimeout = legit._idleTimeout;
14  active(legit);
15  // active() should mutate these objects
16  assert.strictEqual(legit._idleTimeout, savedTimeout);
17  assert(Number.isInteger(legit._idleStart));
18  assert(legit._idleNext);
19  assert(legit._idlePrev);
20});
21
22
23// active() should not create a timer for these
24const bogusTimers = [
25  { _idleTimeout: -1 },
26  { _idleTimeout: undefined },
27];
28
29bogusTimers.forEach(function(bogus) {
30  const savedTimeout = bogus._idleTimeout;
31  active(bogus);
32  // active() should not mutate these objects
33  assert.deepStrictEqual(bogus, { _idleTimeout: savedTimeout });
34});
35