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

View File

@@ -2,7 +2,6 @@
goog.provide('ol.control.Attribution');
goog.require('goog.asserts');
goog.require('ol');
goog.require('ol.dom');
goog.require('ol.Attribution');
@@ -11,7 +10,6 @@ goog.require('ol.css');
goog.require('ol.events');
goog.require('ol.events.EventType');
goog.require('ol.object');
goog.require('ol.source.Tile');
/**
@@ -160,8 +158,7 @@ ol.control.Attribution.prototype.getSourceAttributions = function(frameState) {
var attributions = ol.object.assign({}, frameState.attributions);
/** @type {Object.<string, ol.Attribution>} */
var hiddenAttributions = {};
var projection = frameState.viewState.projection;
goog.asserts.assert(projection, 'projection of viewState required');
var projection = /** @type {!ol.proj.Projection} */ (frameState.viewState.projection);
for (i = 0, ii = layerStatesArray.length; i < ii; i++) {
source = layerStatesArray[i].layer.getSource();
if (!source) {
@@ -180,10 +177,7 @@ ol.control.Attribution.prototype.getSourceAttributions = function(frameState) {
}
tileRanges = frameState.usedTiles[sourceKey];
if (tileRanges) {
goog.asserts.assertInstanceof(source, ol.source.Tile,
'source should be an ol.source.Tile');
var tileGrid = source.getTileGridForProjection(projection);
goog.asserts.assert(tileGrid, 'tileGrid required for projection');
var tileGrid = /** @type {ol.source.Tile} */ (source).getTileGridForProjection(projection);
intersectsTileRange = sourceAttribution.intersectsAnyTileRange(
tileRanges, tileGrid, projection);
} else {

View File

@@ -1,6 +1,5 @@
goog.provide('ol.control.FullScreen');
goog.require('goog.asserts');
goog.require('ol.events');
goog.require('ol.events.EventType');
goog.require('ol');
@@ -125,7 +124,6 @@ ol.control.FullScreen.prototype.handleFullScreen_ = function() {
} else {
element = map.getTargetElement();
}
goog.asserts.assert(element, 'element should be defined');
if (this.keys_) {
ol.control.FullScreen.requestFullScreenWithKeys(element);

View File

@@ -1,6 +1,5 @@
goog.provide('ol.control.OverviewMap');
goog.require('goog.asserts');
goog.require('ol.events');
goog.require('ol.events.EventType');
goog.require('ol');
@@ -272,18 +271,14 @@ ol.control.OverviewMap.prototype.validateExtent_ = function() {
return;
}
var mapSize = map.getSize();
goog.asserts.assertArray(mapSize, 'mapSize should be an array');
var mapSize = /** @type {ol.Size} */ (map.getSize());
var view = map.getView();
goog.asserts.assert(view, 'view should be defined');
var extent = view.calculateExtent(mapSize);
var ovmapSize = ovmap.getSize();
goog.asserts.assertArray(ovmapSize, 'ovmapSize should be an array');
var ovmapSize = /** @type {ol.Size} */ (ovmap.getSize());
var ovview = ovmap.getView();
goog.asserts.assert(ovview, 'ovview should be defined');
var ovextent = ovview.calculateExtent(ovmapSize);
var topLeftPixel =
@@ -321,18 +316,14 @@ ol.control.OverviewMap.prototype.resetExtent_ = function() {
var map = this.getMap();
var ovmap = this.ovmap_;
var mapSize = map.getSize();
goog.asserts.assertArray(mapSize, 'mapSize should be an array');
var mapSize = /** @type {ol.Size} */ (map.getSize());
var view = map.getView();
goog.asserts.assert(view, 'view should be defined');
var extent = view.calculateExtent(mapSize);
var ovmapSize = ovmap.getSize();
goog.asserts.assertArray(ovmapSize, 'ovmapSize should be an array');
var ovmapSize = /** @type {ol.Size} */ (ovmap.getSize());
var ovview = ovmap.getView();
goog.asserts.assert(ovview, 'ovview should be defined');
// get how many times the current map overview could hold different
// box sizes using the min and max ratio, pick the step in the middle used
@@ -355,10 +346,8 @@ ol.control.OverviewMap.prototype.recenter_ = function() {
var ovmap = this.ovmap_;
var view = map.getView();
goog.asserts.assert(view, 'view should be defined');
var ovview = ovmap.getView();
goog.asserts.assert(ovview, 'ovview should be defined');
ovview.setCenter(view.getCenter());
};
@@ -376,20 +365,15 @@ ol.control.OverviewMap.prototype.updateBox_ = function() {
return;
}
var mapSize = map.getSize();
goog.asserts.assertArray(mapSize, 'mapSize should be an array');
var mapSize = /** @type {ol.Size} */ (map.getSize());
var view = map.getView();
goog.asserts.assert(view, 'view should be defined');
var ovview = ovmap.getView();
goog.asserts.assert(ovview, 'ovview should be defined');
var ovmapSize = ovmap.getSize();
goog.asserts.assertArray(ovmapSize, 'ovmapSize should be an array');
var rotation = view.getRotation();
goog.asserts.assert(rotation !== undefined, 'rotation should be defined');
var overlay = this.boxOverlay_;
var box = this.boxOverlay_.getElement();
@@ -422,7 +406,6 @@ ol.control.OverviewMap.prototype.calculateCoordinateRotate_ = function(
var map = this.getMap();
var view = map.getView();
goog.asserts.assert(view, 'view should be defined');
var currentCenter = view.getCenter();

View File

@@ -1,7 +1,6 @@
goog.provide('ol.control.ScaleLine');
goog.provide('ol.control.ScaleLineUnits');
goog.require('goog.asserts');
goog.require('ol.events');
goog.require('ol');
goog.require('ol.Object');
@@ -246,7 +245,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
pointResolution /= 1609.3472;
}
} else {
goog.asserts.fail('Scale line element cannot be updated');
ol.assert(false, 33); // Invalid units
}
var i = 3 * Math.floor(

View File

@@ -2,7 +2,6 @@
goog.provide('ol.control.ZoomSlider');
goog.require('goog.asserts');
goog.require('ol.events');
goog.require('ol.events.Event');
goog.require('ol.events.EventType');
@@ -216,8 +215,6 @@ ol.control.ZoomSlider.render = function(mapEvent) {
if (!mapEvent.frameState) {
return;
}
goog.asserts.assert(mapEvent.frameState.viewState,
'viewState should be defined');
if (!this.sliderInitialized_) {
this.initSlider_();
}
@@ -237,10 +234,8 @@ ol.control.ZoomSlider.prototype.handleContainerClick_ = function(event) {
var map = this.getMap();
var view = map.getView();
var currentResolution = view.getResolution();
goog.asserts.assert(currentResolution,
'currentResolution should be defined');
map.beforeRender(ol.animation.zoom({
resolution: currentResolution,
resolution: /** @type {number} */ (currentResolution),
duration: this.duration_,
easing: ol.easing.easeOut
}));
@@ -312,10 +307,8 @@ ol.control.ZoomSlider.prototype.handleDraggerEnd_ = function(event) {
var map = this.getMap();
var view = map.getView();
view.setHint(ol.ViewHint.INTERACTING, -1);
goog.asserts.assert(this.currentResolution_,
'this.currentResolution_ should be defined');
map.beforeRender(ol.animation.zoom({
resolution: this.currentResolution_,
resolution: /** @type {number} */ (this.currentResolution_),
duration: this.duration_,
easing: ol.easing.easeOut
}));

View File

@@ -1,6 +1,5 @@
goog.provide('ol.control.ZoomToExtent');
goog.require('goog.asserts');
goog.require('ol.events');
goog.require('ol.events.EventType');
goog.require('ol.control.Control');
@@ -73,7 +72,6 @@ ol.control.ZoomToExtent.prototype.handleZoomToExtent_ = function() {
var map = this.getMap();
var view = map.getView();
var extent = !this.extent_ ? view.getProjection().getExtent() : this.extent_;
var size = map.getSize();
goog.asserts.assert(size, 'size should be defined');
var size = /** @type {ol.Size} */ (map.getSize());
view.fit(extent, size);
};