results.webkit.org: TypeError when evaluating empty commits
https://bugs.webkit.org/show_bug.cgi?id=202936

Reviewed by Jonathan Bedard.

*resultsdbpy/resultsdbpy/view/static/library/js/components/TimelineComponents.js: Draw empty line when invaild scales or dots state pass in


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251114 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index 963217c..2d530f2 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,12 @@
+2019-10-14  Zhifei FANG  <zhifei_fang@apple.com>
+
+        results.webkit.org: TypeError when evaluating empty commits
+        https://bugs.webkit.org/show_bug.cgi?id=202936
+
+        Reviewed by Jonathan Bedard.
+
+        *resultsdbpy/resultsdbpy/view/static/library/js/components/TimelineComponents.js: Draw empty line when invaild scales or dots state pass in
+
 2019-10-14  Jonathan Bedard  <jbedard@apple.com>
 
         Python 3: Add support in webkitpy.common.net.bugzilla
diff --git a/Tools/resultsdbpy/resultsdbpy/view/static/library/js/components/TimelineComponents.js b/Tools/resultsdbpy/resultsdbpy/view/static/library/js/components/TimelineComponents.js
index 4cde3fb..08868f2 100644
--- a/Tools/resultsdbpy/resultsdbpy/view/static/library/js/components/TimelineComponents.js
+++ b/Tools/resultsdbpy/resultsdbpy/view/static/library/js/components/TimelineComponents.js
@@ -373,7 +373,10 @@
             context.moveTo(startX, radius);
             context.lineTo(startX + renderWidth, radius);
         });
-
+        if (!scales || !dots || !scales.length || !dots.length) {
+            colorBatchRender.batchRender(context);
+            return;
+        }
         // Draw the dots
         // First, Calculate the render range:
         let startScalesIndex = Math.floor((scrollLeft + startX) / dotWidth);
@@ -732,19 +735,6 @@
         const usedLineColor = computedStyle.getPropertyValue('--borderColorInlineElement');
         const baseLineY = isTop ? canvasHeight - scaleBroadLineHeight : scaleBroadLineHeight;
         const context = element.getContext("2d", { alpha: false });
-        let currentStartScaleIndex = Math.floor(scrollLeft / scaleWidth);
-        if (currentStartScaleIndex < 0)
-            currentStartScaleIndex = 0;
-        const currentStartScaleKey = getScaleKey(scales[currentStartScaleIndex]);
-        let currentEndScaleIndex = Math.ceil((scrollLeft + renderWidth) / scaleWidth);
-        currentEndScaleIndex = currentEndScaleIndex >= scales.length ? scales.length - 1 : currentEndScaleIndex;
-        const currentEndScaleKey = getScaleKey(scales[currentEndScaleIndex]);
-        const currentStartNode = scalesMapLinkList.map.get(currentStartScaleKey);
-        const currentEndNode = scalesMapLinkList.map.get(currentEndScaleKey);
-        if (!currentEndNode) {
-            console.error(currentEndScaleKey);
-        }
-        let now = currentStartNode;
         // Clear pervious batch render
         colorBatchRender.clear();
         colorBatchRender.lazyCreateColorSeqs(usedLineColor, (context) => {
@@ -758,6 +748,24 @@
             context.moveTo(0, baseLineY);
             context.lineTo(element.logicWidth, baseLineY);
         });
+        if (!scales || !scales.length) {
+            colorBatchRender.batchRender(context);
+            return;
+        }
+        let currentStartScaleIndex = Math.floor(scrollLeft / scaleWidth);
+        if (currentStartScaleIndex < 0)
+            currentStartScaleIndex = 0;
+        const currentStartScaleKey = getScaleKey(scales[currentStartScaleIndex]);
+        let currentEndScaleIndex = Math.ceil((scrollLeft + renderWidth) / scaleWidth);
+        currentEndScaleIndex = currentEndScaleIndex >= scales.length ? scales.length - 1 : currentEndScaleIndex;
+        const currentEndScaleKey = getScaleKey(scales[currentEndScaleIndex]);
+        const currentStartNode = scalesMapLinkList.map.get(currentStartScaleKey);
+        const currentEndNode = scalesMapLinkList.map.get(currentEndScaleKey);
+        if (!currentEndNode) {
+            console.error(currentEndScaleKey);
+        }
+        let now = currentStartNode;
+        
 
         onScreenScales = [];
         while (now != currentEndNode.next) {