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

@@ -564,12 +564,14 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
this.writeNode("feature:_geometry", feature.geometry, node);
}
for(var name in feature.attributes) {
var value = feature.attributes[name];
if(value != null) {
this.writeNode(
"feature:_attribute",
{name: name, value: value}, node
);
if (feature.attributes.hasOwnProperty(name)) {
var value = feature.attributes[name];
if(value != null) {
this.writeNode(
"feature:_attribute",
{name: name, value: value}, node
);
}
}
}
return node;

View File

@@ -325,15 +325,17 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
featureNode.appendChild(linkNode);
}
for(var attr in feature.attributes) {
if (attr == "link" || attr == "title" || attr == "description") { continue; }
var attrText = this.createTextNode(feature.attributes[attr]);
var nodename = attr;
if (attr.search(":") != -1) {
nodename = attr.split(":")[1];
}
var attrContainer = this.createElementNS(this.featureNS, "feature:"+nodename);
attrContainer.appendChild(attrText);
featureNode.appendChild(attrContainer);
if (feature.attributes.hasOwnProperty(attr)) {
if (attr == "link" || attr == "title" || attr == "description") { continue; }
var attrText = this.createTextNode(feature.attributes[attr]);
var nodename = attr;
if (attr.search(":") != -1) {
nodename = attr.split(":")[1];
}
var attrContainer = this.createElementNS(this.featureNS, "feature:"+nodename);
attrContainer.appendChild(attrText);
featureNode.appendChild(attrContainer);
}
}
featureNode.appendChild(geometryNode);
return featureNode;

View File

@@ -140,33 +140,35 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, {
feat_list[i] = feat;
}
for (var node_id in nodes) {
var node = nodes[node_id];
if (!node.used || this.checkTags) {
var tags = null;
if (nodes.hasOwnProperty(node_id)) {
var node = nodes[node_id];
if (!node.used || this.checkTags) {
var tags = null;
if (this.checkTags) {
var result = this.getTags(node.node, true);
if (node.used && !result[1]) {
continue;
}
tags = result[0];
} else {
tags = this.getTags(node.node);
}
if (this.checkTags) {
var result = this.getTags(node.node, true);
if (node.used && !result[1]) {
continue;
}
tags = result[0];
} else {
tags = this.getTags(node.node);
}
var feat = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(node['lon'], node['lat']),
tags);
if (this.internalProjection && this.externalProjection) {
feat.geometry.transform(this.externalProjection,
this.internalProjection);
}
feat.osm_id = parseInt(node_id);
feat.fid = "node." + feat.osm_id;
feat_list.push(feat);
}
// Memory cleanup
node.node = null;
var feat = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(node['lon'], node['lat']),
tags);
if (this.internalProjection && this.externalProjection) {
feat.geometry.transform(this.externalProjection,
this.internalProjection);
}
feat.osm_id = parseInt(node_id);
feat.fid = "node." + feat.osm_id;
feat_list.push(feat);
}
// Memory cleanup
node.node = null;
}
}
return feat_list;
},
@@ -273,9 +275,11 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, {
}
if (this.checkTags) {
for(var key in way.tags) {
if (this.areaTags[key]) {
poly_tags = true;
break;
if (way.tags.hasOwnProperty(key)) {
if (this.areaTags[key]) {
poly_tags = true;
break;
}
}
}
}
@@ -430,10 +434,12 @@ OpenLayers.Format.OSM = OpenLayers.Class(OpenLayers.Format.XML, {
*/
serializeTags: function(feature, node) {
for (var key in feature.attributes) {
var tag = this.createElementNS(null, "tag");
tag.setAttribute("k", key);
tag.setAttribute("v", feature.attributes[key]);
node.appendChild(tag);
if (feature.attributes.hasOwnProperty(key)) {
var tag = this.createElementNS(null, "tag");
tag.setAttribute("k", key);
tag.setAttribute("v", feature.attributes[key]);
node.appendChild(tag);
}
}
},

View File

@@ -541,9 +541,11 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
getCssProperty: function(sym) {
var css = null;
for(var prop in this.cssMap) {
if(this.cssMap[prop] == sym) {
css = prop;
break;
if (this.cssMap.hasOwnProperty(prop)) {
if(this.cssMap[prop] == sym) {
css = prop;
break;
}
}
}
return css;
@@ -565,12 +567,14 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
getGraphicFormat: function(href) {
var format, regex;
for(var key in this.graphicFormats) {
if(this.graphicFormats[key].test(href)) {
format = key;
break;
if (this.graphicFormats.hasOwnProperty(key)) {
if(this.graphicFormats[key].test(href)) {
format = key;
break;
}
}
}
return format || this.defautlGraphicFormat;
return format || this.defaultGraphicFormat;
},
/**
@@ -676,7 +680,9 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
}
} else {
for(var name in sld.namedLayers) {
this.writeNode("NamedLayer", sld.namedLayers[name], root);
if (sld.namedLayers.hasOwnProperty(name)) {
this.writeNode("NamedLayer", sld.namedLayers[name], root);
}
}
}
return root;
@@ -769,11 +775,13 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
ruleMap[zIndex].symbolizers.push(symbolizer.clone());
}
for (zIndex in ruleMap) {
if (!(zIndex in rulesByZ)) {
zValues.push(zIndex);
rulesByZ[zIndex] = [];
if (ruleMap.hasOwnProperty(zIndex)) {
if (!(zIndex in rulesByZ)) {
zValues.push(zIndex);
rulesByZ[zIndex] = [];
}
rulesByZ[zIndex].push(ruleMap[zIndex]);
}
rulesByZ[zIndex].push(ruleMap[zIndex]);
}
} else {
// no symbolizers in rule

View File

@@ -128,10 +128,12 @@ OpenLayers.Format.SLD.v1_0_0_GeoServer = OpenLayers.Class(
var options = symbolizer.vendorOptions;
if (options) {
for (var key in symbolizer.vendorOptions) {
this.writeNode("VendorOption", {
name: key,
value: symbolizer.vendorOptions[key]
}, node);
if (symbolizer.vendorOptions.hasOwnProperty(key)) {
this.writeNode("VendorOption", {
name: key,
value: symbolizer.vendorOptions[key]
}, node);
}
}
}
return node;

View File

@@ -210,10 +210,14 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
this.writeNode("eventTime", options, node);
}
for (var procedure in options.procedures) {
this.writeNode("procedure", options.procedures[procedure], node);
if (options.procedures.hasOwnProperty(procedure)) {
this.writeNode("procedure", options.procedures[procedure], node);
}
}
for (var observedProperty in options.observedProperties) {
this.writeNode("observedProperty", options.observedProperties[observedProperty], node);
if (options.observedProperties.hasOwnProperty(observedProperty)) {
this.writeNode("observedProperty", options.observedProperties[observedProperty], node);
}
}
if (options.foi) {
this.writeNode("featureOfInterest", options.foi, node);

View File

@@ -104,15 +104,17 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
var featureContainer = this.createElementNS(this.featureNS, "feature:" + this.featureName);
featureContainer.appendChild(geomContainer);
for(var attr in feature.attributes) {
var attrText = this.createTextNode(feature.attributes[attr]);
var nodename = attr;
if (attr.search(":") != -1) {
nodename = attr.split(":")[1];
}
var attrContainer = this.createElementNS(this.featureNS, "feature:" + nodename);
attrContainer.appendChild(attrText);
featureContainer.appendChild(attrContainer);
}
if (feature.attributes.hasOwnProperty(attr)) {
var attrText = this.createTextNode(feature.attributes[attr]);
var nodename = attr;
if (attr.search(":") != -1) {
nodename = attr.split(":")[1];
}
var attrContainer = this.createElementNS(this.featureNS, "feature:" + nodename);
attrContainer.appendChild(attrText);
featureContainer.appendChild(attrContainer);
}
}
return featureContainer;
},
@@ -166,14 +168,16 @@ OpenLayers.Format.WFS = OpenLayers.Class(OpenLayers.Format.GML, {
// add in attributes
for(var propName in feature.attributes) {
propertyNode = this.createElementNS(this.wfsns, 'wfs:Property');
nameNode = this.createElementNS(this.wfsns, 'wfs:Name');
nameNode.appendChild(this.createTextNode(propName));
propertyNode.appendChild(nameNode);
valueNode = this.createElementNS(this.wfsns, 'wfs:Value');
valueNode.appendChild(this.createTextNode(feature.attributes[propName]));
propertyNode.appendChild(valueNode);
updateNode.appendChild(propertyNode);
if (feature.attributes.hasOwnProperty(propName)) {
propertyNode = this.createElementNS(this.wfsns, 'wfs:Property');
nameNode = this.createElementNS(this.wfsns, 'wfs:Name');
nameNode.appendChild(this.createTextNode(propName));
propertyNode.appendChild(nameNode);
valueNode = this.createElementNS(this.wfsns, 'wfs:Value');
valueNode.appendChild(this.createTextNode(feature.attributes[propName]));
propertyNode.appendChild(valueNode);
updateNode.appendChild(propertyNode);
}
}

View File

@@ -332,12 +332,14 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
// add in attributes
for(var key in feature.attributes) {
if(feature.attributes[key] !== undefined &&
(!modified || !modified.attributes ||
(modified.attributes && modified.attributes[key] !== undefined))) {
this.writeNode(
"Property", {name: key, value: feature.attributes[key]}, node
);
if (feature.attributes.hasOwnProperty(key)) {
if(feature.attributes[key] !== undefined &&
(!modified || !modified.attributes ||
(modified.attributes && modified.attributes[key] !== undefined))) {
this.writeNode(
"Property", {name: key, value: feature.attributes[key]}, node
);
}
}
}
@@ -410,9 +412,11 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
var parts = [];
var uri;
for(var key in schemaLocations) {
uri = this.namespaces[key];
if(uri) {
parts.push(uri + " " + schemaLocations[key]);
if (schemaLocations.hasOwnProperty(key)) {
uri = this.namespaces[key];
if(uri) {
parts.push(uri + " " + schemaLocations[key]);
}
}
}
var value = parts.join(" ") || undefined;

View File

@@ -48,8 +48,10 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
prefix = this.namespaces[this.defaultPrefix];
} else {
for(prefix in this.namespaces) {
if(this.namespaces[prefix] == uri) {
break;
if (this.namespaces.hasOwnProperty(prefix)) {
if(this.namespaces[prefix] == uri) {
break;
}
}
}
}
@@ -674,12 +676,14 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
setAttributes: function(node, obj) {
var value;
for(var name in obj) {
value = obj[name].toString();
if(value.match(/[A-Z]/)) {
// safari lowercases attributes with setAttribute
this.setAttributeNS(node, null, name, value);
} else {
node.setAttribute(name, value);
if (obj.hasOwnProperty(name)) {
value = obj[name].toString();
if(value.match(/[A-Z]/)) {
// safari lowercases attributes with setAttribute
this.setAttributeNS(node, null, name, value);
} else {
node.setAttribute(name, value);
}
}
}
},
@@ -1091,25 +1095,29 @@ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
userValue: true
};
for (var dim in context.dimensions) {
var attributes = {};
var dimension = context.dimensions[dim];
for (var name in dimension) {
if (typeof dimension[name] == "boolean") {
attributes[name] = Number(dimension[name]);
} else {
attributes[name] = dimension[name];
if (context.dimensions.hasOwnProperty(dim)) {
var attributes = {};
var dimension = context.dimensions[dim];
for (var name in dimension) {
if (dimension.hasOwnProperty(name)) {
if (typeof dimension[name] == "boolean") {
attributes[name] = Number(dimension[name]);
} else {
attributes[name] = dimension[name];
}
}
}
var values = "";
if (attributes.values) {
values = attributes.values.join(",");
delete attributes.values;
}
}
var values = "";
if (attributes.values) {
values = attributes.values.join(",");
delete attributes.values;
}
node.appendChild(this.createElementDefaultNS(
"Dimension", values, attributes
));
}
node.appendChild(this.createElementDefaultNS(
"Dimension", values, attributes
));
}
}
return node;
},

View File

@@ -122,7 +122,9 @@ OpenLayers.Format.WMC.v1_1_0 = OpenLayers.Class(
// optional SRS element(s)
if (context.srs) {
for(var name in context.srs) {
node.appendChild(this.createElementDefaultNS("SRS", name));
if (context.srs.hasOwnProperty(name)) {
node.appendChild(this.createElementDefaultNS("SRS", name));
}
}
}

View File

@@ -84,8 +84,10 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.Vers
matrixSet: true
};
for (var prop in required) {
if (!(prop in config)) {
throw new Error("Missing property '" + prop + "' in layer configuration.");
if (required.hasOwnProperty(prop)) {
if (!(prop in config)) {
throw new Error("Missing property '" + prop + "' in layer configuration.");
}
}
}

View File

@@ -89,7 +89,9 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
this.namespaces = OpenLayers.Util.extend({}, this.namespaces);
this.namespaceAlias = {};
for(var alias in this.namespaces) {
this.namespaceAlias[this.namespaces[alias]] = alias;
if (this.namespaces.hasOwnProperty(alias)) {
this.namespaceAlias[this.namespaces[alias]] = alias;
}
}
},
@@ -558,11 +560,13 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
setAttributes: function(node, obj) {
var value, uri;
for(var name in obj) {
if(obj[name] != null && obj[name].toString) {
value = obj[name].toString();
// check for qualified attribute name ("prefix:local")
uri = this.namespaces[name.substring(0, name.indexOf(":"))] || null;
this.setAttributeNS(node, uri, name, value);
if (obj.hasOwnProperty(name)) {
if(obj[name] != null && obj[name].toString) {
value = obj[name].toString();
// check for qualified attribute name ("prefix:local")
uri = this.namespaces[name.substring(0, name.indexOf(":"))] || null;
this.setAttributeNS(node, uri, name, value);
}
}
}
},