mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
Update timers to ignore Date Override (#6552)
This commit is contained in:
parent
5f9e600c5b
commit
d52e4007c8
2 changed files with 42 additions and 4 deletions
|
@ -366,3 +366,37 @@ unitTest(async function timerNestedMicrotaskOrdering(): Promise<void> {
|
|||
unitTest(function testQueueMicrotask() {
|
||||
assertEquals(typeof queueMicrotask, "function");
|
||||
});
|
||||
|
||||
unitTest(async function timerIgnoresDateOverride(): Promise<void> {
|
||||
const OriginalDate = Date;
|
||||
const { promise, resolve, reject } = deferred();
|
||||
let hasThrown = 0;
|
||||
try {
|
||||
const overrideCalled: () => number = () => {
|
||||
reject("global Date override used over original Date object");
|
||||
return 0;
|
||||
};
|
||||
function DateOverride(): void {
|
||||
overrideCalled();
|
||||
}
|
||||
globalThis.Date = DateOverride as DateConstructor;
|
||||
globalThis.Date.now = overrideCalled;
|
||||
globalThis.Date.UTC = overrideCalled;
|
||||
globalThis.Date.parse = overrideCalled;
|
||||
queueMicrotask(resolve);
|
||||
await promise;
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
if (typeof err === "string") {
|
||||
assertEquals(err, "global Date override used over original Date object");
|
||||
hasThrown = 2;
|
||||
} else if (err instanceof TypeError) {
|
||||
hasThrown = 3;
|
||||
} else {
|
||||
hasThrown = 4;
|
||||
}
|
||||
} finally {
|
||||
globalThis.Date = OriginalDate;
|
||||
}
|
||||
assertEquals(hasThrown, 1);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue