mirror of https://github.com/nodejs/node.git
tools: add timers functions to the list of restricted globals
PR-URL: https://github.com/nodejs/node/pull/42013 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com>pull/42050/head
parent
3aab9860d7
commit
2ff61fd1cd
|
@ -85,6 +85,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
|
||||
|
@ -101,6 +107,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: structuredClone
|
||||
message: Use `const { structuredClone } = require('internal/structured_clone');` instead of the global.
|
||||
- name: SubtleCrypto
|
||||
|
|
|
@ -14,6 +14,11 @@ const {
|
|||
Immediate,
|
||||
insert
|
||||
} = require('internal/timers');
|
||||
const {
|
||||
clearImmediate,
|
||||
clearInterval,
|
||||
clearTimeout,
|
||||
} = require('timers');
|
||||
|
||||
const {
|
||||
AbortError,
|
||||
|
@ -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);
|
||||
signal.addEventListener('abort', oncancel);
|
||||
}
|
||||
|
@ -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);
|
||||
signal.addEventListener('abort', oncancel);
|
||||
|
@ -153,7 +156,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(
|
||||
|
@ -175,7 +177,6 @@ async function* setInterval(after, value, options = {}) {
|
|||
}
|
||||
throw new AbortError(undefined, { cause: signal?.reason });
|
||||
} finally {
|
||||
// eslint-disable-next-line no-undef
|
||||
clearInterval(interval);
|
||||
signal?.removeEventListener('abort', onCancel);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue