Bug 1610682 - Time out of eager evaluation after 100ms. r=jlast

Differential Revision: https://phabricator.services.mozilla.com/D61775

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Logan Smyth 2020-02-06 23:39:55 +00:00
Родитель 256e1fae96
Коммит e3a676c7fc
3 изменённых файлов: 58 добавлений и 1 удалений

Просмотреть файл

@ -275,11 +275,31 @@ function preventSideEffects(dbg) {
// TODO: re-enable addAllGlobalsAsDebuggees(bug #1610532)
// dbg.addAllGlobalsAsDebuggees();
const timeoutDuration = 100;
const endTime = Date.now() + timeoutDuration;
let count = 0;
function shouldCancel() {
// To keep the evaled code as quick as possible, we avoid querying the
// current time on ever single step and instead check every 100 steps
// as an arbitrary count that seemed to be "often enough".
return ++count % 100 === 0 && Date.now() > endTime;
}
dbg.onEnterFrame = frame => {
if (shouldCancel()) {
return null;
}
frame.onStep = () => {
if (shouldCancel()) {
return null;
}
return undefined;
};
const script = frame.script;
if (data.executedScripts.has(script)) {
return;
return undefined;
}
data.executedScripts.add(script);
@ -287,6 +307,8 @@ function preventSideEffects(dbg) {
for (const offset of offsets) {
script.setBreakpoint(offset, data.handler);
}
return undefined;
};
dbg.onNativeCall = (callee, reason) => {

Просмотреть файл

@ -0,0 +1,34 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/*
* Check that is possible to evaluate JS with evaluation timeouts in place.
*/
add_task(
threadFrontTest(async ({ threadFront, targetFront, debuggee }) => {
const consoleFront = await targetFront.getFront("console");
await consoleFront.evaluateJSAsync(`
function fib(n) {
if (n == 1 || n == 0) {
return 1;
}
return fib(n-1) + fib(n-2)
}
`);
const normalResult = await consoleFront.evaluateJSAsync("fib(1)", {
eager: true,
});
Assert.equal(normalResult.result, 1, "normal eval");
const timeoutResult = await consoleFront.evaluateJSAsync("fib(100)", {
eager: true,
});
Assert.equal(typeof timeoutResult.result, "object", "timeout eval");
Assert.equal(timeoutResult.result.type, "undefined", "timeout eval type");
})
);

Просмотреть файл

@ -122,6 +122,7 @@ skip-if = true # breakpoint sliding is not supported bug 1525685
[test_conditional_breakpoint-02.js]
[test_conditional_breakpoint-03.js]
[test_conditional_breakpoint-04.js]
[test_console_eval-01.js]
[test_logpoint-01.js]
[test_logpoint-02.js]
[test_logpoint-03.js]