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:
Andreas Hocevar
2016-07-19 16:39:58 +02:00
parent f50f1f401c
commit 6f5ed17fc5
158 changed files with 1488 additions and 1629 deletions
+7 -11
View File
@@ -1,7 +1,6 @@
goog.provide('ol.style.Atlas');
goog.provide('ol.style.AtlasManager');
goog.require('goog.asserts');
goog.require('ol');
goog.require('ol.dom');
@@ -85,9 +84,7 @@ ol.style.AtlasManager.prototype.getInfo = function(id) {
if (!info) {
return null;
}
/** @type {?ol.AtlasInfo} */
var hitInfo = this.getInfo_(this.hitAtlases_, id);
goog.asserts.assert(hitInfo, 'hitInfo must not be null');
var hitInfo = /** @type {ol.AtlasInfo} */ (this.getInfo_(this.hitAtlases_, id));
return this.mergeInfos_(info, hitInfo);
};
@@ -122,9 +119,9 @@ ol.style.AtlasManager.prototype.getInfo_ = function(atlases, id) {
* entry, or `null` if the entry is not part of the atlases.
*/
ol.style.AtlasManager.prototype.mergeInfos_ = function(info, hitInfo) {
goog.asserts.assert(info.offsetX === hitInfo.offsetX,
ol.DEBUG && console.assert(info.offsetX === hitInfo.offsetX,
'in order to merge, offsetX of info and hitInfo must be equal');
goog.asserts.assert(info.offsetY === hitInfo.offsetY,
ol.DEBUG && console.assert(info.offsetY === hitInfo.offsetY,
'in order to merge, offsetY of info and hitInfo must be equal');
return /** @type {ol.AtlasManagerInfo} */ ({
offsetX: info.offsetX,
@@ -177,10 +174,8 @@ ol.style.AtlasManager.prototype.add = function(id, width, height,
var renderHitCallback = opt_renderHitCallback !== undefined ?
opt_renderHitCallback : ol.nullFunction;
/** @type {?ol.AtlasInfo} */
var hitInfo = this.add_(true,
id, width, height, renderHitCallback, opt_this);
goog.asserts.assert(hitInfo, 'hitInfo must not be null');
var hitInfo = /** @type {ol.AtlasInfo} */ (this.add_(true,
id, width, height, renderHitCallback, opt_this));
return this.mergeInfos_(info, hitInfo);
};
@@ -225,7 +220,8 @@ ol.style.AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height,
++ii;
}
}
goog.asserts.fail('Failed to add to atlasmanager');
ol.DEBUG && console.assert(false, 'Failed to add to atlasmanager');
return null;
};
+1 -2
View File
@@ -1,6 +1,5 @@
goog.provide('ol.style.Circle');
goog.require('goog.asserts');
goog.require('ol');
goog.require('ol.color');
goog.require('ol.colorlike');
@@ -289,7 +288,7 @@ ol.style.Circle.prototype.render_ = function(atlasManager) {
var info = atlasManager.add(
id, size, size, this.draw_.bind(this, renderOptions),
renderHitDetectionCallback);
goog.asserts.assert(info, 'circle radius is too large');
ol.DEBUG && console.assert(info, 'circle radius is too large');
this.canvas_ = info.image;
this.origin_ = [info.offsetX, info.offsetY];
+12 -14
View File
@@ -3,7 +3,6 @@ goog.provide('ol.style.IconAnchorUnits');
goog.provide('ol.style.IconImageCache');
goog.provide('ol.style.IconOrigin');
goog.require('goog.asserts');
goog.require('ol.events');
goog.require('ol.events.EventTarget');
goog.require('ol.events.EventType');
@@ -102,17 +101,16 @@ ol.style.Icon = function(opt_options) {
*/
var src = options.src;
goog.asserts.assert(!(src !== undefined && image),
'image and src can not provided at the same time');
goog.asserts.assert(
!image || (image && imgSize),
'imgSize must be set when image is provided');
ol.assert(!(src !== undefined && image),
4); // `image` and `src` cannot be provided at the same time
ol.assert(!image || (image && imgSize),
5); // `imgSize` must be set when `image` is provided
if ((src === undefined || src.length === 0) && image) {
src = image.src || ol.getUid(image).toString();
}
goog.asserts.assert(src !== undefined && src.length > 0,
'must provide a defined and non-empty src or image');
ol.assert(src !== undefined && src.length > 0,
6); // A defined and non-empty `src` or `image` must be provided
/**
* @type {ol.style.ImageState}
@@ -131,7 +129,7 @@ ol.style.Icon = function(opt_options) {
* @type {ol.style.IconImage_}
*/
this.iconImage_ = ol.style.IconImage_.get(
image, src, imgSize, crossOrigin, imageState, color);
image, /** @type {string} */ (src), imgSize, crossOrigin, imageState, color);
/**
* @private
@@ -578,9 +576,9 @@ ol.style.IconImage_.prototype.getSrc = function() {
*/
ol.style.IconImage_.prototype.load = function() {
if (this.imageState_ == ol.style.ImageState.IDLE) {
goog.asserts.assert(this.src_ !== undefined,
ol.DEBUG && console.assert(this.src_ !== undefined,
'this.src_ must not be undefined');
goog.asserts.assert(!this.imageListenerKeys_,
ol.DEBUG && console.assert(!this.imageListenerKeys_,
'no listener keys existing');
this.imageState_ = ol.style.ImageState.LOADING;
this.imageListenerKeys_ = [
@@ -606,7 +604,7 @@ ol.style.IconImage_.prototype.replaceColor_ = function() {
return;
}
goog.asserts.assert(this.canvas_ !== null,
ol.DEBUG && console.assert(this.canvas_ !== null,
'this.canvas_ must not be null');
this.canvas_.width = this.image_.width;
@@ -636,7 +634,7 @@ ol.style.IconImage_.prototype.replaceColor_ = function() {
* @private
*/
ol.style.IconImage_.prototype.unlistenImage_ = function() {
goog.asserts.assert(this.imageListenerKeys_,
ol.DEBUG && console.assert(this.imageListenerKeys_,
'we must have listeners registered');
this.imageListenerKeys_.forEach(ol.events.unlistenByKey);
this.imageListenerKeys_ = null;
@@ -677,7 +675,7 @@ goog.addSingletonGetter(ol.style.IconImageCache);
* @return {string} Cache key.
*/
ol.style.IconImageCache.getKey = function(src, crossOrigin, color) {
goog.asserts.assert(crossOrigin !== undefined,
ol.DEBUG && console.assert(crossOrigin !== undefined,
'argument crossOrigin must be defined');
var colorString = color ? ol.color.asString(color) : 'null';
return crossOrigin + ':' + src + ':' + colorString;
+2 -3
View File
@@ -1,6 +1,5 @@
goog.provide('ol.style.RegularShape');
goog.require('goog.asserts');
goog.require('ol');
goog.require('ol.color');
goog.require('ol.colorlike');
@@ -27,7 +26,7 @@ goog.require('ol.style.Stroke');
*/
ol.style.RegularShape = function(options) {
goog.asserts.assert(
ol.DEBUG && console.assert(
options.radius !== undefined || options.radius1 !== undefined,
'must provide either "radius" or "radius1"');
@@ -367,7 +366,7 @@ ol.style.RegularShape.prototype.render_ = function(atlasManager) {
var info = atlasManager.add(
id, size, size, this.draw_.bind(this, renderOptions),
renderHitDetectionCallback);
goog.asserts.assert(info, 'shape size is too large');
ol.DEBUG && console.assert(info, 'shape size is too large');
this.canvas_ = info.image;
this.origin_ = [info.offsetX, info.offsetY];
+5 -13
View File
@@ -1,6 +1,5 @@
goog.provide('ol.style.Style');
goog.require('goog.asserts');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.GeometryType');
goog.require('ol.style.Circle');
@@ -159,20 +158,13 @@ ol.style.Style.prototype.setGeometry = function(geometry) {
this.geometryFunction_ = geometry;
} else if (typeof geometry === 'string') {
this.geometryFunction_ = function(feature) {
var result = feature.get(geometry);
if (result) {
goog.asserts.assertInstanceof(result, ol.geom.Geometry,
'feature geometry must be an ol.geom.Geometry instance');
}
return result;
return /** @type {ol.geom.Geometry} */ (feature.get(geometry));
};
} else if (!geometry) {
this.geometryFunction_ = ol.style.defaultGeometryFunction;
} else if (geometry !== undefined) {
goog.asserts.assertInstanceof(geometry, ol.geom.Geometry,
'geometry must be an ol.geom.Geometry instance');
this.geometryFunction_ = function() {
return geometry;
return /** @type {ol.geom.Geometry} */ (geometry);
};
}
this.geometry_ = geometry;
@@ -211,8 +203,8 @@ ol.style.createStyleFunction = function(obj) {
if (Array.isArray(obj)) {
styles = obj;
} else {
goog.asserts.assertInstanceof(obj, ol.style.Style,
'obj geometry must be an ol.style.Style instance');
ol.assert(obj instanceof ol.style.Style,
41); // Expected an `ol.style.Style` or an array of `ol.style.Style`
styles = [obj];
}
styleFunction = function() {
@@ -343,6 +335,6 @@ ol.style.createDefaultEditingStyles = function() {
* @return {ol.geom.Geometry|ol.render.Feature|undefined} Geometry to render.
*/
ol.style.defaultGeometryFunction = function(feature) {
goog.asserts.assert(feature, 'feature must not be null');
ol.DEBUG && console.assert(feature, 'feature must not be null');
return feature.getGeometry();
};