0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-timers-args.js
Beth Griggs 7c77932fa2 test: refactor several parallel/test-timer tests
Change var to const/let. Simplify test-timers-uncaught-exception.

PR-URL: https://github.com/nodejs/node/pull/10524
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2017-01-03 17:18:36 +00:00

32 lines
717 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
function range(n) {
return 'x'.repeat(n + 1).split('').map(function(_, i) { return i; });
}
function timeout(nargs) {
const args = range(nargs);
setTimeout.apply(null, [callback, 1].concat(args));
function callback() {
assert.deepStrictEqual([].slice.call(arguments), args);
if (nargs < 128) timeout(nargs + 1);
}
}
function interval(nargs) {
const args = range(nargs);
const timer = setTimeout.apply(null, [callback, 1].concat(args));
function callback() {
clearInterval(timer);
assert.deepStrictEqual([].slice.call(arguments), args);
if (nargs < 128) interval(nargs + 1);
}
}
timeout(0);
interval(0);