From 779b46bac3bb2ca8aa997d683183eded1971fadc Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Wed, 13 Jan 2021 13:40:22 +0000 Subject: [PATCH] Inline and remove peekLast() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the future we can use `.at()`, but that has not been shipped yet. R=szuend@chromium.org Bug: 1050549 Change-Id: I89e760db277ffb91bfbba93106e6e11d3ece91d6 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2624711 Commit-Queue: Tim van der Lippe Reviewed-by: Simon Zünd Auto-Submit: Tim van der Lippe --- front_end/bindings/CompilerScriptMapping.js | 2 +- .../IsolatedFilesystemTestRunner.js | 2 +- front_end/console/ConsoleView.js | 10 +++++--- front_end/coverage/CoverageModel.js | 10 ++++---- front_end/elements/StylesSidebarPane.js | 4 +-- front_end/emulation/MediaQueryInspector.js | 2 +- .../FormattedContentBuilder.ts | 2 +- front_end/formatter_worker/HTMLFormatter.js | 14 +++++------ front_end/legacy/legacy-defs.d.ts | 1 - .../object_ui/RemoteObjectPreviewFormatter.js | 2 +- front_end/perf_ui/FlameChart.js | 19 ++++++++------ .../performance_monitor/PerformanceMonitor.js | 3 ++- .../TimelineTestRunner.js | 2 +- front_end/platform/utilities.js | 12 --------- front_end/profiler/HeapSnapshotDataGrids.js | 4 +-- front_end/profiler/HeapSnapshotView.js | 2 +- front_end/quick_open/FilteredListWidget.js | 4 +-- front_end/sdk/CPUProfileDataModel.js | 6 ++--- front_end/sdk/CSSMatchedStyles.js | 2 +- front_end/sdk/NetworkManager.js | 2 +- front_end/sdk/RuntimeModel.js | 3 ++- front_end/sdk/TracingModel.js | 4 +-- front_end/timeline/CountersGraph.js | 2 +- front_end/timeline/EventsTimelineTreeView.js | 2 +- front_end/timeline/TimelineController.js | 4 +-- front_end/timeline/TimelineEventOverview.js | 4 +-- .../TimelineFlameChartDataProvider.js | 13 +++++----- front_end/timeline/TimelineHistoryManager.js | 3 ++- front_end/timeline/TimelineUIUtils.js | 8 +++--- .../timeline_model/TimelineFrameModel.js | 2 +- front_end/timeline_model/TimelineJSProfile.js | 4 +-- front_end/timeline_model/TimelineModel.js | 25 ++++++++++--------- front_end/ui/ContextMenu.js | 2 +- front_end/ui/Toolbar.js | 2 +- 34 files changed, 90 insertions(+), 93 deletions(-) diff --git a/front_end/bindings/CompilerScriptMapping.js b/front_end/bindings/CompilerScriptMapping.js index 9a4330eea2..60931f52e1 100644 --- a/front_end/bindings/CompilerScriptMapping.js +++ b/front_end/bindings/CompilerScriptMapping.js @@ -367,7 +367,7 @@ class Binding { * @param {!Protocol.Page.FrameId} frameId */ _recreateUISourceCodeIfNeeded(frameId) { - const sourceMap = this._referringSourceMaps.peekLast(); + const sourceMap = this._referringSourceMaps[this._referringSourceMaps.length - 1]; if (!sourceMap || this._activeSourceMap === sourceMap) { return; } diff --git a/front_end/bindings_test_runner/IsolatedFilesystemTestRunner.js b/front_end/bindings_test_runner/IsolatedFilesystemTestRunner.js index 2f7cb03616..b0ec8dce80 100644 --- a/front_end/bindings_test_runner/IsolatedFilesystemTestRunner.js +++ b/front_end/bindings_test_runner/IsolatedFilesystemTestRunner.js @@ -73,7 +73,7 @@ BindingsTestRunner.TestFileSystem.prototype = { const pathTokens = path.split('/'); let node = this.root; const folders = pathTokens.slice(0, pathTokens.length - 1); - const fileName = pathTokens.peekLast(); + const fileName = pathTokens[pathTokens.length - 1]; for (const folder of folders) { let dir = node._children.get(folder); diff --git a/front_end/console/ConsoleView.js b/front_end/console/ConsoleView.js index 1c387edb5d..02572d7ff5 100644 --- a/front_end/console/ConsoleView.js +++ b/front_end/console/ConsoleView.js @@ -665,7 +665,7 @@ export class ConsoleView extends UI.Widget.VBox { const viewMessage = this._createViewMessage(message); consoleMessageToViewMessage.set(message, viewMessage); if (message.type === SDK.ConsoleModel.MessageType.Command || message.type === SDK.ConsoleModel.MessageType.Result) { - const lastMessage = this._consoleMessages.peekLast(); + const lastMessage = this._consoleMessages[this._consoleMessages.length - 1]; const newTimestamp = lastMessage && messagesSortedBySymbol.get(lastMessage) || 0; messagesSortedBySymbol.set(viewMessage, newTimestamp); } else { @@ -771,11 +771,12 @@ export class ConsoleView extends UI.Widget.VBox { return; } - if (!preventCollapse && this._tryToCollapseMessages(viewMessage, this._visibleViewMessages.peekLast())) { + if (!preventCollapse && + this._tryToCollapseMessages(viewMessage, this._visibleViewMessages[this._visibleViewMessages.length - 1])) { return; } - const lastMessage = this._visibleViewMessages.peekLast(); + const lastMessage = this._visibleViewMessages[this._visibleViewMessages.length - 1]; if (viewMessage.consoleMessage().type === SDK.ConsoleModel.MessageType.EndGroup) { if (lastMessage && !this._currentGroup.messagesHidden()) { lastMessage.incrementCloseGroupDecorationCount(); @@ -1069,7 +1070,8 @@ export class ConsoleView extends UI.Widget.VBox { this._appendMessageToEnd(startGroupViewMessage); for (const viewMessageInGroup of viewMessagesInGroup) { - viewMessageInGroup.setInSimilarGroup(true, viewMessagesInGroup.peekLast() === viewMessageInGroup); + viewMessageInGroup.setInSimilarGroup( + true, viewMessagesInGroup[viewMessagesInGroup.length - 1] === viewMessageInGroup); this._appendMessageToEnd(viewMessageInGroup, true); alreadyAdded.add(viewMessageInGroup.consoleMessage()); } diff --git a/front_end/coverage/CoverageModel.js b/front_end/coverage/CoverageModel.js index a4e40ee22e..fbe1d552b2 100644 --- a/front_end/coverage/CoverageModel.js +++ b/front_end/coverage/CoverageModel.js @@ -478,11 +478,11 @@ export class CoverageModel extends SDK.SDKModel.SDKModel { const result = []; const stack = []; for (const entry of ranges) { - let top = stack.peekLast(); + let top = stack[stack.length - 1]; while (top && top.endOffset <= entry.startOffset) { append(top.endOffset, top.count); stack.pop(); - top = stack.peekLast(); + top = stack[stack.length - 1]; } append(entry.startOffset, top ? top.count : 0); stack.push(entry); @@ -497,7 +497,7 @@ export class CoverageModel extends SDK.SDKModel.SDKModel { * @param {number} count */ function append(end, count) { - const last = result.peekLast(); + const last = result[result.length - 1]; if (last) { if (last.end === end) { return; @@ -548,7 +548,7 @@ export class CoverageModel extends SDK.SDKModel.SDKModel { const coverageInfo = urlCoverage._ensureEntry(contentProvider, contentLength, startLine, startColumn, type); this._coverageByContentProvider.set(contentProvider, coverageInfo); const segments = CoverageModel._convertToDisjointSegments(ranges, stamp); - const last = segments.peekLast(); + const last = segments[segments.length - 1]; if (last && last.end < contentLength) { segments.push({end: contentLength, stamp: stamp, count: 0}); } @@ -809,7 +809,7 @@ export const mergeSegments = (segmentsA, segmentsB) => { const b = segmentsB[indexB]; const count = (a.count || 0) + (b.count || 0); const end = Math.min(a.end, b.end); - const last = result.peekLast(); + const last = result[result.length - 1]; const stamp = Math.min(a.stamp, b.stamp); if (!last || last.count !== count || last.stamp !== stamp) { result.push({end: end, count: count, stamp: stamp}); diff --git a/front_end/elements/StylesSidebarPane.js b/front_end/elements/StylesSidebarPane.js index a50854f8d4..f5d6b20236 100644 --- a/front_end/elements/StylesSidebarPane.js +++ b/front_end/elements/StylesSidebarPane.js @@ -761,7 +761,7 @@ export class StylesSidebarPane extends ElementsSidebarPane { blocks.push(block); } - const lastBlock = blocks.peekLast(); + const lastBlock = blocks[blocks.length - 1]; if (lastBlock) { this._idleCallbackManager.schedule(() => { const section = new StylePropertiesSection(this, matchedStyles, style); @@ -2451,7 +2451,7 @@ export class BlankStylePropertiesSection extends StylePropertiesSection { _actualRuleLocation() { const prefix = this._rulePrefix(); const lines = prefix.split('\n'); - const lastLine = lines.peekLast(); + const lastLine = lines[lines.length - 1]; const editRange = new TextUtils.TextRange.TextRange(0, 0, lines.length - 1, lastLine ? lastLine.length : 0); return this._ruleLocation.rebaseAfterTextEdit(TextUtils.TextRange.TextRange.createFromLocation(0, 0), editRange); } diff --git a/front_end/emulation/MediaQueryInspector.js b/front_end/emulation/MediaQueryInspector.js index 878c98f1f7..d34423d7c4 100644 --- a/front_end/emulation/MediaQueryInspector.js +++ b/front_end/emulation/MediaQueryInspector.js @@ -186,7 +186,7 @@ export class MediaQueryInspector extends UI.Widget.Widget { _squashAdjacentEqual(models) { const filtered = []; for (let i = 0; i < models.length; ++i) { - const last = filtered.peekLast(); + const last = filtered[filtered.length - 1]; if (!last || !last.equals(models[i])) { filtered.push(models[i]); } diff --git a/front_end/formatter_worker/FormattedContentBuilder.ts b/front_end/formatter_worker/FormattedContentBuilder.ts index 55fcface69..c5212f6ae0 100644 --- a/front_end/formatter_worker/FormattedContentBuilder.ts +++ b/front_end/formatter_worker/FormattedContentBuilder.ts @@ -26,7 +26,7 @@ export class FormattedContentBuilder { } addToken(token: string, offset: number): void { - const last = this.formattedContent.peekLast(); + const last = this.formattedContent[this.formattedContent.length - 1]; if (this.enforceSpaceBetweenWords && last && /\w/.test(last[last.length - 1]) && /\w/.test(token)) { this.addSoftSpace(); } diff --git a/front_end/formatter_worker/HTMLFormatter.js b/front_end/formatter_worker/HTMLFormatter.js index f3339b645c..ccfc48d281 100644 --- a/front_end/formatter_worker/HTMLFormatter.js +++ b/front_end/formatter_worker/HTMLFormatter.js @@ -253,7 +253,7 @@ export class HTMLModel { if (lastOffset >= text.length) { break; } - const element = this._stack.peekLast(); + const element = this._stack[this._stack.length - 1]; if (!element) { break; } @@ -274,7 +274,7 @@ export class HTMLModel { } while (this._stack.length > 1) { - const element = this._stack.peekLast(); + const element = this._stack[this._stack.length - 1]; if (!element) { break; } @@ -301,7 +301,7 @@ export class HTMLModel { this._tokens.push(token); this._updateDOM(token); - const element = this._stack.peekLast(); + const element = this._stack[this._stack.length - 1]; if (element && (element.name === 'script' || element.name === 'style') && element.openTag && element.openTag.endOffset === lastOffset) { return AbortTokenization; @@ -387,7 +387,7 @@ export class HTMLModel { */ _onTagComplete(tag) { if (tag.isOpenTag) { - const topElement = this._stack.peekLast(); + const topElement = this._stack[this._stack.length - 1]; if (topElement) { const tagSet = AutoClosingTags.get(topElement.name); if (topElement !== this._document && topElement.openTag && topElement.openTag.selfClosingTag) { @@ -400,10 +400,10 @@ export class HTMLModel { return; } - let lastTag = this._stack.peekLast(); + let lastTag = this._stack[this._stack.length - 1]; while (this._stack.length > 1 && lastTag && lastTag.name !== tag.name) { this._popElement(autocloseTag(lastTag, tag.startOffset)); - lastTag = this._stack.peekLast(); + lastTag = this._stack[this._stack.length - 1]; } if (this._stack.length === 1) { return; @@ -435,7 +435,7 @@ export class HTMLModel { * @param {!Tag} openTag */ _pushElement(openTag) { - const topElement = this._stack.peekLast(); + const topElement = this._stack[this._stack.length - 1]; const newElement = new FormatterElement(openTag.name); if (topElement) { newElement.parent = topElement; diff --git a/front_end/legacy/legacy-defs.d.ts b/front_end/legacy/legacy-defs.d.ts index 751182012a..e922cf5b6f 100644 --- a/front_end/legacy/legacy-defs.d.ts +++ b/front_end/legacy/legacy-defs.d.ts @@ -15,7 +15,6 @@ declare class DOM { } interface Array { - peekLast(): T | undefined; intersectOrdered(array: T[], comparator: (a: T, b: T) => number): T[]; mergeOrdered(array: T[], comparator: (a: T, b: T) => number): T[]; lowerBound(object: S, comparator?: {(a: S, b: T): number}, left?: number, right?: number): number; diff --git a/front_end/object_ui/RemoteObjectPreviewFormatter.js b/front_end/object_ui/RemoteObjectPreviewFormatter.js index 2054111cbc..926848c397 100644 --- a/front_end/object_ui/RemoteObjectPreviewFormatter.js +++ b/front_end/object_ui/RemoteObjectPreviewFormatter.js @@ -269,7 +269,7 @@ export class RemoteObjectPreviewFormatter { * @return {!Element} */ _renderPropertyPreviewOrAccessor(propertyPath) { - const property = propertyPath.peekLast(); + const property = propertyPath[propertyPath.length - 1]; if (!property) { throw new Error('Could not find property'); } diff --git a/front_end/perf_ui/FlameChart.js b/front_end/perf_ui/FlameChart.js index 6b6bb3940e..10382f9a9a 100644 --- a/front_end/perf_ui/FlameChart.js +++ b/front_end/perf_ui/FlameChart.js @@ -1667,7 +1667,10 @@ export class FlameChart extends UI.Widget.VBox { } const groupOffsets = this._groupOffsets; - const lastGroupOffset = Array.prototype.peekLast.call(groupOffsets); + if (groupOffsets === null || groupOffsets === undefined) { + return; + } + const lastGroupOffset = groupOffsets[groupOffsets.length - 1]; const colorUsage = ThemeSupport.ThemeSupport.ColorUsage; context.save(); @@ -1823,13 +1826,13 @@ export class FlameChart extends UI.Widget.VBox { const groupTop = groupOffsets[i]; const group = groups[i]; let firstGroup = true; - let last = groupStack.peekLast(); + let last = groupStack[groupStack.length - 1]; while (last && last.nestingLevel >= group.style.nestingLevel) { groupStack.pop(); firstGroup = false; - last = groupStack.peekLast(); + last = groupStack[groupStack.length - 1]; } - last = groupStack.peekLast(); + last = groupStack[groupStack.length - 1]; const parentGroupVisible = last ? last.visible : false; const thisGroupVisible = parentGroupVisible && (!this._isGroupCollapsible(i) || group.expanded); groupStack.push({nestingLevel: group.style.nestingLevel, visible: Boolean(thisGroupVisible)}); @@ -2138,7 +2141,7 @@ export class FlameChart extends UI.Widget.VBox { /** @type {!Array<{nestingLevel: number, visible: boolean}>} */ const groupStack = [{nestingLevel: -1, visible: true}]; const lastGroupLevel = - Math.max(levelCount, groups.length ? /** @type {!Group} */ (groups.peekLast()).startLevel + 1 : 0); + Math.max(levelCount, groups.length ? /** @type {!Group} */ (groups[groups.length - 1]).startLevel + 1 : 0); let level; for (level = 0; level < lastGroupLevel; ++level) { let parentGroupIsVisible = true; @@ -2147,16 +2150,16 @@ export class FlameChart extends UI.Widget.VBox { ++groupIndex; style = groups[groupIndex].style; let nextLevel = true; - let last = groupStack.peekLast(); + let last = groupStack[groupStack.length - 1]; while (last && last.nestingLevel >= style.nestingLevel) { groupStack.pop(); nextLevel = false; - last = groupStack.peekLast(); + last = groupStack[groupStack.length - 1]; } const thisGroupIsVisible = groupIndex >= 0 && this._isGroupCollapsible(groupIndex) ? groups[groupIndex].expanded : true; - last = groupStack.peekLast(); + last = groupStack[groupStack.length - 1]; parentGroupIsVisible = last ? last.visible : false; visible = Boolean(thisGroupIsVisible) && parentGroupIsVisible; groupStack.push({nestingLevel: style.nestingLevel, visible: visible}); diff --git a/front_end/performance_monitor/PerformanceMonitor.js b/front_end/performance_monitor/PerformanceMonitor.js index ea4419c751..213bd0ce9b 100644 --- a/front_end/performance_monitor/PerformanceMonitor.js +++ b/front_end/performance_monitor/PerformanceMonitor.js @@ -399,7 +399,8 @@ export class PerformanceMonitorImpl extends UI.Widget.HBox { path.moveTo(x, calcY(0)); path.lineTo(this._width + 5, calcY(0)); lastY = calcY( - /** @type {!{metrics: !Map}} */ (this._metricsBuffer.peekLast()).metrics.get(metricName) || + /** @type {!{metrics: !Map}} */ (this._metricsBuffer[this._metricsBuffer.length - 1]) + .metrics.get(metricName) || 0); lastX = this._width + 5; path.lineTo(lastX, lastY); diff --git a/front_end/performance_test_runner/TimelineTestRunner.js b/front_end/performance_test_runner/TimelineTestRunner.js index 43cafd6ba4..5723cd1c8e 100644 --- a/front_end/performance_test_runner/TimelineTestRunner.js +++ b/front_end/performance_test_runner/TimelineTestRunner.js @@ -247,7 +247,7 @@ PerformanceTestRunner.forAllEvents = async function(events, callback) { const eventStack = []; for (const event of events) { - while (eventStack.length && eventStack.peekLast().endTime <= event.startTime) { + while (eventStack.length && eventStack[eventStack.length - 1].endTime <= event.startTime) { eventStack.pop(); } diff --git a/front_end/platform/utilities.js b/front_end/platform/utilities.js index cd29122022..e241b5313b 100644 --- a/front_end/platform/utilities.js +++ b/front_end/platform/utilities.js @@ -236,18 +236,6 @@ Object.defineProperty(Int32Array.prototype, 'upperBound', {value: Array.prototyp Object.defineProperty(Float64Array.prototype, 'lowerBound', {value: Array.prototype.lowerBound, configurable: true}); -Object.defineProperty(Array.prototype, 'peekLast', { - /** - * @return {!T|undefined} - * @this {Array.} - * @template T - */ - value: function() { - return this[this.length - 1]; - }, - configurable: true -}); - (function() { /** * @param {!Array.} array1 diff --git a/front_end/profiler/HeapSnapshotDataGrids.js b/front_end/profiler/HeapSnapshotDataGrids.js index bdf25d913a..32ed3d8f98 100644 --- a/front_end/profiler/HeapSnapshotDataGrids.js +++ b/front_end/profiler/HeapSnapshotDataGrids.js @@ -551,7 +551,7 @@ export class HeapSnapshotViewportDataGrid extends HeapSnapshotSortableDataGrid { */ revealTreeNode(pathToReveal) { const height = this._calculateOffset(pathToReveal); - const node = /** @type {!HeapSnapshotGridNode} */ (pathToReveal.peekLast()); + const node = /** @type {!HeapSnapshotGridNode} */ (pathToReveal[pathToReveal.length - 1]); const scrollTop = this.scrollContainer.scrollTop; const scrollBottom = scrollTop + this.scrollContainer.offsetHeight; if (height >= scrollTop && height < scrollBottom) { @@ -597,7 +597,7 @@ export class HeapSnapshotViewportDataGrid extends HeapSnapshotSortableDataGrid { } parentNode = node; } - return height - /** @type {!HeapSnapshotGridNode} */ (pathToReveal.peekLast()).nodeSelfHeight(); + return height - /** @type {!HeapSnapshotGridNode} */ (pathToReveal[pathToReveal.length - 1]).nodeSelfHeight(); } /** diff --git a/front_end/profiler/HeapSnapshotView.js b/front_end/profiler/HeapSnapshotView.js index c789fd1566..c23dbfb4d5 100644 --- a/front_end/profiler/HeapSnapshotView.js +++ b/front_end/profiler/HeapSnapshotView.js @@ -311,7 +311,7 @@ export class HeapSnapshotView extends UI.View.SimpleView { profileSamples.ids = samples.lastAssignedIds; profileSamples.timestamps = samples.timestamps; profileSamples.max = samples.sizes; - profileSamples.totalTime = Math.max(samples.timestamps.peekLast() || 0, 10000); + profileSamples.totalTime = Math.max(samples.timestamps[samples.timestamps.length - 1] || 0, 10000); if (this._trackingOverviewGrid) { this._trackingOverviewGrid.setSamples(profileSamples); } diff --git a/front_end/quick_open/FilteredListWidget.js b/front_end/quick_open/FilteredListWidget.js index c3d7299905..144ff20169 100644 --- a/front_end/quick_open/FilteredListWidget.js +++ b/front_end/quick_open/FilteredListWidget.js @@ -459,14 +459,14 @@ export class FilteredListWidget extends UI.Widget.VBox { bestItems.splice(index, 0, i); if (bestScores.length > bestItemsToCollect) { // Best list is too large -> drop last elements. - const bestItemLast = bestItems.peekLast(); + const bestItemLast = bestItems[bestItems.length - 1]; if (bestItemLast) { overflowItems.push(bestItemLast); } bestScores.length = bestItemsToCollect; bestItems.length = bestItemsToCollect; } - const bestScoreLast = bestScores.peekLast(); + const bestScoreLast = bestScores[bestScores.length - 1]; if (bestScoreLast) { minBestScore = bestScoreLast; } diff --git a/front_end/sdk/CPUProfileDataModel.js b/front_end/sdk/CPUProfileDataModel.js index 434cd12b16..f5be0b8ff6 100644 --- a/front_end/sdk/CPUProfileDataModel.js +++ b/front_end/sdk/CPUProfileDataModel.js @@ -287,11 +287,11 @@ export class CPUProfileDataModel extends ProfileTreeModel { if (this.samples.length === timestamps.length) { // Support for a legacy format where were no timeDeltas. // Add an extra timestamp used to calculate the last sample duration. - const averageSample = ((timestamps.peekLast() || 0) - timestamps[0]) / (timestamps.length - 1); - this.timestamps.push((timestamps.peekLast() || 0) + averageSample); + const averageSample = ((timestamps[timestamps.length - 1] || 0) - timestamps[0]) / (timestamps.length - 1); + this.timestamps.push((timestamps[timestamps.length - 1] || 0) + averageSample); } this.profileStartTime = timestamps[0]; - this.profileEndTime = /** @type {number} */ (timestamps.peekLast()); + this.profileEndTime = /** @type {number} */ (timestamps[timestamps.length - 1]); } _buildIdToNodeMap() { diff --git a/front_end/sdk/CSSMatchedStyles.js b/front_end/sdk/CSSMatchedStyles.js index 8b0b79fb38..16d33b67d1 100644 --- a/front_end/sdk/CSSMatchedStyles.js +++ b/front_end/sdk/CSSMatchedStyles.js @@ -77,7 +77,7 @@ export class CSSMatchedStyles { // Merge UA rules that are sequential and have similar selector/media. const cleanMatchedPayload = []; for (const ruleMatch of payload) { - const lastMatch = cleanMatchedPayload.peekLast(); + const lastMatch = cleanMatchedPayload[cleanMatchedPayload.length - 1]; if (!lastMatch || ruleMatch.rule.origin !== 'user-agent' || lastMatch.rule.origin !== 'user-agent' || ruleMatch.rule.selectorList.text !== lastMatch.rule.selectorList.text || mediaText(ruleMatch) !== mediaText(lastMatch)) { diff --git a/front_end/sdk/NetworkManager.js b/front_end/sdk/NetworkManager.js index a3631e2895..09e3295b92 100644 --- a/front_end/sdk/NetworkManager.js +++ b/front_end/sdk/NetworkManager.js @@ -1739,7 +1739,7 @@ class RedirectExtraInfoBuilder { if (this._hasExtraInfo) { // if we haven't gotten the last responseExtraInfo event, we have to wait for it. - const lastItem = this._requests.peekLast(); + const lastItem = this._requests[this._requests.length - 1]; if (lastItem && !lastItem.hasExtraResponseInfo()) { return; } diff --git a/front_end/sdk/RuntimeModel.js b/front_end/sdk/RuntimeModel.js index b096745f2a..4239213ef6 100644 --- a/front_end/sdk/RuntimeModel.js +++ b/front_end/sdk/RuntimeModel.js @@ -529,7 +529,8 @@ export class RuntimeModel extends SDKModel { * @return {!Promise} */ async checkSideEffectSupport() { - const testContext = this.executionContexts().peekLast(); + const contexts = this.executionContexts(); + const testContext = contexts[contexts.length - 1]; if (!testContext) { return false; } diff --git a/front_end/sdk/TracingModel.js b/front_end/sdk/TracingModel.js index a4eeb6470e..93e818ec13 100644 --- a/front_end/sdk/TracingModel.js +++ b/front_end/sdk/TracingModel.js @@ -443,7 +443,7 @@ export class TracingModel { case phase.NestableAsyncInstant: { if (openEventsStack && openEventsStack.length) { - const event = openEventsStack.peekLast(); + const event = openEventsStack[openEventsStack.length - 1]; if (event) { event._addStep(event); } @@ -497,7 +497,7 @@ export class TracingModel { return; } if (event.phase === phase.AsyncStepInto || event.phase === phase.AsyncStepPast) { - const lastStep = asyncEvent.steps.peekLast(); + const lastStep = asyncEvent.steps[asyncEvent.steps.length - 1]; if (lastStep && lastStep.phase !== phase.AsyncBegin && lastStep.phase !== event.phase) { console.assert( false, 'Async event step phase mismatch: ' + lastStep.phase + ' at ' + lastStep.startTime + ' vs. ' + diff --git a/front_end/timeline/CountersGraph.js b/front_end/timeline/CountersGraph.js index 687866403d..c0495d42a7 100644 --- a/front_end/timeline/CountersGraph.js +++ b/front_end/timeline/CountersGraph.js @@ -304,7 +304,7 @@ export class Counter { * @param {number} value */ appendSample(time, value) { - if (this.values.length && this.values.peekLast() === value) { + if (this.values.length && this.values[this.values.length - 1] === value) { return; } this.times.push(time); diff --git a/front_end/timeline/EventsTimelineTreeView.js b/front_end/timeline/EventsTimelineTreeView.js index 4d63ef8a22..86c9a3686e 100644 --- a/front_end/timeline/EventsTimelineTreeView.js +++ b/front_end/timeline/EventsTimelineTreeView.js @@ -86,7 +86,7 @@ export class EventsTimelineTreeView extends TimelineTreeView { while (iterators.length) { // @ts-ignore crbug.com/1011811 there is no common iterator type between Closure and TypeScript - const iterator = iterators.peekLast().next(); + const iterator = iterators[iterators.length - 1].next(); if (iterator.done) { iterators.pop(); continue; diff --git a/front_end/timeline/TimelineController.js b/front_end/timeline/TimelineController.js index f6ed1274e7..1ef8828620 100644 --- a/front_end/timeline/TimelineController.js +++ b/front_end/timeline/TimelineController.js @@ -356,8 +356,8 @@ export class TimelineController { } } else { // Legacy backends support. - const mainMetaEvent = - metadataEvents.filter(event => event.name === metadataEventTypes.TracingStartedInPage).peekLast(); + const filteredEvents = metadataEvents.filter(event => event.name === metadataEventTypes.TracingStartedInPage); + const mainMetaEvent = filteredEvents[filteredEvents.length - 1]; if (mainMetaEvent) { const pid = mainMetaEvent.thread.process().id(); if (this._tracingManager) { diff --git a/front_end/timeline/TimelineEventOverview.js b/front_end/timeline/TimelineEventOverview.js index e8af0225ea..e261f7c7c7 100644 --- a/front_end/timeline/TimelineEventOverview.js +++ b/front_end/timeline/TimelineEventOverview.js @@ -269,7 +269,7 @@ export class TimelineEventOverviewCPUActivity extends TimelineEventOverview { * @param {!SDK.TracingModel.Event} e */ function onEventStart(e) { - const index = categoryIndexStack.length ? categoryIndexStack.peekLast() : idleIndex; + const index = categoryIndexStack.length ? categoryIndexStack[categoryIndexStack.length - 1] : idleIndex; quantizer.appendInterval(e.startTime, /** @type {number} */ (index)); categoryIndexStack.push(categoryToIndex.get(TimelineUIUtils.eventStyle(e).category) || otherIndex); } @@ -565,7 +565,7 @@ export class TimelineEventOverviewFrames extends TimelineEventOverview { ctx.lineTo(x, y + tickDepth); ctx.lineTo(x, y); } - const lastFrame = frames.peekLast(); + const lastFrame = frames[frames.length - 1]; if (lastFrame) { x = Math.round((lastFrame.startTime + lastFrame.duration - timeOffset) * scale) + offset; } diff --git a/front_end/timeline/TimelineFlameChartDataProvider.js b/front_end/timeline/TimelineFlameChartDataProvider.js index 58bd75f5ba..975f5ddd9d 100644 --- a/front_end/timeline/TimelineFlameChartDataProvider.js +++ b/front_end/timeline/TimelineFlameChartDataProvider.js @@ -573,14 +573,15 @@ export class TimelineFlameChartDataProvider extends Common.ObjectWrapper.ObjectW continue; } } - while (openEvents.length && - /** @type {number} */ (/** @type {!SDK.TracingModel.Event} */ (openEvents.peekLast()).endTime) <= - e.startTime) { + while ( + openEvents.length && + /** @type {number} */ (/** @type {!SDK.TracingModel.Event} */ (openEvents[openEvents.length - 1]).endTime) <= + e.startTime) { openEvents.pop(); } eventToDisallowRoot.set(e, false); if (ignoreListingEnabled && this._isIgnoreListedEvent(e)) { - const parent = openEvents.peekLast(); + const parent = openEvents[openEvents.length - 1]; if (parent && eventToDisallowRoot.get(parent)) { continue; } @@ -596,7 +597,7 @@ export class TimelineFlameChartDataProvider extends Common.ObjectWrapper.ObjectW const level = this._currentLevel + openEvents.length; const index = this._appendEvent(e, level); if (openEvents.length) { - this._entryParent[index] = /** @type {!SDK.TracingModel.Event} */ (openEvents.peekLast()); + this._entryParent[index] = /** @type {!SDK.TracingModel.Event} */ (openEvents[openEvents.length - 1]); } if (!isExtension && this._performanceModel.timelineModel().isMarkerEvent(e)) { // @ts-ignore This is invalid code, but we should keep it for now @@ -832,7 +833,7 @@ export class TimelineFlameChartDataProvider extends Common.ObjectWrapper.ObjectW const hasFilmStrip = Boolean(screenshots.length); this._framesHeader.collapsible = hasFilmStrip; this._appendHeader(Common.UIString.UIString('Frames'), this._framesHeader, false /* selectable */); - this._frameGroup = this._timelineData.groups.peekLast(); + this._frameGroup = this._timelineData.groups[this._timelineData.groups.length - 1]; const style = TimelineUIUtils.markerStyleForFrame(); this._entryTypeByLevel[this._currentLevel] = EntryType.Frame; diff --git a/front_end/timeline/TimelineHistoryManager.js b/front_end/timeline/TimelineHistoryManager.js index 4857cd408b..f8db2bf605 100644 --- a/front_end/timeline/TimelineHistoryManager.js +++ b/front_end/timeline/TimelineHistoryManager.js @@ -254,7 +254,8 @@ export class TimelineHistoryManager { container.style.width = this._totalHeight * thumbnailAspectRatio + 'px'; container.style.height = this._totalHeight + 'px'; const filmStripModel = performanceModel.filmStripModel(); - const lastFrame = filmStripModel.frames().peekLast(); + const frames = filmStripModel.frames(); + const lastFrame = frames[frames.length - 1]; if (!lastFrame) { return container; } diff --git a/front_end/timeline/TimelineUIUtils.js b/front_end/timeline/TimelineUIUtils.js index 4f0f163836..67ad1475dc 100644 --- a/front_end/timeline/TimelineUIUtils.js +++ b/front_end/timeline/TimelineUIUtils.js @@ -1334,7 +1334,7 @@ export class TimelineUIUtils { if (index === 0) { value = 0; } else if (index === categoryCache.time.length) { - value = categoryCache.value.peekLast(); + value = categoryCache.value[categoryCache.value.length - 1]; } else { const t0 = categoryCache.time[index - 1]; const t1 = categoryCache.time[index]; @@ -1397,7 +1397,7 @@ export class TimelineUIUtils { statsArrays = {time: [], value: []}; aggregatedStats[category] = statsArrays; } - if (statsArrays.time.length && statsArrays.time.peekLast() === time || lastTime > time) { + if (statsArrays.time.length && statsArrays.time[statsArrays.time.length - 1] === time || lastTime > time) { return; } const lastValue = statsArrays.value.length > 0 ? statsArrays.value[statsArrays.value.length - 1] : 0; @@ -1425,7 +1425,7 @@ export class TimelineUIUtils { */ function onStartEvent(e) { const category = TimelineUIUtils.eventStyle(e).category.name; - const parentCategory = categoryStack.length ? categoryStack.peekLast() : null; + const parentCategory = categoryStack.length ? categoryStack[categoryStack.length - 1] : null; if (category !== parentCategory) { categoryChange(parentCategory || null, category, e.startTime); } @@ -1437,7 +1437,7 @@ export class TimelineUIUtils { */ function onEndEvent(e) { const category = categoryStack.pop(); - const parentCategory = categoryStack.length ? categoryStack.peekLast() : null; + const parentCategory = categoryStack.length ? categoryStack[categoryStack.length - 1] : null; if (category !== parentCategory) { categoryChange(category || null, parentCategory || null, e.endTime || 0); } diff --git a/front_end/timeline_model/TimelineFrameModel.js b/front_end/timeline_model/TimelineFrameModel.js index 0b2d9e0179..456032e2e7 100644 --- a/front_end/timeline_model/TimelineFrameModel.js +++ b/front_end/timeline_model/TimelineFrameModel.js @@ -252,7 +252,7 @@ export class TimelineFrameModel { if (this._lastLayerTree) { this._lastLayerTree._setPaints(frame._paints); } - const lastFrame = this._frames.peekLast(); + const lastFrame = this._frames[this._frames.length - 1]; if (this._frames.length && lastFrame && (frame.startTime !== lastFrame.endTime || frame.startTime > frame.endTime)) { console.assert( diff --git a/front_end/timeline_model/TimelineJSProfile.js b/front_end/timeline_model/TimelineJSProfile.js index 108e5f5303..738fe9f072 100644 --- a/front_end/timeline_model/TimelineJSProfile.js +++ b/front_end/timeline_model/TimelineJSProfile.js @@ -141,7 +141,7 @@ export class TimelineJSProfileProcessor { */ function truncateJSStack(depth, time) { if (lockedJsStackDepth.length) { - const lockedDepth = /** @type {number}*/ (lockedJsStackDepth.peekLast()); + const lockedDepth = /** @type {number}*/ (lockedJsStackDepth[lockedJsStackDepth.length - 1]); if (depth < lockedDepth) { console.error(`Child stack is shallower (${depth}) than the parent stack (${lockedDepth}) at ${time}`); depth = lockedDepth; @@ -208,7 +208,7 @@ export class TimelineJSProfileProcessor { const endTime = e.endTime || e.startTime; const minFrames = Math.min(callFrames.length, jsFramesStack.length); let i; - for (i = lockedJsStackDepth.peekLast() || 0; i < minFrames; ++i) { + for (i = lockedJsStackDepth[lockedJsStackDepth.length - 1] || 0; i < minFrames; ++i) { const newFrame = callFrames[i]; const oldFrame = jsFramesStack[i].args['data']; if (!equalFrames(newFrame, oldFrame)) { diff --git a/front_end/timeline_model/TimelineModel.js b/front_end/timeline_model/TimelineModel.js index a5600edce7..227482ee82 100644 --- a/front_end/timeline_model/TimelineModel.js +++ b/front_end/timeline_model/TimelineModel.js @@ -130,11 +130,11 @@ export class TimelineModelImpl { if (SDK.TracingModel.TracingModel.isAsyncPhase(e.phase) || SDK.TracingModel.TracingModel.isFlowPhase(e.phase)) { continue; } - let last = stack.peekLast(); + let last = stack[stack.length - 1]; while (last && last.endTime !== undefined && last.endTime <= e.startTime) { stack.pop(); onEndEvent(last); - last = stack.peekLast(); + last = stack[stack.length - 1]; } if (filter && !filter(e)) { continue; @@ -143,7 +143,7 @@ export class TimelineModelImpl { onStartEvent(e); stack.push(e); } else { - onInstantEvent && onInstantEvent(e, stack.peekLast() || null); + onInstantEvent && onInstantEvent(e, stack[stack.length - 1] || null); } } while (stack.length) { @@ -470,7 +470,7 @@ export class TimelineModelImpl { let lastMainUrl = null; let hasMain = false; for (const item of data) { - const last = ranges.peekLast(); + const last = ranges[ranges.length - 1]; if (!last || item.from > last.to) { ranges.push({from: item.from, to: item.to}); } else { @@ -676,7 +676,8 @@ export class TimelineModelImpl { let target = null; // Check for legacy CpuProfile event format first. - let cpuProfileEvent = events.peekLast(); + /** @type {(SDK.TracingModel.Event|undefined)} */ + let cpuProfileEvent = events[events.length - 1]; if (cpuProfileEvent && cpuProfileEvent.name === RecordType.CpuProfile) { const eventData = cpuProfileEvent.args['data']; cpuProfile = /** @type {?Protocol.Profiler.Profile} */ (eventData && eventData['cpuProfile']); @@ -856,17 +857,17 @@ export class TimelineModelImpl { this._estimatedTotalBlockingTime += event.duration - 50; } - let last = eventStack.peekLast(); + let last = eventStack[eventStack.length - 1]; while (last && last.endTime !== undefined && last.endTime <= event.startTime) { eventStack.pop(); - last = eventStack.peekLast(); + last = eventStack[eventStack.length - 1]; } if (!this._processEvent(event)) { continue; } if (!SDK.TracingModel.TracingModel.isAsyncPhase(event.phase) && event.duration) { if (eventStack.length) { - const parent = eventStack.peekLast(); + const parent = eventStack[eventStack.length - 1]; if (parent) { parent.selfTime -= event.duration; if (parent.selfTime < 0) { @@ -952,7 +953,7 @@ export class TimelineModelImpl { if (asyncEvent.hasCategory(TimelineModelImpl.Category.LatencyInfo) || asyncEvent.name === RecordType.ImplSideFling) { - const lastStep = asyncEvent.steps.peekLast(); + const lastStep = asyncEvent.steps[asyncEvent.steps.length - 1]; if (!lastStep) { throw new Error('AsyncEvent.steps access is out of bounds.'); } @@ -1037,7 +1038,7 @@ export class TimelineModelImpl { } } let pageFrameId = TimelineModelImpl.eventFrameId(event); - const last = eventStack.peekLast(); + const last = eventStack[eventStack.length - 1]; if (!pageFrameId && last) { pageFrameId = TimelineData.forEvent(last).frameId; } @@ -1051,7 +1052,7 @@ export class TimelineModelImpl { switch (event.name) { case recordTypes.ResourceSendRequest: case recordTypes.WebSocketCreate: { - timelineData.setInitiator(eventStack.peekLast() || null); + timelineData.setInitiator(eventStack[eventStack.length - 1] || null); timelineData.url = eventData['url']; break; } @@ -1834,7 +1835,7 @@ export class Track { * @return {number} */ function peekLastEndTime() { - const last = stack.peekLast(); + const last = stack[stack.length - 1]; if (last !== undefined) { const endTime = last.endTime; if (endTime !== undefined) { diff --git a/front_end/ui/ContextMenu.js b/front_end/ui/ContextMenu.js index e311fca504..e5801c68d9 100644 --- a/front_end/ui/ContextMenu.js +++ b/front_end/ui/ContextMenu.js @@ -375,7 +375,7 @@ export class SubMenu extends Item { } result.subItems.push(item._buildDescriptor()); } - if (section !== nonEmptySections.peekLast()) { + if (section !== nonEmptySections[nonEmptySections.length - 1]) { if (!result.subItems) { result.subItems = []; } diff --git a/front_end/ui/Toolbar.js b/front_end/ui/Toolbar.js index 159686c34e..4f2ef2b47d 100644 --- a/front_end/ui/Toolbar.js +++ b/front_end/ui/Toolbar.js @@ -396,7 +396,7 @@ export class Toolbar { nonSeparatorVisible = true; } } - if (lastSeparator && lastSeparator !== this._items.peekLast()) { + if (lastSeparator && lastSeparator !== this._items[this._items.length - 1]) { lastSeparator.setVisible(false); }