Update timers to ignore Date Override (#6552)

This commit is contained in:
Kyle June 2020-07-04 15:16:27 -04:00 committed by GitHub
parent 5f9e600c5b
commit d52e4007c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 4 deletions

View file

@ -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);
});