Skip to content

Commit

Permalink
Merge pull request #1279 from oslek/isArray
Browse files Browse the repository at this point in the history
Robust array type check for cross-frame support
  • Loading branch information
mourner committed Jan 14, 2013
2 parents a598e2b + 7dd7e4f commit 405bf0c
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/core/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ L.Util = {
});
},

isArray: function (obj) {
return (Object.prototype.toString.call(obj) === '[object Array]');
},

emptyImageUrl: 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
};

Expand Down
2 changes: 1 addition & 1 deletion src/geo/LatLng.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ L.latLng = function (a, b) { // (LatLng) or ([Number, Number]) or (Number, Numbe
if (a instanceof L.LatLng) {
return a;
}
if (a instanceof Array) {
if (L.Util.isArray(a)) {
return new L.LatLng(a[0], a[1]);
}
if (isNaN(a)) {
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/Point.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ L.point = function (x, y, round) {
if (x instanceof L.Point) {
return x;
}
if (x instanceof Array) {
if (L.Util.isArray(x)) {
return new L.Point(x[0], x[1]);
}
if (isNaN(x)) {
Expand Down
2 changes: 1 addition & 1 deletion src/layer/GeoJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ L.GeoJSON = L.FeatureGroup.extend({
},

addData: function (geojson) {
var features = geojson instanceof Array ? geojson : geojson.features,
var features = L.Util.isArray(geojson) ? geojson : geojson.features,
i, len;

if (features) {
Expand Down
2 changes: 1 addition & 1 deletion src/layer/vector/Polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ L.Polygon = L.Polyline.extend({
initialize: function (latlngs, options) {
L.Polyline.prototype.initialize.call(this, latlngs, options);

if (latlngs && (latlngs[0] instanceof Array) && (typeof latlngs[0][0] !== 'number')) {
if (latlngs && L.Util.isArray(latlngs[0]) && (typeof latlngs[0][0] !== 'number')) {
this._latlngs = this._convertLatLngs(latlngs[0]);
this._holes = latlngs.slice(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/layer/vector/Polyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ L.Polyline = L.Path.extend({
_convertLatLngs: function (latlngs) {
var i, len;
for (i = 0, len = latlngs.length; i < len; i++) {
if (latlngs[i] instanceof Array && typeof latlngs[i][0] !== 'number') {
if (L.Util.isArray(latlngs[i]) && typeof latlngs[i][0] !== 'number') {
return;
}
latlngs[i] = L.latLng(latlngs[i]);
Expand Down
2 changes: 1 addition & 1 deletion src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ L.Map = L.Class.extend({
},

_initLayers: function (layers) {
layers = layers ? (layers instanceof Array ? layers : [layers]) : [];
layers = layers ? (L.Util.isArray(layers) ? layers : [layers]) : [];

this._layers = {};
this._zoomBoundLayers = {};
Expand Down

0 comments on commit 405bf0c

Please sign in to comment.