Commit 400b6e7f authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[tools] Modernize tools .mjs files

This is mostly an auto-conversion done by several tools.

- use let / const
- use arrow functions
- use template strings

There are some additional manual rewrite required to modernize the
code further.

Change-Id: I63a7a43b05b14b33ad9941350d3d5f26aab10ba0
Bug: v8:10667
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2519564Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71080}
parent 4beadfde
......@@ -27,37 +27,37 @@ export class BaseArgumentsProcessor {
'Default log file name is "' +
this.result_.logFileName + '".\n');
print('Options:');
for (var arg in this.argsDispatch_) {
var synonyms = [arg];
var dispatch = this.argsDispatch_[arg];
for (var synArg in this.argsDispatch_) {
for (const arg in this.argsDispatch_) {
const synonyms = [arg];
const dispatch = this.argsDispatch_[arg];
for (const synArg in this.argsDispatch_) {
if (arg !== synArg && dispatch === this.argsDispatch_[synArg]) {
synonyms.push(synArg);
delete this.argsDispatch_[synArg];
}
}
print(' ' + synonyms.join(', ').padEnd(20) + " " + dispatch[2]);
print(` ${synonyms.join(', ').padEnd(20)} ${dispatch[2]}`);
}
quit(2);
}
parse() {
while (this.args_.length) {
var arg = this.args_.shift();
let arg = this.args_.shift();
if (arg.charAt(0) != '-') {
this.result_.logFileName = arg;
continue;
}
var userValue = null;
var eqPos = arg.indexOf('=');
let userValue = null;
const eqPos = arg.indexOf('=');
if (eqPos != -1) {
userValue = arg.substr(eqPos + 1);
arg = arg.substr(0, eqPos);
}
if (arg in this.argsDispatch_) {
var dispatch = this.argsDispatch_[arg];
var property = dispatch[0];
var defaultValue = dispatch[1];
const dispatch = this.argsDispatch_[arg];
const property = dispatch[0];
const defaultValue = dispatch[1];
if (typeof defaultValue == "function") {
userValue = defaultValue(userValue);
} else if (userValue == null) {
......
......@@ -90,7 +90,7 @@ export class CodeMap {
* @param {number} to The destination address.
*/
moveCode(from, to) {
var removedNode = this.dynamics_.remove(from);
const removedNode = this.dynamics_.remove(from);
this.deleteAllCoveredNodes_(this.dynamics_, to, to + removedNode.value.size);
this.dynamics_.insert(to, removedNode.value);
}
......@@ -102,7 +102,7 @@ export class CodeMap {
* @param {number} start The starting address of the entry being deleted.
*/
deleteCode(start) {
var removedNode = this.dynamics_.remove(start);
const removedNode = this.dynamics_.remove(start);
}
/**
......@@ -130,7 +130,7 @@ export class CodeMap {
* @private
*/
markPages_(start, end) {
for (var addr = start; addr <= end;
for (let addr = start; addr <= end;
addr += CodeMap.PAGE_SIZE) {
this.pages_[(addr / CodeMap.PAGE_SIZE)|0] = 1;
}
......@@ -140,16 +140,16 @@ export class CodeMap {
* @private
*/
deleteAllCoveredNodes_(tree, start, end) {
var to_delete = [];
var addr = end - 1;
const to_delete = [];
let addr = end - 1;
while (addr >= start) {
var node = tree.findGreatestLessThan(addr);
const node = tree.findGreatestLessThan(addr);
if (!node) break;
var start2 = node.key, end2 = start2 + node.value.size;
const start2 = node.key, end2 = start2 + node.value.size;
if (start2 < end && start < end2) to_delete.push(start2);
addr = start2 - 1;
}
for (var i = 0, l = to_delete.length; i < l; ++i) tree.remove(to_delete[i]);
for (let i = 0, l = to_delete.length; i < l; ++i) tree.remove(to_delete[i]);
}
/**
......@@ -163,7 +163,7 @@ export class CodeMap {
* @private
*/
findInTree_(tree, addr) {
var node = tree.findGreatestLessThan(addr);
const node = tree.findGreatestLessThan(addr);
return node && this.isAddressBelongsTo_(addr, node) ? node : null;
}
......@@ -175,29 +175,29 @@ export class CodeMap {
* @param {number} addr Address.
*/
findAddress(addr) {
var pageAddr = (addr / CodeMap.PAGE_SIZE)|0;
const pageAddr = (addr / CodeMap.PAGE_SIZE)|0;
if (pageAddr in this.pages_) {
// Static code entries can contain "holes" of unnamed code.
// In this case, the whole library is assigned to this address.
var result = this.findInTree_(this.statics_, addr);
let result = this.findInTree_(this.statics_, addr);
if (!result) {
result = this.findInTree_(this.libraries_, addr);
if (!result) return null;
}
return { entry : result.value, offset : addr - result.key };
}
var min = this.dynamics_.findMin();
var max = this.dynamics_.findMax();
const min = this.dynamics_.findMin();
const max = this.dynamics_.findMax();
if (max != null && addr < (max.key + max.value.size) && addr >= min.key) {
var dynaEntry = this.findInTree_(this.dynamics_, addr);
const dynaEntry = this.findInTree_(this.dynamics_, addr);
if (dynaEntry == null) return null;
// Dedupe entry name.
var entry = dynaEntry.value;
const entry = dynaEntry.value;
if (!entry.nameUpdated_) {
entry.name = this.dynamicsNameGen_.getName(entry.name);
entry.nameUpdated_ = true;
}
return { entry : entry, offset : addr - dynaEntry.key };
return { entry, offset : addr - dynaEntry.key };
}
return null;
}
......@@ -209,7 +209,7 @@ export class CodeMap {
* @param {number} addr Address.
*/
findEntry(addr) {
var result = this.findAddress(addr);
const result = this.findAddress(addr);
return result ? result.entry : null;
}
......@@ -219,7 +219,7 @@ export class CodeMap {
* @param {number} addr Address.
*/
findDynamicEntryByStartAddress(addr) {
var node = this.dynamics_.find(addr);
const node = this.dynamics_.find(addr);
return node ? node.value : null;
}
......@@ -292,7 +292,7 @@ class NameGenerator {
this.knownNames_[name] = 0;
return name;
}
var count = ++this.knownNames_[name];
const count = ++this.knownNames_[name];
return name + ' {' + count + '}';
};
}
......@@ -72,7 +72,7 @@ ConsArray.prototype.atEnd = function() {
* Returns the current item, moves to the next one.
*/
ConsArray.prototype.next = function() {
var result = this.currCell_.data[this.currCellPos_++];
const result = this.currCell_.data[this.currCellPos_++];
if (this.currCellPos_ >= this.currCell_.data.length) {
this.currCell_ = this.currCell_.next;
this.currCellPos_ = 0;
......
......@@ -84,9 +84,9 @@ export class CsvParser {
* @param {string} line Input line.
*/
parseLine(line) {
var pos = 0;
var endPos = line.length;
var fields = [];
let pos = 0;
const endPos = line.length;
const fields = [];
if (endPos == 0) return fields;
let nextPos = 0;
while(nextPos !== -1) {
......
......@@ -11,7 +11,7 @@ import {
// Dump C++ symbols of shared library if possible
function processArguments(args) {
var processor = new ArgumentsProcessor(args);
const processor = new ArgumentsProcessor(args);
if (processor.parse()) {
return processor.result();
} else {
......@@ -25,26 +25,26 @@ function initSourceMapSupport() {
// Overwrite the load function to load scripts synchronously.
SourceMap.load = function(sourceMapURL) {
var content = readFile(sourceMapURL);
var sourceMapObject = (JSON.parse(content));
const content = readFile(sourceMapURL);
const sourceMapObject = (JSON.parse(content));
return new SourceMap(sourceMapURL, sourceMapObject);
};
}
var entriesProviders = {
const entriesProviders = {
'unix': UnixCppEntriesProvider,
'windows': WindowsCppEntriesProvider,
'mac': MacCppEntriesProvider
};
var params = processArguments(arguments);
var sourceMap = null;
const params = processArguments(arguments);
let sourceMap = null;
if (params.sourceMap) {
initSourceMapSupport();
sourceMap = SourceMap.load(params.sourceMap);
}
var cppProcessor = new CppProcessor(
const cppProcessor = new CppProcessor(
new (entriesProviders[params.platform])(params.nm, params.targetRootFS,
params.apkEmbeddedLibrary),
params.timedRange, params.pairwiseTimedRange);
......
......@@ -33,7 +33,7 @@ export class CppProcessor extends LogReader {
processLogFile(fileName) {
this.lastLogFileName_ = fileName;
var line;
let line;
while (line = readline()) {
this.processLogLine(line);
}
......@@ -42,26 +42,26 @@ export class CppProcessor extends LogReader {
processLogFileInTest(fileName) {
// Hack file name to avoid dealing with platform specifics.
this.lastLogFileName_ = 'v8.log';
var contents = readFile(fileName);
const contents = readFile(fileName);
this.processLogChunk(contents);
};
processSharedLibrary(name, startAddr, endAddr, aslrSlide) {
var self = this;
var libFuncs = this.cppEntriesProvider_.parseVmSymbols(
const self = this;
const libFuncs = this.cppEntriesProvider_.parseVmSymbols(
name, startAddr, endAddr, aslrSlide, function(fName, fStart, fEnd) {
var entry = new CodeEntry(fEnd - fStart, fName, 'CPP');
const entry = new CodeEntry(fEnd - fStart, fName, 'CPP');
self.codeMap_.addStaticCode(fStart, entry);
});
};
dumpCppSymbols() {
var staticEntries = this.codeMap_.getAllStaticEntriesWithAddresses();
var total = staticEntries.length;
for (var i = 0; i < total; ++i) {
var entry = staticEntries[i];
var printValues = ['cpp', '0x' + entry[0].toString(16), entry[1].size,
'"' + entry[1].name + '"'];
const staticEntries = this.codeMap_.getAllStaticEntriesWithAddresses();
const total = staticEntries.length;
for (let i = 0; i < total; ++i) {
const entry = staticEntries[i];
const printValues = ['cpp', `0x${entry[0].toString(16)}`, entry[1].size,
`"${entry[1].name}"`];
print(printValues.join(','));
}
}
......
......@@ -7,7 +7,7 @@ import { WebInspector } from "./sourcemap.mjs";
import { BaseArgumentsProcessor } from "./arguments.mjs";
function processArguments(args) {
var processor = new ArgumentsProcessor(args);
const processor = new ArgumentsProcessor(args);
if (processor.parse()) {
return processor.result();
} else {
......@@ -33,8 +33,8 @@ function initSourceMapSupport() {
// Overwrite the load function to load scripts synchronously.
SourceMap.load = function(sourceMapURL) {
var content = readFile(sourceMapURL);
var sourceMapObject = (JSON.parse(content));
const content = readFile(sourceMapURL);
const sourceMapObject = (JSON.parse(content));
return new SourceMap(sourceMapURL, sourceMapObject);
};
}
......@@ -82,7 +82,7 @@ for (const ic of processor.icTimeline.all) {
ic.type + ' (' + ic.oldState + '->' + ic.newState + ic.modifier + ') at ' +
ic.filePosition + ' ' + ic.key +
' (map 0x' + ic.map.toString(16) + ')' +
(ic.reason ? ' ' + ic.reason : '') + ' time: ' + ic.time);
(ic.reason ? ` ${ic.reason}` : '') + ' time: ' + ic.time);
accumulator[ic.type]++;
}
......
......@@ -146,11 +146,11 @@ LogReader.prototype.processLogLine = function(line) {
* @return {Array.<number>} Processed stack.
*/
LogReader.prototype.processStack = function(pc, func, stack) {
var fullStack = func ? [pc, func] : [pc];
var prevFrame = pc;
for (var i = 0, n = stack.length; i < n; ++i) {
var frame = stack[i];
var firstChar = frame.charAt(0);
const fullStack = func ? [pc, func] : [pc];
let prevFrame = pc;
for (let i = 0, n = stack.length; i < n; ++i) {
const frame = stack[i];
const firstChar = frame.charAt(0);
if (firstChar == '+' || firstChar == '-') {
// An offset from the previous frame.
prevFrame += parseInt(frame, 16);
......@@ -159,7 +159,7 @@ LogReader.prototype.processStack = function(pc, func, stack) {
} else if (firstChar != 'o') {
fullStack.push(parseInt(frame, 16));
} else {
this.printError("dropping: " + frame);
this.printError(`dropping: ${frame}`);
}
}
return fullStack;
......@@ -172,9 +172,7 @@ LogReader.prototype.processStack = function(pc, func, stack) {
* @param {!Object} dispatch Dispatch record.
* @return {boolean} True if dispatch must be skipped.
*/
LogReader.prototype.skipDispatch = function(dispatch) {
return false;
};
LogReader.prototype.skipDispatch = dispatch => false;
// Parses dummy variable for readability;
export const parseString = 'parse-string';
......@@ -188,17 +186,17 @@ export const parseVarArgs = 'parse-var-args';
*/
LogReader.prototype.dispatchLogRow_ = function(fields) {
// Obtain the dispatch.
var command = fields[0];
var dispatch = this.dispatchTable_[command];
const command = fields[0];
const dispatch = this.dispatchTable_[command];
if (dispatch === undefined) return;
if (dispatch === null || this.skipDispatch(dispatch)) {
return;
}
// Parse fields.
var parsedFields = [];
for (var i = 0; i < dispatch.parsers.length; ++i) {
var parser = dispatch.parsers[i];
const parsedFields = [];
for (let i = 0; i < dispatch.parsers.length; ++i) {
const parser = dispatch.parsers[i];
if (parser === parseString) {
parsedFields.push(fields[1 + i]);
} else if (typeof parser == 'function') {
......@@ -208,7 +206,7 @@ LogReader.prototype.dispatchLogRow_ = function(fields) {
parsedFields.push(fields.slice(1 + i));
break;
} else {
throw new Error("Invalid log field parser: " + parser);
throw new Error(`Invalid log field parser: ${parser}`);
}
}
......@@ -224,7 +222,7 @@ LogReader.prototype.dispatchLogRow_ = function(fields) {
* @private
*/
LogReader.prototype.processLog_ = function(lines) {
for (var i = 0, n = lines.length; i < n; ++i) {
for (let i = 0, n = lines.length; i < n; ++i) {
this.processLogLine_(lines[i]);
}
}
......@@ -238,10 +236,10 @@ LogReader.prototype.processLog_ = function(lines) {
LogReader.prototype.processLogLine_ = function(line) {
if (line.length > 0) {
try {
var fields = this.csvParser_.parseLine(line);
const fields = this.csvParser_.parseLine(line);
this.dispatchLogRow_(fields);
} catch (e) {
this.printError('line ' + (this.lineNum_ + 1) + ': ' + (e.message || e) + '\n' + e.stack);
this.printError(`line ${this.lineNum_ + 1}: ${e.message || e}\n${e.stack}`);
}
}
this.lineNum_++;
......
......@@ -8,7 +8,7 @@ import {
} from "./parse-processor.mjs";
function processArguments(args) {
var processor = new ArgumentsProcessor(args);
const processor = new ArgumentsProcessor(args);
if (processor.parse()) {
return processor.result();
} else {
......@@ -22,17 +22,17 @@ function initSourceMapSupport() {
// Overwrite the load function to load scripts synchronously.
SourceMap.load = function(sourceMapURL) {
var content = readFile(sourceMapURL);
var sourceMapObject = (JSON.parse(content));
const content = readFile(sourceMapURL);
const sourceMapObject = (JSON.parse(content));
return new SourceMap(sourceMapURL, sourceMapObject);
};
}
var params = processArguments(arguments);
var sourceMap = null;
const params = processArguments(arguments);
let sourceMap = null;
if (params.sourceMap) {
initSourceMapSupport();
sourceMap = SourceMap.load(params.sourceMap);
}
var parseProcessor = new ParseProcessor();
const parseProcessor = new ParseProcessor();
parseProcessor.processLogFile(params.logFileName);
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
import { LogReader, parseString } from "./logreader.mjs";
import { BaseArgumentsProcessor } from "./arguments.mjs";
......@@ -339,7 +337,7 @@ class Script extends CompilationUnit {
calculateMetrics(printSummary) {
let log = (str) => this.summary += str + '\n';
log("SCRIPT: " + this.id);
log(`SCRIPT: ${this.id}`);
let all = this.funktions;
if (all.length === 0) return;
......@@ -354,7 +352,7 @@ class Script extends CompilationUnit {
let value = (funktions.length + "").padStart(6) +
(nofPercent + "%").padStart(5) +
BYTES(ownBytes, this.bytesTotal).padStart(10);
log((" - " + name).padEnd(20) + value);
log((` - ${name}`).padEnd(20) + value);
this.metrics.set(name + "-bytes", ownBytes);
this.metrics.set(name + "-count", funktions.length);
this.metrics.set(name + "-count-percent", nofPercent);
......@@ -362,7 +360,7 @@ class Script extends CompilationUnit {
Math.round(ownBytes / this.bytesTotal * 100));
};
log(" - file: " + this.file);
log(` - file: ${this.file}`);
log(' - details: ' +
'isEval=' + this.isEval + ' deserialized=' + this.isDeserialized +
' streamed=' + this.isStreamingCompiled);
......@@ -409,7 +407,7 @@ class Script extends CompilationUnit {
// [start+delta*2, acc(metric0, start, start+delta*2), ...],
// ...
// ]
if (end <= start) throw 'Invalid ranges [' + start + ',' + end + ']';
if (end <= start) throw `Invalid ranges [${start},${end}]`;
const timespan = end - start;
const kSteps = Math.ceil(timespan / delta);
// To reduce the time spent iterating over the funktions of this script
......@@ -607,8 +605,8 @@ class ExecutionCost {
}
toString() {
return (' - ' + this.prefix + '-time:').padEnd(24) +
(" executed=" + formatNumber(this.executedCost) + 'ms').padEnd(20) +
return (` - ${this.prefix}-time:`).padEnd(24) +
(` executed=${formatNumber(this.executedCost)}ms`).padEnd(20) +
" non-executed=" + formatNumber(this.nonExecutedCost) + 'ms';
}
......@@ -623,11 +621,11 @@ class ExecutionCost {
class Funktion extends CompilationUnit {
constructor(name, start, end, script) {
super();
if (start < 0) throw "invalid start position: " + start;
if (start < 0) throw `invalid start position: ${start}`;
if (script.isEval) {
if (end < start) throw 'invalid start end positions';
} else {
if (end <= 0) throw 'invalid end position: ' + end;
if (end <= 0) throw `invalid end position: ${end}`;
if (end <= start) throw 'invalid start end positions';
}
......@@ -722,7 +720,7 @@ class Funktion extends CompilationUnit {
}
toString(details = true) {
let result = 'function' + (this.name ? ' ' + this.name : '') +
let result = `function${this.name ? ` ${this.name}` : ''}` +
`() range=${this.start}-${this.end}`;
if (details) result += ` script=${this.script ? this.script.id : 'X'}`;
return result;
......@@ -841,7 +839,7 @@ export class ParseProcessor extends LogReader {
processLogFile(fileName) {
this.collectEntries = true
this.lastLogFileName_ = fileName;
var line;
let line;
while (line = readline()) {
this.processLogLine(line);
}
......@@ -886,7 +884,7 @@ export class ParseProcessor extends LogReader {
functionName) {
let handlerFn = this.functionEventDispatchTable_[eventName];
if (handlerFn === undefined) {
console.error('Couldn\'t find handler for function event:' + eventName);
console.error(`Couldn't find handler for function event:${eventName}`);
}
handlerFn(
scriptId, startPosition, endPosition, duration, timestamp,
......@@ -965,7 +963,7 @@ export class ParseProcessor extends LogReader {
script.preparseTimestamp = toTimestamp(timestamp);
return;
default:
console.error('Unhandled script event: ' + eventName);
console.error(`Unhandled script event: ${eventName}`);
}
}
......
This diff is collapsed.
......@@ -47,12 +47,12 @@ export function ViewBuilder(samplingRate) {
*/
ViewBuilder.prototype.buildView = function(
callTree, opt_bottomUpViewWeights) {
var head;
var samplingRate = this.samplingRate;
var createViewNode = this.createViewNode;
let head;
const samplingRate = this.samplingRate;
const createViewNode = this.createViewNode;
callTree.traverse(function(node, viewParent) {
var totalWeight = node.totalWeight * samplingRate;
var selfWeight = node.selfWeight * samplingRate;
const totalWeight = node.totalWeight * samplingRate;
let selfWeight = node.selfWeight * samplingRate;
if (opt_bottomUpViewWeights === true) {
if (viewParent === head) {
selfWeight = totalWeight;
......@@ -60,7 +60,7 @@ ViewBuilder.prototype.buildView = function(
selfWeight = 0;
}
}
var viewNode = createViewNode(node.label, totalWeight, selfWeight, head);
const viewNode = createViewNode(node.label, totalWeight, selfWeight, head);
if (viewParent) {
viewParent.addChild(viewNode);
} else {
......@@ -68,7 +68,7 @@ ViewBuilder.prototype.buildView = function(
}
return viewNode;
});
var view = this.createView(head);
const view = this.createView(head);
return view;
};
......@@ -79,9 +79,7 @@ ViewBuilder.prototype.buildView = function(
* @param {ProfileView.Node} head View head node.
* @return {ProfileView} Profile view.
*/
ViewBuilder.prototype.createView = function(head) {
return new ProfileView(head);
};
ViewBuilder.prototype.createView = head => new ProfileView(head);
/**
......@@ -96,11 +94,11 @@ ViewBuilder.prototype.createView = function(head) {
* @param {ProfileView.Node} head Profile view head.
* @return {ProfileView.Node} Profile view node.
*/
ViewBuilder.prototype.createViewNode = function(
funcName, totalTime, selfTime, head) {
return new ProfileView.Node(
funcName, totalTime, selfTime, head);
};
ViewBuilder.prototype.createViewNode = (
funcName, totalTime, selfTime, head) =>
new ProfileView.Node(
funcName, totalTime, selfTime, head)
;
/**
......@@ -135,10 +133,10 @@ ProfileView.prototype.sort = function(sortFunc) {
* @param {function(ProfileView.Node)} f Visitor function.
*/
ProfileView.prototype.traverse = function(f) {
var nodesToTraverse = new ConsArray();
const nodesToTraverse = new ConsArray();
nodesToTraverse.concat([this.head]);
while (!nodesToTraverse.atEnd()) {
var node = nodesToTraverse.next();
const node = nodesToTraverse.next();
f(node);
nodesToTraverse.concat(node.children);
}
......
This diff is collapsed.
......@@ -75,7 +75,7 @@ SplayTree.prototype.insert = function(key, value) {
if (this.root_.key == key) {
return;
}
var node = new SplayTree.Node(key, value);
const node = new SplayTree.Node(key, value);
if (key > this.root_.key) {
node.left = this.root_;
node.right = this.root_.right;
......@@ -99,17 +99,17 @@ SplayTree.prototype.insert = function(key, value) {
*/
SplayTree.prototype.remove = function(key) {
if (this.isEmpty()) {
throw Error('Key not found: ' + key);
throw Error(`Key not found: ${key}`);
}
this.splay_(key);
if (this.root_.key != key) {
throw Error('Key not found: ' + key);
throw Error(`Key not found: ${key}`);
}
var removed = this.root_;
const removed = this.root_;
if (!this.root_.left) {
this.root_ = this.root_.right;
} else {
var right = this.root_.right;
const { right } = this.root_;
this.root_ = this.root_.left;
// Splay to make sure that the new root has an empty right child.
this.splay_(key);
......@@ -144,7 +144,7 @@ SplayTree.prototype.findMin = function() {
if (this.isEmpty()) {
return null;
}
var current = this.root_;
let current = this.root_;
while (current.left) {
current = current.left;
}
......@@ -159,7 +159,7 @@ SplayTree.prototype.findMax = function(opt_startNode) {
if (this.isEmpty()) {
return null;
}
var current = opt_startNode || this.root_;
let current = opt_startNode || this.root_;
while (current.right) {
current = current.right;
}
......@@ -195,7 +195,7 @@ SplayTree.prototype.findGreatestLessThan = function(key) {
* with keys.
*/
SplayTree.prototype.exportKeysAndValues = function() {
var result = [];
const result = [];
this.traverse_(function(node) { result.push([node.key, node.value]); });
return result;
};
......@@ -205,7 +205,7 @@ SplayTree.prototype.exportKeysAndValues = function() {
* @return {Array<*>} An array containing all the values of tree's nodes.
*/
SplayTree.prototype.exportValues = function() {
var result = [];
const result = [];
this.traverse_(function(node) { result.push(node.value); });
return result;
};
......@@ -230,9 +230,9 @@ SplayTree.prototype.splay_ = function(key) {
// the L tree of the algorithm. The left child of the dummy node
// will hold the R tree of the algorithm. Using a dummy node, left
// and right will always be nodes and we avoid special cases.
var dummy, left, right;
let dummy, left, right;
dummy = left = right = new SplayTree.Node(null, null);
var current = this.root_;
let current = this.root_;
while (true) {
if (key < current.key) {
if (!current.left) {
......@@ -240,7 +240,7 @@ SplayTree.prototype.splay_ = function(key) {
}
if (key < current.left.key) {
// Rotate right.
var tmp = current.left;
const tmp = current.left;
current.left = tmp.right;
tmp.right = current;
current = tmp;
......@@ -258,7 +258,7 @@ SplayTree.prototype.splay_ = function(key) {
}
if (key > current.right.key) {
// Rotate left.
var tmp = current.right;
const tmp = current.right;
current.right = tmp.left;
tmp.left = current;
current = tmp;
......@@ -290,9 +290,9 @@ SplayTree.prototype.splay_ = function(key) {
* @private
*/
SplayTree.prototype.traverse_ = function(f) {
var nodesToVisit = [this.root_];
const nodesToVisit = [this.root_];
while (nodesToVisit.length > 0) {
var node = nodesToVisit.shift();
const node = nodesToVisit.shift();
if (node == null) {
continue;
}
......
......@@ -55,16 +55,15 @@ DOM.defineCustomElement(
}
updateCount() {
this.count.innerHTML = 'length=' + this._selectedLogEntries.length;
this.count.innerHTML = `length=${this._selectedLogEntries.length}`;
}
updateTable(event) {
let select = this.groupKey;
let key = select.options[select.selectedIndex].text;
let tableBody = this.tableBody;
DOM.removeAllChildren(tableBody);
DOM.removeAllChildren(this.tableBody);
let groups = Group.groupBy(this._selectedLogEntries, key, true);
this.render(groups, tableBody);
this.render(groups, this.tableBody);
}
escapeHtml(unsafe) {
......@@ -89,8 +88,7 @@ DOM.defineCustomElement(
// searches for mapLogEntries using the id, time
const selectedMapLogEntriesSet = new Set();
for (const icLogEntry of icLogEntries) {
const time = icLogEntry.time;
const selectedMap = MapLogEntry.get(id, time);
const selectedMap = MapLogEntry.get(id, icLogEntry.time);
selectedMapLogEntriesSet.add(selectedMap);
}
return Array.from(selectedMapLogEntriesSet);
......@@ -131,8 +129,7 @@ DOM.defineCustomElement(
const omitted = groups.length - max;
if (omitted > 0) {
const tr = DOM.tr();
const tdNode =
tr.appendChild(DOM.td('Omitted ' + omitted + ' entries.'));
const tdNode = tr.appendChild(DOM.td(`Omitted ${omitted} entries.`));
tdNode.colSpan = 4;
fragment.appendChild(tr);
}
......
......@@ -38,7 +38,7 @@ DOM.defineCustomElement('log-file-reader',
event.preventDefault();
this.dispatchEvent(
new CustomEvent('fileuploadstart', {bubbles: true, composed: true}));
var host = event.dataTransfer ? event.dataTransfer : event.target;
const host = event.dataTransfer ? event.dataTransfer : event.target;
this.readFile(host.files[0]);
}
......@@ -73,7 +73,7 @@ DOM.defineCustomElement('log-file-reader',
handleFileLoad(e, file) {
const chunk = e.target.result;
this.updateLabel('Finished loading \'' + file.name + '\'.');
this.updateLabel(`Finished loading '${file.name}'.`);
this.dispatchEvent(new CustomEvent('fileuploadend', {
bubbles: true,
composed: true,
......
......@@ -184,9 +184,9 @@ class Edge {
}
finishSetup() {
let from = this.from;
const from = this.from;
if (from) from.addEdge(this);
let to = this.to;
const to = this.to;
if (to === undefined) return;
to.edge = this;
if (from === undefined) return;
......
......@@ -29,9 +29,9 @@ DOM.defineCustomElement(
let details = '';
let clickableDetails = '';
if (map) {
clickableDetails += 'ID: ' + map.id;
clickableDetails += '\nSource location: ' + map.filePosition;
details += '\n' + map.description;
clickableDetails += `ID: ${map.id}`;
clickableDetails += `\nSource location: ${map.filePosition}`;
details += `\n${map.description}`;
this.setSelectedMap(map);
}
this._filePositionNode.innerText = clickableDetails;
......
......@@ -39,7 +39,7 @@ DOM.defineCustomElement('./map-panel/map-transitions',
handleTransitionViewChange(e) {
this.tooltip.style.left = e.pageX + 'px';
this.tooltip.style.top = e.pageY + 'px';
let map = e.target.map;
const map = e.target.map;
if (map) {
this.tooltipContents.innerText = map.description;
}
......
......@@ -125,7 +125,7 @@ export class Processor extends LogReader {
this.processLogLine(line);
}
} catch (e) {
console.error('Error occurred during parsing, trying to continue: ' + e);
console.error(`Error occurred during parsing, trying to continue: ${e}`);
}
this.finalize();
}
......@@ -142,7 +142,7 @@ export class Processor extends LogReader {
}
} catch (e) {
console.error(
'Error occurred during parsing line ' + i +
`Error occurred during parsing line ${i}` +
', trying to continue: ' + e);
}
this.finalize();
......@@ -155,8 +155,8 @@ export class Processor extends LogReader {
this._mapTimeline.forEach(map => {
if (map.isRoot()) id = map.finalizeRootMap(id + 1);
if (map.edge && map.edge.name) {
let edge = map.edge;
let list = this._mapTimeline.transitions.get(edge.name);
const edge = map.edge;
const list = this._mapTimeline.transitions.get(edge.name);
if (list === undefined) {
this._mapTimeline.transitions.set(edge.name, [edge]);
} else {
......@@ -178,13 +178,13 @@ export class Processor extends LogReader {
case '*':
return Profile.CodeState.OPTIMIZED;
}
throw new Error('unknown code state: ' + s);
throw new Error(`unknown code state: ${s}`);
}
processCodeCreation(type, kind, timestamp, start, size, name, maybe_func) {
if (maybe_func.length) {
let funcAddr = parseInt(maybe_func[0]);
let state = this.parseState(maybe_func[1]);
const funcAddr = parseInt(maybe_func[0]);
const state = this.parseState(maybe_func[1]);
this._profile.addFuncCode(
type, name, timestamp, start, size, funcAddr, state);
} else {
......@@ -324,7 +324,7 @@ export class Processor extends LogReader {
if (id === '0x000000000000') return undefined;
let map = MapLogEntry.get(id, time);
if (map === undefined) {
console.error('No map details provided: id=' + id);
console.error(`No map details provided: id=${id}`);
// Manually patch in a map to continue running.
return this.createMapEntry(id, time);
};
......
......@@ -188,12 +188,11 @@ class LineBuilder {
this._selection = new Set(highlightPositions);
this._clickHandler = panel.handleSourcePositionClick.bind(panel);
// TODO: sort on script finalization.
script.sourcePositions
.sort((a, b) => {
if (a.line === b.line) return a.column - b.column;
return a.line - b.line;
}) this._sourcePositions =
new SourcePositionIterator(script.sourcePositions);
script.sourcePositions.sort((a, b) => {
if (a.line === b.line) return a.column - b.column;
return a.line - b.line;
});
this._sourcePositions = new SourcePositionIterator(script.sourcePositions);
}
get sourcePositionToMarkers() {
......
......@@ -220,7 +220,6 @@ DOM.defineCustomElement('./timeline/timeline-track',
}
renderLegend() {
let timelineLegend = this.timelineLegend;
let timelineLegendContent = this.timelineLegendContent;
DOM.removeAllChildren(timelineLegendContent);
this._timeline.uniqueTypes.forEach((entries, type) => {
......@@ -249,7 +248,7 @@ DOM.defineCustomElement('./timeline/timeline-track',
row.appendChild(DOM.td(this.data.all.length));
row.appendChild(DOM.td('100%'));
timelineLegendContent.appendChild(row);
timelineLegend.appendChild(timelineLegendContent);
this.timelineLegend.appendChild(timelineLegendContent);
}
handleEntryTypeDblClick(e) {
......@@ -306,7 +305,7 @@ DOM.defineCustomElement('./timeline/timeline-track',
}
let imageData = this.backgroundCanvas.toDataURL('image/webp', 0.2);
node.style.backgroundImage = 'url(' + imageData + ')';
node.style.backgroundImage = `url(${imageData})`;
}
updateTimeline() {
......
......@@ -34,7 +34,7 @@ import {
// Tick Processor's code flow.
function processArguments(args) {
var processor = new ArgumentsProcessor(args);
const processor = new ArgumentsProcessor(args);
if (processor.parse()) {
return processor.result();
} else {
......@@ -48,25 +48,25 @@ function initSourceMapSupport() {
// Overwrite the load function to load scripts synchronously.
SourceMap.load = function(sourceMapURL) {
var content = readFile(sourceMapURL);
var sourceMapObject = (JSON.parse(content));
const content = readFile(sourceMapURL);
const sourceMapObject = (JSON.parse(content));
return new SourceMap(sourceMapURL, sourceMapObject);
};
}
var entriesProviders = {
const entriesProviders = {
'unix': UnixCppEntriesProvider,
'windows': WindowsCppEntriesProvider,
'mac': MacCppEntriesProvider
};
var params = processArguments(arguments);
var sourceMap = null;
const params = processArguments(arguments);
let sourceMap = null;
if (params.sourceMap) {
initSourceMapSupport();
sourceMap = SourceMap.load(params.sourceMap);
}
var tickProcessor = new TickProcessor(
const tickProcessor = new TickProcessor(
new (entriesProviders[params.platform])(params.nm, params.objdump, params.targetRootFS,
params.apkEmbeddedLibrary),
params.separateIc,
......
This diff is collapsed.
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