From a3bfad3473a3efc1eb1da81a7a9975ce6b4e62a5 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 16 Feb 2022 11:46:23 +0100 Subject: [PATCH 1/3] tools: add timers functions to the list of restricted globals --- lib/.eslintrc.yaml | 12 ++++++++++++ lib/timers/promises.js | 10 ++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 86d1438cd93723..95781d439a52c3 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -79,6 +79,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 @@ -93,6 +99,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 diff --git a/lib/timers/promises.js b/lib/timers/promises.js index 5e5ead5f3e7601..5b9dceb13b59c1 100644 --- a/lib/timers/promises.js +++ b/lib/timers/promises.js @@ -7,6 +7,7 @@ const { ReflectConstruct, SafePromisePrototypeFinally, Symbol, + globalThis, } = primordials; const { @@ -14,6 +15,11 @@ const { Immediate, insert } = require('internal/timers'); +const { + clearImmediate, + clearInterval, + clearTimeout, +} = globalThis; const { AbortError, @@ -73,7 +79,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 +122,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 +157,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 +178,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); } From 757364a293185ab20013836c69cabfad66a44e57 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 16 Feb 2022 14:59:59 +0100 Subject: [PATCH 2/3] fixup! tools: add timers functions to the list of restricted globals --- lib/timers/promises.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/timers/promises.js b/lib/timers/promises.js index 5b9dceb13b59c1..c5d429cce20bcb 100644 --- a/lib/timers/promises.js +++ b/lib/timers/promises.js @@ -19,7 +19,7 @@ const { clearImmediate, clearInterval, clearTimeout, -} = globalThis; +} = require('timers'); const { AbortError, From 296395c0ee48f208477821249bda217233030edf Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 16 Feb 2022 15:02:53 +0100 Subject: [PATCH 3/3] fixup! tools: add timers functions to the list of restricted globals --- lib/timers/promises.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/timers/promises.js b/lib/timers/promises.js index c5d429cce20bcb..47a78de32efa3b 100644 --- a/lib/timers/promises.js +++ b/lib/timers/promises.js @@ -7,7 +7,6 @@ const { ReflectConstruct, SafePromisePrototypeFinally, Symbol, - globalThis, } = primordials; const {