Skip to content

Commit 01618c6

Browse files
aduh95bengl
authored andcommitted
tools: add timers functions to the list of restricted globals
PR-URL: #42013 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Mestery <[email protected]>
1 parent a87fa5b commit 01618c6

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/.eslintrc.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ rules:
8383
message: Use `const { atob } = require('buffer');` instead of the global.
8484
- name: btoa
8585
message: Use `const { btoa } = require('buffer');` instead of the global.
86+
- name: clearImmediate
87+
message: Use `const { clearImmediate } = require('timers');` instead of the global.
88+
- name: clearInterval
89+
message: Use `const { clearInterval } = require('timers');` instead of the global.
90+
- name: clearTimeout
91+
message: Use `const { clearTimeout } = require('timers');` instead of the global.
8692
- name: crypto
8793
message: Use `const { crypto } = require('internal/crypto/webcrypto');` instead of the global.
8894
- name: Crypto
@@ -99,6 +105,12 @@ rules:
99105
message: Use `const { performance } = require('perf_hooks');` instead of the global.
100106
- name: queueMicrotask
101107
message: Use `const { queueMicrotask } = require('internal/process/task_queues');` instead of the global.
108+
- name: setImmediate
109+
message: Use `const { setImmediate } = require('timers');` instead of the global.
110+
- name: setInterval
111+
message: Use `const { setInterval } = require('timers');` instead of the global.
112+
- name: setTimeout
113+
message: Use `const { setTimeout } = require('timers');` instead of the global.
102114
- name: structuredClone
103115
message: Use `const { structuredClone } = require('internal/structured_clone');` instead of the global.
104116
- name: SubtleCrypto

lib/timers/promises.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const {
1414
Immediate,
1515
insert
1616
} = require('internal/timers');
17+
const {
18+
clearImmediate,
19+
clearInterval,
20+
clearTimeout,
21+
} = require('timers');
1722

1823
const {
1924
AbortError,
@@ -73,7 +78,6 @@ function setTimeout(after, value, options = {}) {
7378
insert(timeout, timeout._idleTimeout);
7479
if (signal) {
7580
oncancel = FunctionPrototypeBind(cancelListenerHandler,
76-
// eslint-disable-next-line no-undef
7781
timeout, clearTimeout, reject, signal);
7882
signal.addEventListener('abort', oncancel);
7983
}
@@ -117,7 +121,6 @@ function setImmediate(value, options = {}) {
117121
if (!ref) immediate.unref();
118122
if (signal) {
119123
oncancel = FunctionPrototypeBind(cancelListenerHandler,
120-
// eslint-disable-next-line no-undef
121124
immediate, clearImmediate, reject,
122125
signal);
123126
signal.addEventListener('abort', oncancel);
@@ -153,7 +156,6 @@ async function* setInterval(after, value, options = {}) {
153156
insert(interval, interval._idleTimeout);
154157
if (signal) {
155158
onCancel = () => {
156-
// eslint-disable-next-line no-undef
157159
clearInterval(interval);
158160
if (callback) {
159161
callback(
@@ -175,7 +177,6 @@ async function* setInterval(after, value, options = {}) {
175177
}
176178
throw new AbortError(undefined, { cause: signal?.reason });
177179
} finally {
178-
// eslint-disable-next-line no-undef
179180
clearInterval(interval);
180181
signal?.removeEventListener('abort', onCancel);
181182
}

0 commit comments

Comments
 (0)