diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/debug/Source-reparse.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/debug/Source-reparse.js')
-rw-r--r-- | js/src/jit-test/tests/debug/Source-reparse.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/Source-reparse.js b/js/src/jit-test/tests/debug/Source-reparse.js new file mode 100644 index 0000000000..53700abe05 --- /dev/null +++ b/js/src/jit-test/tests/debug/Source-reparse.js @@ -0,0 +1,50 @@ +// reparsing a source should produce equivalent scripts and avoid invoking the +// onNewScript hook. + +const g = newGlobal({newCompartment: true}); +const dbg = new Debugger; +dbg.addDebuggee(g); + +let globalScript; +dbg.onNewScript = script => { globalScript = script }; + +// Leave `g()` on the first line so we can check that `columnNumber` is passed to the +// reparsed script (`columnNumber` is only used to offset breakpoint column on the first +// line of the script). +g.evaluate(`g(); +function f() { + for (var i = 0; i < 10; i++) { + g(); + } +} + +function g() { + return 3; +} + +f(); +`, { + fileName: "foobar.js", + lineNumber: 3, + columnNumber: 42, +}); + +let onNewScriptCalls = 0; +dbg.onNewScript = script => { onNewScriptCalls++; }; + +const reparsedScript = globalScript.source.reparse(); + +assertEq(onNewScriptCalls, 0); + +assertEq(reparsedScript.url, "foobar.js"); +assertEq(reparsedScript.startLine, 3); +assertEq(reparsedScript.startColumn, 42); + +// Test for the same breakpoint positions in the original and reparsed script. +function getBreakpointPositions(script) { + const offsets = script.getPossibleBreakpoints(); + const str = offsets.map(({ lineNumber, columnNumber }) => `${lineNumber}:${columnNumber}`).toString(); + const childPositions = script.getChildScripts().map(getBreakpointPositions); + return str + childPositions.toString(); +} +assertEq(getBreakpointPositions(globalScript), getBreakpointPositions(reparsedScript)); |