提交 590463bd 编写于 作者: 迷渡's avatar 迷渡 提交者: Ryan Dahl

setTimeout's params should not be bigint (#2834)

上级 b5a5e973
......@@ -179,6 +179,12 @@ function checkThis(thisArg: unknown): void {
}
}
function checkBigInt(n: unknown): void {
if (typeof n === "bigint") {
throw new TypeError("Cannot convert a BigInt value to a number");
}
}
function setTimer(
cb: (...args: Args) => void,
delay: number,
......@@ -224,6 +230,7 @@ export function setTimeout(
delay: number = 0,
...args: Args
): number {
checkBigInt(delay);
// @ts-ignore
checkThis(this);
return setTimer(cb, delay, args, false);
......@@ -235,6 +242,7 @@ export function setInterval(
delay: number = 0,
...args: Args
): number {
checkBigInt(delay);
// @ts-ignore
checkThis(this);
return setTimer(cb, delay, args, true);
......
......@@ -244,6 +244,21 @@ test(async function clearTimeoutShouldConvertToNumber(): Promise<void> {
assert(called);
});
test(function setTimeoutShouldThrowWithBigint(): void {
let hasThrown = 0;
try {
setTimeout((): void => {}, (1n as unknown) as number);
hasThrown = 1;
} catch (err) {
if (err instanceof TypeError) {
hasThrown = 2;
} else {
hasThrown = 3;
}
}
assertEquals(hasThrown, 2);
});
test(function testFunctionName(): void {
assertEquals(clearTimeout.name, "clearTimeout");
assertEquals(clearInterval.name, "clearInterval");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册