mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix(runtime/js/timers): Use (0, eval) instead of eval() (#10103)
This commit is contained in:
parent
06b5959eed
commit
8b49d948f5
3 changed files with 24 additions and 1 deletions
|
@ -21,6 +21,7 @@ export {
|
||||||
unreachable,
|
unreachable,
|
||||||
} from "../../../test_util/std/testing/asserts.ts";
|
} from "../../../test_util/std/testing/asserts.ts";
|
||||||
export { deferred } from "../../../test_util/std/async/deferred.ts";
|
export { deferred } from "../../../test_util/std/async/deferred.ts";
|
||||||
|
export type { Deferred } from "../../../test_util/std/async/deferred.ts";
|
||||||
export { readLines } from "../../../test_util/std/io/bufio.ts";
|
export { readLines } from "../../../test_util/std/io/bufio.ts";
|
||||||
export { parse as parseArgs } from "../../../test_util/std/flags/mod.ts";
|
export { parse as parseArgs } from "../../../test_util/std/flags/mod.ts";
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
assert,
|
assert,
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertNotEquals,
|
assertNotEquals,
|
||||||
|
Deferred,
|
||||||
deferred,
|
deferred,
|
||||||
unitTest,
|
unitTest,
|
||||||
} from "./test_util.ts";
|
} from "./test_util.ts";
|
||||||
|
@ -64,6 +65,27 @@ unitTest(async function timeoutSuccess(): Promise<void> {
|
||||||
assertEquals(count, 1);
|
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> {
|
unitTest(async function timeoutArgs(): Promise<void> {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const arg = 1;
|
const arg = 1;
|
||||||
|
|
|
@ -442,7 +442,7 @@
|
||||||
if ("function" === typeof callback) {
|
if ("function" === typeof callback) {
|
||||||
callback();
|
callback();
|
||||||
} else {
|
} else {
|
||||||
eval(callback);
|
(0, eval)(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue