Remove goog.asserts.*
This pull requests replaces type check hint assertions with type casts, library sanity check assertions with conditional console.assert statements in debug mode, and runtime sanity checks with assertions that throw an ol.AssertionError with an error code for lookup outside the library.
This commit is contained in:
+20
-44
@@ -5,7 +5,6 @@
|
||||
goog.provide('ol.Map');
|
||||
goog.provide('ol.MapProperty');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.async.nextTick');
|
||||
goog.require('ol.Collection');
|
||||
goog.require('ol.CollectionEventType');
|
||||
@@ -15,7 +14,6 @@ goog.require('ol.MapBrowserEventHandler');
|
||||
goog.require('ol.MapEvent');
|
||||
goog.require('ol.MapEventType');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.ObjectEvent');
|
||||
goog.require('ol.ObjectEventType');
|
||||
goog.require('ol.RendererType');
|
||||
goog.require('ol.TileQueue');
|
||||
@@ -481,7 +479,7 @@ ol.inherits(ol.Map, ol.Object);
|
||||
*/
|
||||
ol.Map.prototype.addControl = function(control) {
|
||||
var controls = this.getControls();
|
||||
goog.asserts.assert(controls !== undefined, 'controls should be defined');
|
||||
ol.DEBUG && console.assert(controls !== undefined, 'controls should be defined');
|
||||
controls.push(control);
|
||||
};
|
||||
|
||||
@@ -493,7 +491,7 @@ ol.Map.prototype.addControl = function(control) {
|
||||
*/
|
||||
ol.Map.prototype.addInteraction = function(interaction) {
|
||||
var interactions = this.getInteractions();
|
||||
goog.asserts.assert(interactions !== undefined,
|
||||
ol.DEBUG && console.assert(interactions !== undefined,
|
||||
'interactions should be defined');
|
||||
interactions.push(interaction);
|
||||
};
|
||||
@@ -519,7 +517,7 @@ ol.Map.prototype.addLayer = function(layer) {
|
||||
*/
|
||||
ol.Map.prototype.addOverlay = function(overlay) {
|
||||
var overlays = this.getOverlays();
|
||||
goog.asserts.assert(overlays !== undefined, 'overlays should be defined');
|
||||
ol.DEBUG && console.assert(overlays !== undefined, 'overlays should be defined');
|
||||
overlays.push(overlay);
|
||||
};
|
||||
|
||||
@@ -976,7 +974,7 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
|
||||
this.focus_ = mapBrowserEvent.coordinate;
|
||||
mapBrowserEvent.frameState = this.frameState_;
|
||||
var interactions = this.getInteractions();
|
||||
goog.asserts.assert(interactions !== undefined,
|
||||
ol.DEBUG && console.assert(interactions !== undefined,
|
||||
'interactions should be defined');
|
||||
var interactionsArray = interactions.getArray();
|
||||
var i;
|
||||
@@ -1061,7 +1059,7 @@ ol.Map.prototype.handleTargetChanged_ = function() {
|
||||
var targetElement;
|
||||
if (this.getTarget()) {
|
||||
targetElement = this.getTargetElement();
|
||||
goog.asserts.assert(targetElement !== null,
|
||||
ol.DEBUG && console.assert(targetElement !== null,
|
||||
'expects a non-null value for targetElement');
|
||||
}
|
||||
|
||||
@@ -1138,28 +1136,6 @@ ol.Map.prototype.handleViewChanged_ = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.events.Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
ol.Map.prototype.handleLayerGroupMemberChanged_ = function(event) {
|
||||
goog.asserts.assertInstanceof(event, ol.events.Event,
|
||||
'event should be an Event');
|
||||
this.render();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.ObjectEvent} event Event.
|
||||
* @private
|
||||
*/
|
||||
ol.Map.prototype.handleLayerGroupPropertyChanged_ = function(event) {
|
||||
goog.asserts.assertInstanceof(event, ol.ObjectEvent,
|
||||
'event should be an ol.ObjectEvent');
|
||||
this.render();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -1173,10 +1149,10 @@ ol.Map.prototype.handleLayerGroupChanged_ = function() {
|
||||
this.layerGroupPropertyListenerKeys_ = [
|
||||
ol.events.listen(
|
||||
layerGroup, ol.ObjectEventType.PROPERTYCHANGE,
|
||||
this.handleLayerGroupPropertyChanged_, this),
|
||||
this.render, this),
|
||||
ol.events.listen(
|
||||
layerGroup, ol.events.EventType.CHANGE,
|
||||
this.handleLayerGroupMemberChanged_, this)
|
||||
this.render, this)
|
||||
];
|
||||
}
|
||||
this.render();
|
||||
@@ -1224,7 +1200,7 @@ ol.Map.prototype.render = function() {
|
||||
*/
|
||||
ol.Map.prototype.removeControl = function(control) {
|
||||
var controls = this.getControls();
|
||||
goog.asserts.assert(controls !== undefined, 'controls should be defined');
|
||||
ol.DEBUG && console.assert(controls !== undefined, 'controls should be defined');
|
||||
return controls.remove(control);
|
||||
};
|
||||
|
||||
@@ -1238,7 +1214,7 @@ ol.Map.prototype.removeControl = function(control) {
|
||||
*/
|
||||
ol.Map.prototype.removeInteraction = function(interaction) {
|
||||
var interactions = this.getInteractions();
|
||||
goog.asserts.assert(interactions !== undefined,
|
||||
ol.DEBUG && console.assert(interactions !== undefined,
|
||||
'interactions should be defined');
|
||||
return interactions.remove(interaction);
|
||||
};
|
||||
@@ -1266,7 +1242,7 @@ ol.Map.prototype.removeLayer = function(layer) {
|
||||
*/
|
||||
ol.Map.prototype.removeOverlay = function(overlay) {
|
||||
var overlays = this.getOverlays();
|
||||
goog.asserts.assert(overlays !== undefined, 'overlays should be defined');
|
||||
ol.DEBUG && console.assert(overlays !== undefined, 'overlays should be defined');
|
||||
return overlays.remove(overlay);
|
||||
};
|
||||
|
||||
@@ -1486,9 +1462,9 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
logos[logo] = '';
|
||||
} else if (logo instanceof HTMLElement) {
|
||||
logos[ol.getUid(logo).toString()] = logo;
|
||||
} else if (logo !== null) {
|
||||
goog.asserts.assertString(logo.href, 'logo.href should be a string');
|
||||
goog.asserts.assertString(logo.src, 'logo.src should be a string');
|
||||
} else if (logo) {
|
||||
ol.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
|
||||
ol.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
|
||||
logos[logo.src] = logo.href;
|
||||
}
|
||||
}
|
||||
@@ -1517,7 +1493,7 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
} else if (typeof options.renderer === 'string') {
|
||||
rendererTypes = [options.renderer];
|
||||
} else {
|
||||
goog.asserts.fail('Incorrect format for renderer option');
|
||||
ol.assert(false, 46); // Incorrect format for `renderer` option
|
||||
}
|
||||
} else {
|
||||
rendererTypes = ol.DEFAULT_RENDERER_TYPES;
|
||||
@@ -1550,8 +1526,8 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
if (Array.isArray(options.controls)) {
|
||||
controls = new ol.Collection(options.controls.slice());
|
||||
} else {
|
||||
goog.asserts.assertInstanceof(options.controls, ol.Collection,
|
||||
'options.controls should be an ol.Collection');
|
||||
ol.assert(options.controls instanceof ol.Collection,
|
||||
47); // Expected `controls` to be an array or an `ol.Collection`
|
||||
controls = options.controls;
|
||||
}
|
||||
} else {
|
||||
@@ -1563,8 +1539,8 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
if (Array.isArray(options.interactions)) {
|
||||
interactions = new ol.Collection(options.interactions.slice());
|
||||
} else {
|
||||
goog.asserts.assertInstanceof(options.interactions, ol.Collection,
|
||||
'options.interactions should be an ol.Collection');
|
||||
ol.assert(options.interactions instanceof ol.Collection,
|
||||
48); // Expected `interactions` to be an array or an `ol.Collection`
|
||||
interactions = options.interactions;
|
||||
}
|
||||
} else {
|
||||
@@ -1576,8 +1552,8 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
if (Array.isArray(options.overlays)) {
|
||||
overlays = new ol.Collection(options.overlays.slice());
|
||||
} else {
|
||||
goog.asserts.assertInstanceof(options.overlays, ol.Collection,
|
||||
'options.overlays should be an ol.Collection');
|
||||
ol.assert(options.overlays instanceof ol.Collection,
|
||||
49); // Expected `overlays` to be an array or an `ol.Collection`
|
||||
overlays = options.overlays;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user