Skip to content
Snippets Groups Projects
Commit 241da2de authored by Anton Shestakov's avatar Anton Shestakov
Browse files

hgweb: properly iterate over arrays and objects in mercurial.js

In JavaScript, using for-in loops to access every property of an object can
have unexpected results when inheritance is involved. For example, if some
piece of code adds a property (it may be a method too) to Object.prototype,
then all for-in loops that iterate over keys of any object (also anything that
inherits Object) will get that property on one of the iterations. To filter out
such unexpected properties for-in loops have to use Object.hasOwnProperty()
method. (This corresponds to "forin" option of jshint).

In the two first cases "data" and "edges" are arrays, to it's simpler to just
switch to using a regular for-with-a-counter loop.
parent ccf86aa5
No related branches found
No related tags found
No related merge requests found
......@@ -95,7 +95,7 @@
var backgrounds = '';
var nodedata = '';
for (var i in data) {
for (var i = 0; i < data.length; i++) {
var parity = i % 2;
this.cell[1] += this.bg_height;
......@@ -107,7 +107,7 @@
var fold = false;
var prevWidth = this.ctx.lineWidth;
for (var j in edges) {
for (var j = 0; j < edges.length; j++) {
line = edges[j];
start = line[0];
......@@ -227,6 +227,7 @@
}
for (var unit in scales){
if (!scales.hasOwnProperty(unit)) { continue; }
var s = scales[unit];
var n = Math.floor(delta / s);
if ((n >= 2) || (s === 1)){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment