Commit c68220b4 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[tools] Fix system-analyzer source line numbers

Properly indent wrapper source lines so the source line numbers
are easily visible.

Change-Id: I25095ca3e15a8e953c6e826eb8594289a10aa41b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2551105
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71439}
parent 2795d8e4
...@@ -51,6 +51,10 @@ export class Script { ...@@ -51,6 +51,10 @@ export class Script {
this.lineToColumn = new Map(); this.lineToColumn = new Map();
} }
get length() {
return this.source.length;
}
addSourcePosition(line, column, entry) { addSourcePosition(line, column, entry) {
let sourcePosition = this.lineToColumn.get(line)?.get(column); let sourcePosition = this.lineToColumn.get(line)?.get(column);
if (sourcePosition === undefined) { if (sourcePosition === undefined) {
......
...@@ -100,7 +100,17 @@ class DOM { ...@@ -100,7 +100,17 @@ class DOM {
} }
return node; return node;
} }
static span(classes) {
const node = document.createElement('span');
if (classes !== undefined) {
if (typeof classes === 'string') {
node.className = classes;
} else {
classes.forEach(cls => node.classList.add(cls));
}
}
return node;
}
static table(className) { static table(className) {
const node = document.createElement('table'); const node = document.createElement('table');
if (className) node.className = className; if (className) node.className = className;
......
...@@ -6,24 +6,26 @@ found in the LICENSE file. --> ...@@ -6,24 +6,26 @@ found in the LICENSE file. -->
<link href="./index.css" rel="stylesheet"> <link href="./index.css" rel="stylesheet">
</head> </head>
<style> <style>
pre.scriptNode { .scriptNode {
white-space: pre-wrap; font-family: Consolas, monospace;
} }
pre.scriptNode:before { .scriptNode:before {
counter-reset: sourceLineCounter; counter-reset: sourceLineCounter;
} }
pre.scriptNode span { .scriptNode span {
counter-increment: sourceLineCounter; counter-increment: sourceLineCounter 1111;
text-indent: -3.5em;
padding-left: 3.5em;
display: block;
} }
pre.scriptNode span::before { .scriptNode span::before {
content: counter(sourceLineCounter) ": "; content: counter(sourceLineCounter) ": ";
width: 3.5em;
display: inline-block; display: inline-block;
width: 4em; white-space: pre;
padding-left: auto;
margin-left: auto;
text-align: right; text-align: right;
} }
...@@ -49,6 +51,6 @@ found in the LICENSE file. --> ...@@ -49,6 +51,6 @@ found in the LICENSE file. -->
<h2>Source Panel</h2> <h2>Source Panel</h2>
<select id="script-dropdown"></select> <select id="script-dropdown"></select>
<div id="script" class="panelBody"> <div id="script" class="panelBody">
<pre class="scripNode"></pre> <div class="scriptNode"></div>
</div> </div>
</div> </div>
...@@ -78,7 +78,7 @@ DOM.defineCustomElement('view/source-panel', ...@@ -78,7 +78,7 @@ DOM.defineCustomElement('view/source-panel',
scriptNode = builder.createScriptNode(); scriptNode = builder.createScriptNode();
this._sourcePositionsToMarkNodes = builder.sourcePositionToMarkers; this._sourcePositionsToMarkNodes = builder.sourcePositionToMarkers;
} else { } else {
scriptNode = document.createElement('pre'); scriptNode = DOM.div();
this._selectedMarkNodes = undefined; this._selectedMarkNodes = undefined;
} }
const oldScriptNode = this.script.childNodes[1]; const oldScriptNode = this.script.childNodes[1];
...@@ -212,8 +212,7 @@ class LineBuilder { ...@@ -212,8 +212,7 @@ class LineBuilder {
} }
createScriptNode() { createScriptNode() {
const scriptNode = document.createElement('pre'); const scriptNode = DOM.div('scriptNode');
scriptNode.classList.add('scriptNode');
for (let [lineIndex, line] of lineIterator(this._script.source)) { for (let [lineIndex, line] of lineIterator(this._script.source)) {
scriptNode.appendChild(this._createLineNode(lineIndex, line)); scriptNode.appendChild(this._createLineNode(lineIndex, line));
} }
...@@ -221,7 +220,7 @@ class LineBuilder { ...@@ -221,7 +220,7 @@ class LineBuilder {
} }
_createLineNode(lineIndex, line) { _createLineNode(lineIndex, line) {
const lineNode = document.createElement('span'); const lineNode = DOM.span();
let columnIndex = 0; let columnIndex = 0;
for (const sourcePosition of this._sourcePositions.forLine(lineIndex)) { for (const sourcePosition of this._sourcePositions.forLine(lineIndex)) {
const nextColumnIndex = sourcePosition.column - 1; const nextColumnIndex = sourcePosition.column - 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment