// Set breakpoints "everywhere" in a function, then call the function and check that // the breakpoints were added are at the expected columns, and the breakpoints // were executed in th expected order. // // `code` is a JS Script. The final line should define a function `f` to validate. // `expectedBpts` is a string of spaces and carets ('^'). Throws if we don't hit // breakpoints on exactly the columns indicated by the carets. // `expectedOrdering` is a string of integer indices for the offsets that are // executed, in the order that then are executed. Test code can also push // additional items into this string using items.push("!"). function assertOffsetColumns(code, expectedBpts, expectedOrdering = null) { if (expectedOrdering === null) { // The default ordering simply runs the breakpoints in order.
expectedOrdering = Array.from(expectedBpts.match(/\^/g), (_, i) => i).join(" ");
}
// Define the function `f` in a new global. const global = newGlobal({newCompartment: true});
// Treat everything but the last line as initialization code.
global.eval(initCode);
// Run the test code itself.
global.eval(execCode);
// Allow some tests to append to a log that will show up in expected ordering. const hits = global.hits = []; const bpts = new Set();
// Set breakpoints everywhere and call the function. const dbg = new Debugger;
let debuggeeFn = dbg.addDebuggee(global).makeDebuggeeValue(global.f); if (debuggeeFn.isBoundFunction) {
debuggeeFn = debuggeeFn.boundTargetFunction;
}
const { script } = debuggeeFn; for (const offset of script.getAllColumnOffsets()) {
assertEq(offset.lineNumber, 1);
assertEq(offset.columnNumber <= execCode.length, true);
bpts.add(offset.columnNumber);
if (actualOrdering.trimEnd() !== expectedOrdering.trimEnd()) { thrownew Error(`Assertion failed:
code: ${execCode}
bpts: ${expectedBpts}
expected order: ${expectedOrdering}
actual order: ${actualOrdering}\n`);
}
}
Messung V0.5
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.3Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.