summaryrefslogtreecommitdiff
path: root/cli/tests/unit/timers_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/timers_test.ts')
-rw-r--r--cli/tests/unit/timers_test.ts43
1 files changed, 42 insertions, 1 deletions
diff --git a/cli/tests/unit/timers_test.ts b/cli/tests/unit/timers_test.ts
index e315d018a..55bc11f76 100644
--- a/cli/tests/unit/timers_test.ts
+++ b/cli/tests/unit/timers_test.ts
@@ -7,10 +7,51 @@ import {
unitTest,
} from "./test_util.ts";
-function waitForMs(ms: number): Promise<number> {
+function waitForMs(ms: number): Promise<void> {
return new Promise((resolve): number => setTimeout(resolve, ms));
}
+unitTest(async function functionParameterBindingSuccess(): Promise<void> {
+ const promise = deferred();
+ let count = 0;
+
+ const nullProto = (newCount: number): void => {
+ count = newCount;
+ promise.resolve();
+ };
+
+ Reflect.setPrototypeOf(nullProto, null);
+
+ setTimeout(nullProto, 500, 1);
+ await promise;
+ // count should be reassigned
+ assertEquals(count, 1);
+});
+
+unitTest(async function stringifyAndEvalNonFunctions(): Promise<void> {
+ // eval can only access global scope
+ const global = globalThis as unknown as {
+ globalPromise: ReturnType<typeof deferred>;
+ globalCount: number;
+ };
+ global.globalPromise = deferred();
+ global.globalCount = 0;
+
+ const notAFunction =
+ "globalThis.globalCount++; globalThis.globalPromise.resolve();" as unknown as () =>
+ void;
+
+ setTimeout(notAFunction, 500);
+
+ await global.globalPromise;
+
+ // count should be incremented
+ assertEquals(global.globalCount, 1);
+
+ Reflect.deleteProperty(global, "globalPromise");
+ Reflect.deleteProperty(global, "globalCount");
+});
+
unitTest(async function timeoutSuccess(): Promise<void> {
const promise = deferred();
let count = 0;