mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 20:25:12 -05:00
fix(ext/timers): create primordial eval
(#15110)
This commit is contained in:
parent
03e6727a04
commit
4ec213b0aa
3 changed files with 28 additions and 3 deletions
|
@ -84,6 +84,27 @@ Deno.test(async function timeoutEvalNoScopeLeak() {
|
||||||
Reflect.deleteProperty(global, "globalPromise");
|
Reflect.deleteProperty(global, "globalPromise");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test(async function evalPrimordial() {
|
||||||
|
const global = globalThis as unknown as {
|
||||||
|
globalPromise: ReturnType<typeof deferred>;
|
||||||
|
};
|
||||||
|
global.globalPromise = deferred();
|
||||||
|
const originalEval = globalThis.eval;
|
||||||
|
let wasCalled = false;
|
||||||
|
globalThis.eval = (argument) => {
|
||||||
|
wasCalled = true;
|
||||||
|
return originalEval(argument);
|
||||||
|
};
|
||||||
|
setTimeout(
|
||||||
|
"globalThis.globalPromise.resolve();" as unknown as () => void,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
await global.globalPromise;
|
||||||
|
assert(!wasCalled);
|
||||||
|
Reflect.deleteProperty(global, "globalPromise");
|
||||||
|
globalThis.eval = originalEval;
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test(async function timeoutArgs() {
|
Deno.test(async function timeoutArgs() {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const arg = 1;
|
const arg = 1;
|
||||||
|
|
|
@ -468,6 +468,11 @@
|
||||||
queueMicrotask = value;
|
queueMicrotask = value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Renaming from `eval` is necessary because otherwise it would perform direct
|
||||||
|
// evaluation, allowing user-land access to local variables.
|
||||||
|
// This is because the identifier `eval` is somewhat treated as a keyword
|
||||||
|
primordials.indirectEval = eval;
|
||||||
|
|
||||||
ObjectSetPrototypeOf(primordials, null);
|
ObjectSetPrototypeOf(primordials, null);
|
||||||
ObjectFreeze(primordials);
|
ObjectFreeze(primordials);
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
SafeArrayIterator,
|
SafeArrayIterator,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
TypeError,
|
TypeError,
|
||||||
|
indirectEval,
|
||||||
} = window.__bootstrap.primordials;
|
} = window.__bootstrap.primordials;
|
||||||
const { webidl } = window.__bootstrap;
|
const { webidl } = window.__bootstrap;
|
||||||
const { reportException } = window.__bootstrap.event;
|
const { reportException } = window.__bootstrap.event;
|
||||||
|
@ -155,9 +156,7 @@
|
||||||
reportException(error);
|
reportException(error);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO(@andreubotella): eval doesn't seem to have a primordial, but
|
indirectEval(callback);
|
||||||
// it can be redefined in the global scope.
|
|
||||||
(0, eval)(callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repeat) {
|
if (repeat) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue