protect for in loops with hasOwnProperty

This commit is contained in:
Bart van den Eijnden
2012-02-29 18:43:55 +01:00
parent d7a3ecac08
commit e3cc96dbfb
31 changed files with 385 additions and 266 deletions

View File

@@ -258,7 +258,9 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
activate: function () {
if (!this.active) {
for(var i in this.handlers) {
this.handlers[i].activate();
if (this.handlers.hasOwnProperty(i)) {
this.handlers[i].activate();
}
}
}
return OpenLayers.Control.prototype.activate.apply(
@@ -276,7 +278,9 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
deactivate: function () {
if (this.active) {
for(var i in this.handlers) {
this.handlers[i].deactivate();
if (this.handlers.hasOwnProperty(i)) {
this.handlers[i].deactivate();
}
}
}
return OpenLayers.Control.prototype.deactivate.apply(
@@ -560,7 +564,9 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
unselectAll: function() {
// we'll want an option to supress notification here
for(var fid in this.features) {
this.unselect(this.features[fid]);
if (this.features.hasOwnProperty(fid)) {
this.unselect(this.features[fid]);
}
}
},
@@ -573,7 +579,9 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
*/
setMap: function(map) {
for(var i in this.handlers) {
this.handlers[i].setMap(map);
if (this.handlers.hasOwnProperty(i)) {
this.handlers[i].setMap(map);
}
}
OpenLayers.Control.prototype.setMap.apply(this, arguments);
},

View File

@@ -193,7 +193,9 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
this.next.destroy();
this.deactivate();
for(var prop in this) {
this[prop] = null;
if (this.hasOwnProperty(prop)) {
this[prop] = null;
}
}
},
@@ -334,25 +336,27 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
setListeners: function() {
this.listeners = {};
for(var type in this.registry) {
this.listeners[type] = OpenLayers.Function.bind(function() {
if(!this.restoring) {
var state = this.registry[type].apply(this, arguments);
this.previousStack.unshift(state);
if(this.previousStack.length > 1) {
this.onPreviousChange(
this.previousStack[1], this.previousStack.length - 1
);
if (this.registry.hasOwnProperty(type)) {
this.listeners[type] = OpenLayers.Function.bind(function() {
if(!this.restoring) {
var state = this.registry[type].apply(this, arguments);
this.previousStack.unshift(state);
if(this.previousStack.length > 1) {
this.onPreviousChange(
this.previousStack[1], this.previousStack.length - 1
);
}
if(this.previousStack.length > (this.limit + 1)) {
this.previousStack.pop();
}
if(this.nextStack.length > 0) {
this.nextStack = [];
this.onNextChange(null, 0);
}
}
if(this.previousStack.length > (this.limit + 1)) {
this.previousStack.pop();
}
if(this.nextStack.length > 0) {
this.nextStack = [];
this.onNextChange(null, 0);
}
}
return true;
}, this);
return true;
}, this);
}
}
},
@@ -371,7 +375,9 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
this.setListeners();
}
for(var type in this.listeners) {
this.map.events.register(type, this, this.listeners[type]);
if (this.listeners.hasOwnProperty(type)) {
this.map.events.register(type, this, this.listeners[type]);
}
}
activated = true;
if(this.previousStack.length == 0) {
@@ -405,9 +411,11 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
if(this.map) {
if(OpenLayers.Control.prototype.deactivate.apply(this)) {
for(var type in this.listeners) {
this.map.events.unregister(
type, this, this.listeners[type]
);
if (this.listeners.hasOwnProperty(type)) {
this.map.events.unregister(
type, this, this.listeners[type]
);
}
}
if(this.clearOnDeactivate) {
this.clear();

View File

@@ -168,11 +168,16 @@ OpenLayers.Control.SLDSelect = OpenLayers.Class(OpenLayers.Control, {
* Take care of things that are not handled in superclass.
*/
destroy: function() {
for (var key in this.layerCache) {
delete this.layerCache[key];
var key;
for (key in this.layerCache) {
if (this.layerCache.hasOwnProperty(key)) {
delete this.layerCache[key];
}
}
for (var key in this.wfsCache) {
delete this.wfsCache[key];
for (key in this.wfsCache) {
if (this.wfsCache.hasOwnProperty(key)) {
delete this.wfsCache[key];
}
}
OpenLayers.Control.prototype.destroy.apply(this, arguments);
},

View File

@@ -456,10 +456,12 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
}
var layers;
for (var url in services) {
layers = services[url];
var wmsOptions = this.buildWMSOptions(url, layers,
clickPosition, layers[0].params.FORMAT);
OpenLayers.Request.GET(wmsOptions);
if (services.hasOwnProperty(url)) {
layers = services[url];
var wmsOptions = this.buildWMSOptions(url, layers,
clickPosition, layers[0].params.FORMAT);
OpenLayers.Request.GET(wmsOptions);
}
}
}
},