Merge pull request #14742 from Snuffleupagus/debugger-loops
Replace most loops in `web/debugger.js` with `for...of` loops
This commit is contained in:
commit
7c8a92da77
@ -49,8 +49,7 @@ var FontInspector = (function FontInspectorClosure() {
|
|||||||
}
|
}
|
||||||
const fontName = e.target.dataset.fontName;
|
const fontName = e.target.dataset.fontName;
|
||||||
const selects = document.getElementsByTagName("input");
|
const selects = document.getElementsByTagName("input");
|
||||||
for (let i = 0; i < selects.length; ++i) {
|
for (const select of selects) {
|
||||||
const select = selects[i];
|
|
||||||
if (select.dataset.fontName !== fontName) {
|
if (select.dataset.fontName !== fontName) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -65,7 +64,7 @@ var FontInspector = (function FontInspectorClosure() {
|
|||||||
name: "Font Inspector",
|
name: "Font Inspector",
|
||||||
panel: null,
|
panel: null,
|
||||||
manager: null,
|
manager: null,
|
||||||
init: function init(pdfjsLib) {
|
init(pdfjsLib) {
|
||||||
const panel = this.panel;
|
const panel = this.panel;
|
||||||
const tmp = document.createElement("button");
|
const tmp = document.createElement("button");
|
||||||
tmp.addEventListener("click", resetSelection);
|
tmp.addEventListener("click", resetSelection);
|
||||||
@ -75,7 +74,7 @@ var FontInspector = (function FontInspectorClosure() {
|
|||||||
fonts = document.createElement("div");
|
fonts = document.createElement("div");
|
||||||
panel.appendChild(fonts);
|
panel.appendChild(fonts);
|
||||||
},
|
},
|
||||||
cleanup: function cleanup() {
|
cleanup() {
|
||||||
fonts.textContent = "";
|
fonts.textContent = "";
|
||||||
},
|
},
|
||||||
enabled: false,
|
enabled: false,
|
||||||
@ -93,16 +92,16 @@ var FontInspector = (function FontInspectorClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
// FontInspector specific functions.
|
// FontInspector specific functions.
|
||||||
fontAdded: function fontAdded(fontObj, url) {
|
fontAdded(fontObj, url) {
|
||||||
function properties(obj, list) {
|
function properties(obj, list) {
|
||||||
const moreInfo = document.createElement("table");
|
const moreInfo = document.createElement("table");
|
||||||
for (let i = 0; i < list.length; i++) {
|
for (const entry of list) {
|
||||||
const tr = document.createElement("tr");
|
const tr = document.createElement("tr");
|
||||||
const td1 = document.createElement("td");
|
const td1 = document.createElement("td");
|
||||||
td1.textContent = list[i];
|
td1.textContent = entry;
|
||||||
tr.appendChild(td1);
|
tr.appendChild(td1);
|
||||||
const td2 = document.createElement("td");
|
const td2 = document.createElement("td");
|
||||||
td2.textContent = obj[list[i]].toString();
|
td2.textContent = obj[entry].toString();
|
||||||
tr.appendChild(td2);
|
tr.appendChild(td2);
|
||||||
moreInfo.appendChild(tr);
|
moreInfo.appendChild(tr);
|
||||||
}
|
}
|
||||||
@ -172,7 +171,7 @@ var StepperManager = (function StepperManagerClosure() {
|
|||||||
name: "Stepper",
|
name: "Stepper",
|
||||||
panel: null,
|
panel: null,
|
||||||
manager: null,
|
manager: null,
|
||||||
init: function init(pdfjsLib) {
|
init(pdfjsLib) {
|
||||||
const self = this;
|
const self = this;
|
||||||
stepperControls = document.createElement("div");
|
stepperControls = document.createElement("div");
|
||||||
stepperChooser = document.createElement("select");
|
stepperChooser = document.createElement("select");
|
||||||
@ -192,7 +191,7 @@ var StepperManager = (function StepperManagerClosure() {
|
|||||||
opMap[pdfjsLib.OPS[key]] = key;
|
opMap[pdfjsLib.OPS[key]] = key;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cleanup: function cleanup() {
|
cleanup() {
|
||||||
stepperChooser.textContent = "";
|
stepperChooser.textContent = "";
|
||||||
stepperDiv.textContent = "";
|
stepperDiv.textContent = "";
|
||||||
steppers = [];
|
steppers = [];
|
||||||
@ -200,7 +199,7 @@ var StepperManager = (function StepperManagerClosure() {
|
|||||||
enabled: false,
|
enabled: false,
|
||||||
active: false,
|
active: false,
|
||||||
// Stepper specific functions.
|
// Stepper specific functions.
|
||||||
create: function create(pageIndex) {
|
create(pageIndex) {
|
||||||
const debug = document.createElement("div");
|
const debug = document.createElement("div");
|
||||||
debug.id = "stepper" + pageIndex;
|
debug.id = "stepper" + pageIndex;
|
||||||
debug.hidden = true;
|
debug.hidden = true;
|
||||||
@ -218,23 +217,19 @@ var StepperManager = (function StepperManagerClosure() {
|
|||||||
}
|
}
|
||||||
return stepper;
|
return stepper;
|
||||||
},
|
},
|
||||||
selectStepper: function selectStepper(pageIndex, selectPanel) {
|
selectStepper(pageIndex, selectPanel) {
|
||||||
let i;
|
|
||||||
pageIndex |= 0;
|
pageIndex |= 0;
|
||||||
if (selectPanel) {
|
if (selectPanel) {
|
||||||
this.manager.selectPanel(this);
|
this.manager.selectPanel(this);
|
||||||
}
|
}
|
||||||
for (i = 0; i < steppers.length; ++i) {
|
for (const stepper of steppers) {
|
||||||
const stepper = steppers[i];
|
|
||||||
stepper.panel.hidden = stepper.pageIndex !== pageIndex;
|
stepper.panel.hidden = stepper.pageIndex !== pageIndex;
|
||||||
}
|
}
|
||||||
const options = stepperChooser.options;
|
for (const option of stepperChooser.options) {
|
||||||
for (i = 0; i < options.length; ++i) {
|
|
||||||
const option = options[i];
|
|
||||||
option.selected = (option.value | 0) === pageIndex;
|
option.selected = (option.value | 0) === pageIndex;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveBreakPoints: function saveBreakPoints(pageIndex, bps) {
|
saveBreakPoints(pageIndex, bps) {
|
||||||
breakPoints[pageIndex] = bps;
|
breakPoints[pageIndex] = bps;
|
||||||
sessionStorage.setItem("pdfjsBreakPoints", JSON.stringify(breakPoints));
|
sessionStorage.setItem("pdfjsBreakPoints", JSON.stringify(breakPoints));
|
||||||
},
|
},
|
||||||
@ -361,8 +356,7 @@ const Stepper = (function StepperClosure() {
|
|||||||
const charCodeRow = c("tr");
|
const charCodeRow = c("tr");
|
||||||
const fontCharRow = c("tr");
|
const fontCharRow = c("tr");
|
||||||
const unicodeRow = c("tr");
|
const unicodeRow = c("tr");
|
||||||
for (let j = 0; j < glyphs.length; j++) {
|
for (const glyph of glyphs) {
|
||||||
const glyph = glyphs[j];
|
|
||||||
if (typeof glyph === "object" && glyph !== null) {
|
if (typeof glyph === "object" && glyph !== null) {
|
||||||
charCodeRow.appendChild(c("td", glyph.originalCharCode));
|
charCodeRow.appendChild(c("td", glyph.originalCharCode));
|
||||||
fontCharRow.appendChild(c("td", glyph.fontChar));
|
fontCharRow.appendChild(c("td", glyph.fontChar));
|
||||||
@ -410,9 +404,9 @@ const Stepper = (function StepperClosure() {
|
|||||||
this.breakPoints.sort(function (a, b) {
|
this.breakPoints.sort(function (a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
});
|
});
|
||||||
for (let i = 0; i < this.breakPoints.length; i++) {
|
for (const breakPoint of this.breakPoints) {
|
||||||
if (this.breakPoints[i] > this.currentIdx) {
|
if (breakPoint > this.currentIdx) {
|
||||||
return this.breakPoints[i];
|
return breakPoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -444,8 +438,7 @@ const Stepper = (function StepperClosure() {
|
|||||||
|
|
||||||
goTo(idx) {
|
goTo(idx) {
|
||||||
const allRows = this.panel.getElementsByClassName("line");
|
const allRows = this.panel.getElementsByClassName("line");
|
||||||
for (let x = 0, xx = allRows.length; x < xx; ++x) {
|
for (const row of allRows) {
|
||||||
const row = allRows[x];
|
|
||||||
if ((row.dataset.idx | 0) === idx) {
|
if ((row.dataset.idx | 0) === idx) {
|
||||||
row.style.backgroundColor = "rgb(251,250,207)";
|
row.style.backgroundColor = "rgb(251,250,207)";
|
||||||
row.scrollIntoView();
|
row.scrollIntoView();
|
||||||
@ -465,8 +458,8 @@ var Stats = (function Stats() {
|
|||||||
node.textContent = ""; // Remove any `node` contents from the DOM.
|
node.textContent = ""; // Remove any `node` contents from the DOM.
|
||||||
}
|
}
|
||||||
function getStatIndex(pageNumber) {
|
function getStatIndex(pageNumber) {
|
||||||
for (let i = 0, ii = stats.length; i < ii; ++i) {
|
for (const [i, stat] of stats.entries()) {
|
||||||
if (stats[i].pageNumber === pageNumber) {
|
if (stat.pageNumber === pageNumber) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -505,8 +498,8 @@ var Stats = (function Stats() {
|
|||||||
return a.pageNumber - b.pageNumber;
|
return a.pageNumber - b.pageNumber;
|
||||||
});
|
});
|
||||||
clear(this.panel);
|
clear(this.panel);
|
||||||
for (let i = 0, ii = stats.length; i < ii; ++i) {
|
for (const entry of stats) {
|
||||||
this.panel.appendChild(stats[i].div);
|
this.panel.appendChild(entry.div);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cleanup() {
|
cleanup() {
|
||||||
@ -527,8 +520,7 @@ window.PDFBug = (function PDFBugClosure() {
|
|||||||
enable(ids) {
|
enable(ids) {
|
||||||
const all = ids.length === 1 && ids[0] === "all";
|
const all = ids.length === 1 && ids[0] === "all";
|
||||||
const tools = this.tools;
|
const tools = this.tools;
|
||||||
for (let i = 0; i < tools.length; ++i) {
|
for (const tool of tools) {
|
||||||
const tool = tools[i];
|
|
||||||
if (all || ids.includes(tool.id)) {
|
if (all || ids.includes(tool.id)) {
|
||||||
tool.enabled = true;
|
tool.enabled = true;
|
||||||
}
|
}
|
||||||
@ -570,22 +562,14 @@ window.PDFBug = (function PDFBugClosure() {
|
|||||||
container.style.right = panelWidth + "px";
|
container.style.right = panelWidth + "px";
|
||||||
|
|
||||||
// Initialize all the debugging tools.
|
// Initialize all the debugging tools.
|
||||||
const tools = this.tools;
|
for (const [i, tool] of this.tools.entries()) {
|
||||||
const self = this;
|
|
||||||
for (let i = 0; i < tools.length; ++i) {
|
|
||||||
const tool = tools[i];
|
|
||||||
const panel = document.createElement("div");
|
const panel = document.createElement("div");
|
||||||
const panelButton = document.createElement("button");
|
const panelButton = document.createElement("button");
|
||||||
panelButton.textContent = tool.name;
|
panelButton.textContent = tool.name;
|
||||||
panelButton.addEventListener(
|
panelButton.addEventListener("click", event => {
|
||||||
"click",
|
event.preventDefault();
|
||||||
(function (selected) {
|
this.selectPanel(i);
|
||||||
return function (event) {
|
});
|
||||||
event.preventDefault();
|
|
||||||
self.selectPanel(selected);
|
|
||||||
};
|
|
||||||
})(i)
|
|
||||||
);
|
|
||||||
controls.appendChild(panelButton);
|
controls.appendChild(panelButton);
|
||||||
panels.appendChild(panel);
|
panels.appendChild(panel);
|
||||||
tool.panel = panel;
|
tool.panel = panel;
|
||||||
@ -602,9 +586,9 @@ window.PDFBug = (function PDFBugClosure() {
|
|||||||
this.selectPanel(0);
|
this.selectPanel(0);
|
||||||
},
|
},
|
||||||
cleanup() {
|
cleanup() {
|
||||||
for (let i = 0, ii = this.tools.length; i < ii; i++) {
|
for (const tool of this.tools) {
|
||||||
if (this.tools[i].enabled) {
|
if (tool.enabled) {
|
||||||
this.tools[i].cleanup();
|
tool.cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -616,12 +600,11 @@ window.PDFBug = (function PDFBugClosure() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
activePanel = index;
|
activePanel = index;
|
||||||
const tools = this.tools;
|
for (const [j, tool] of this.tools.entries()) {
|
||||||
for (let j = 0; j < tools.length; ++j) {
|
|
||||||
const isActive = j === index;
|
const isActive = j === index;
|
||||||
buttons[j].classList.toggle("active", isActive);
|
buttons[j].classList.toggle("active", isActive);
|
||||||
tools[j].active = isActive;
|
tool.active = isActive;
|
||||||
tools[j].panel.hidden = !isActive;
|
tool.panel.hidden = !isActive;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user