From ebc87c5c5e8ebc43d402336e5c68290211ed0c29 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 15 Sep 2014 13:00:40 -0400 Subject: [PATCH] godoc: fix bug in "internal call graph" tree widget. Today I learned that getElementByClass returns an HTMLContainer, not an array, so the for loop was iterating its properties, which include: - the methods of the type, which were filtered out by the condition; - the array-like integer indices of the elements, which we want; - the ids of the same elements (!), which we weren't expecting. The net result is that various functions were called twice, causing the tree to be double-populated and clicks to cause and expand+collapse. It's a miracle to me that any JS program even approximately works. Fixes golang/go#8237 LGTM=bradfitz R=gri, bradfitz CC=golang-codereviews https://golang.org/cl/141540043 --- godoc/static/godocs.js | 2 +- godoc/static/static.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/godoc/static/godocs.js b/godoc/static/godocs.js index c4a61e06..9486d2c9 100644 --- a/godoc/static/godocs.js +++ b/godoc/static/godocs.js @@ -441,7 +441,7 @@ function setupCallgraphs() { document.getElementById("pkg-callgraph").style.display = "block"; var treeviews = document.getElementsByClassName("treeview"); - for (var i in treeviews) { + for (var i = 0; i < treeviews.length; i++) { var tree = treeviews[i]; if (tree.id == null || tree.id.indexOf("callgraph-") != 0) { continue; diff --git a/godoc/static/static.go b/godoc/static/static.go index 9ade88d5..3abaf3a4 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -1014,6 +1014,7 @@ function setupCallgraphs() { document.getElementById("pkg-callgraph").style.display = "block"; var treeviews = document.getElementsByClassName("treeview"); + // for (var i = 0; i < treeviews.length; i++) { for (var i in treeviews) { var tree = treeviews[i]; if (tree.id == null || tree.id.indexOf("callgraph-") != 0) {