fix(runtime/js/timers): Use (0, eval) instead of eval() (#10103)

This commit is contained in:
Nayeem Rahman 2021-04-12 00:40:42 +01:00 committed by GitHub
parent 06b5959eed
commit 8b49d948f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

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