Skip to content

Commit 83f5055

Browse files
committed
lib: bypass delay in AbortSignal.timeout
1 parent a077bb8 commit 83f5055

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

lib/internal/abort_controller.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const {
5050

5151
const {
5252
validateObject,
53-
validateUint32,
5453
kValidateObjectAllowObjects,
5554
} = require('internal/validators');
5655

@@ -236,7 +235,6 @@ class AbortSignal extends EventTarget {
236235
* @returns {AbortSignal}
237236
*/
238237
static timeout(delay) {
239-
validateUint32(delay, 'delay', false);
240238
const signal = new AbortSignal(kDontThrowSymbol);
241239
signal[kTimeout] = true;
242240
clearTimeoutRegistry.register(

test/parallel/test-abortcontroller.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,47 @@ test('abortSignal.throwIfAobrted() works as expected (3)', () => {
274274
throws(() => AbortSignal.abort(actualReason).throwIfAborted(), actualReason);
275275
Reflect.defineProperty(AbortSignal.prototype, 'reason', originalDesc);
276276
});
277+
278+
test('abortSignal.timeout() works with special \'delay\' value', async () => {
279+
const inputs = [
280+
undefined,
281+
null,
282+
true,
283+
false,
284+
'',
285+
[],
286+
{},
287+
NaN,
288+
+Infinity,
289+
-Infinity,
290+
(1.0 / 0.0), // sanity check
291+
parseFloat('x'), // NaN
292+
-10,
293+
-1,
294+
-0.5,
295+
-0.1,
296+
-0.0,
297+
0,
298+
0.0,
299+
0.1,
300+
0.5,
301+
1,
302+
1.0,
303+
2147483648, // Browser behavior: timeouts > 2^31-1 run on next tick
304+
12345678901234, // ditto
305+
];
306+
307+
const signals = [];
308+
309+
for (let i = 0; i < inputs.length; i++) {
310+
signals[i] = AbortSignal.timeout(inputs[i]);
311+
}
312+
313+
await sleep(2);
314+
315+
for (let i = 0; i < inputs.length; i++) {
316+
ok(signals[i].aborted);
317+
ok(signals[i].reason instanceof DOMException);
318+
strictEqual(signals[i].reason.name, 'TimeoutError');
319+
}
320+
});

0 commit comments

Comments
 (0)