Skip to content

Commit

Permalink
tools: add timers functions to the list of restricted globals
Browse files Browse the repository at this point in the history
PR-URL: nodejs#42013
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Mestery <[email protected]>
  • Loading branch information
aduh95 authored and danielleadams committed Apr 21, 2022
1 parent 1dfbf3e commit 1b0c4d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ rules:
message: Use `const { atob } = require('buffer');` instead of the global.
- name: btoa
message: Use `const { btoa } = require('buffer');` instead of the global.
- name: clearImmediate
message: Use `const { clearImmediate } = require('timers');` instead of the global.
- name: clearInterval
message: Use `const { clearInterval } = require('timers');` instead of the global.
- name: clearTimeout
message: Use `const { clearTimeout } = require('timers');` instead of the global.
- name: crypto
message: Use `const { crypto } = require('internal/crypto/webcrypto');` instead of the global.
- name: Crypto
Expand All @@ -99,6 +105,12 @@ rules:
message: Use `const { performance } = require('perf_hooks');` instead of the global.
- name: queueMicrotask
message: Use `const { queueMicrotask } = require('internal/process/task_queues');` instead of the global.
- name: setImmediate
message: Use `const { setImmediate } = require('timers');` instead of the global.
- name: setInterval
message: Use `const { setInterval } = require('timers');` instead of the global.
- name: setTimeout
message: Use `const { setTimeout } = require('timers');` instead of the global.
- name: SubtleCrypto
message: Use `const { SubtleCrypto } = require('internal/crypto/webcrypto');` instead of the global.
# Custom rules in tools/eslint-rules
Expand Down
9 changes: 5 additions & 4 deletions lib/timers/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const {
Immediate,
insert
} = require('internal/timers');
const {
clearImmediate,
clearInterval,
clearTimeout,
} = require('timers');

const {
AbortError,
Expand Down Expand Up @@ -73,7 +78,6 @@ function setTimeout(after, value, options = {}) {
insert(timeout, timeout._idleTimeout);
if (signal) {
oncancel = FunctionPrototypeBind(cancelListenerHandler,
// eslint-disable-next-line no-undef
timeout, clearTimeout, reject);
signal.addEventListener('abort', oncancel);
}
Expand Down Expand Up @@ -117,7 +121,6 @@ function setImmediate(value, options = {}) {
if (!ref) immediate.unref();
if (signal) {
oncancel = FunctionPrototypeBind(cancelListenerHandler,
// eslint-disable-next-line no-undef
immediate, clearImmediate, reject);
signal.addEventListener('abort', oncancel);
}
Expand Down Expand Up @@ -152,7 +155,6 @@ async function* setInterval(after, value, options = {}) {
insert(interval, interval._idleTimeout);
if (signal) {
onCancel = () => {
// eslint-disable-next-line no-undef
clearInterval(interval);
if (callback) {
callback(PromiseReject(new AbortError()));
Expand All @@ -172,7 +174,6 @@ async function* setInterval(after, value, options = {}) {
}
throw new AbortError();
} finally {
// eslint-disable-next-line no-undef
clearInterval(interval);
signal?.removeEventListener('abort', onCancel);
}
Expand Down

0 comments on commit 1b0c4d9

Please sign in to comment.