Mercurial > hg
comparison tests/test-hgweb-commands.t @ 35160:69a865dc2ada
hgweb: define locally used variables as actually local in mercurial.js
Variables that are used or assigned without any declaration using var (or let,
or const) are considered global. In many cases this is inadvertent and actually
causes a variable leaking to a broader scope, such as a temporary variable used
inside a loop suddenly being accessible in global scope. (This corresponds to
"undef" option of jshint).
So this patch limits the scope of variables that don't need to be global. There
are a lot of helper variables in Graph.render() used in a loop, I've declared
them all on one line to reduce patch size. "radius" is special because it
wasn't passed to graph.vertex, but was used there (it worked because this
variable leaked to global scope). "window.graph" is created by an inline script
in graph.tmpl so that it can be used in ajaxScrollInit() function, this patch
makes this fact explicit by assigning window.graph to a local variable.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Wed, 22 Nov 2017 21:49:36 +0800 |
parents | d2eff9d4db3f |
children | ec71518acd4a |
comparison
equal
deleted
inserted
replaced
35159:018aac6d7cb0 | 35160:69a865dc2ada |
---|---|
1790 | 1790 |
1791 var data = [["cad8025a2e87", [0, 1], [[0, 0, 1, 3, "FF0000"]], "branch commit with null character: \u0000", "test", "1970-01-01", ["unstable", true], ["tip"], ["something"]], ["1d22e65f027e", [0, 1], [[0, 0, 1, 3, ""]], "branch", "test", "1970-01-01", ["stable", true], [], []], ["a4f92ed23982", [0, 1], [[0, 0, 1, 3, ""]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], [], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"], ["anotherthing"]]]; | 1791 var data = [["cad8025a2e87", [0, 1], [[0, 0, 1, 3, "FF0000"]], "branch commit with null character: \u0000", "test", "1970-01-01", ["unstable", true], ["tip"], ["something"]], ["1d22e65f027e", [0, 1], [[0, 0, 1, 3, ""]], "branch", "test", "1970-01-01", ["stable", true], [], []], ["a4f92ed23982", [0, 1], [[0, 0, 1, 3, ""]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], [], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"], ["anotherthing"]]]; |
1792 var graph = new Graph(); | 1792 var graph = new Graph(); |
1793 graph.scale(39); | 1793 graph.scale(39); |
1794 | 1794 |
1795 graph.vertex = function(x, y, color, parity, cur) { | 1795 graph.vertex = function(x, y, radius, color, parity, cur) { |
1796 | 1796 |
1797 this.ctx.beginPath(); | 1797 this.ctx.beginPath(); |
1798 color = this.setColor(color, 0.25, 0.75); | 1798 color = this.setColor(color, 0.25, 0.75); |
1799 this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); | 1799 this.ctx.arc(x, y, radius, 0, Math.PI * 2, true); |
1800 this.ctx.fill(); | 1800 this.ctx.fill(); |