xref: /third_party/node/test/parallel/test-timers-args.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cifunction range(n) {
61cb0ef41Sopenharmony_ci  return 'x'.repeat(n + 1).split('').map(function(_, i) { return i; });
71cb0ef41Sopenharmony_ci}
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_cifunction timeout(nargs) {
101cb0ef41Sopenharmony_ci  const args = range(nargs);
111cb0ef41Sopenharmony_ci  setTimeout.apply(null, [callback, 1].concat(args));
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci  function callback() {
141cb0ef41Sopenharmony_ci    assert.deepStrictEqual([].slice.call(arguments), args);
151cb0ef41Sopenharmony_ci    if (nargs < 128) timeout(nargs + 1);
161cb0ef41Sopenharmony_ci  }
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cifunction interval(nargs) {
201cb0ef41Sopenharmony_ci  const args = range(nargs);
211cb0ef41Sopenharmony_ci  const timer = setTimeout.apply(null, [callback, 1].concat(args));
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  function callback() {
241cb0ef41Sopenharmony_ci    clearInterval(timer);
251cb0ef41Sopenharmony_ci    assert.deepStrictEqual([].slice.call(arguments), args);
261cb0ef41Sopenharmony_ci    if (nargs < 128) interval(nargs + 1);
271cb0ef41Sopenharmony_ci  }
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_citimeout(0);
311cb0ef41Sopenharmony_ciinterval(0);
32

Indexes created Thu Nov 07 10:32:03 CST 2024