diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2021-04-12 00:40:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-12 01:40:42 +0200 |
commit | 8b49d948f58e0665e87e63f7e154ab53fa60a939 (patch) | |
tree | c4ecac6dc2ce62c894636084a2aa53da957c511d /cli/tests/unit/timers_test.ts | |
parent | 06b5959eed5bd634851cd52dc24dca51e48d32de (diff) |
fix(runtime/js/timers): Use (0, eval) instead of eval() (#10103)
Diffstat (limited to 'cli/tests/unit/timers_test.ts')
-rw-r--r-- | cli/tests/unit/timers_test.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/cli/tests/unit/timers_test.ts b/cli/tests/unit/timers_test.ts index 11698b3c3..f04793afe 100644 --- a/cli/tests/unit/timers_test.ts +++ b/cli/tests/unit/timers_test.ts @@ -3,6 +3,7 @@ import { assert, assertEquals, assertNotEquals, + Deferred, deferred, unitTest, } from "./test_util.ts"; @@ -64,6 +65,27 @@ unitTest(async function timeoutSuccess(): Promise<void> { assertEquals(count, 1); }); +unitTest(async function timeoutEvalNoScopeLeak(): Promise<void> { + // eval can only access global scope + const global = globalThis as unknown as { + globalPromise: Deferred<Error>; + }; + global.globalPromise = deferred(); + setTimeout( + ` + try { + console.log(core); + globalThis.globalPromise.reject(new Error("Didn't throw.")); + } catch (error) { + globalThis.globalPromise.resolve(error); + }` as unknown as () => void, + 0, + ); + const error = await global.globalPromise; + assertEquals(error.name, "ReferenceError"); + Reflect.deleteProperty(global, "globalPromise"); +}); + unitTest(async function timeoutArgs(): Promise<void> { const promise = deferred(); const arg = 1; |