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:
@@ -14,6 +14,14 @@ goog.provide('ol');
|
||||
ol.ASSUME_TOUCH = false;
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Debug mode. When set to `false` (recommended for
|
||||
* production), debug assertion checks will be stripped out of the build.
|
||||
* Default is `true`.
|
||||
*/
|
||||
ol.DEBUG = true;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: rename this to something having to do with tile grids
|
||||
* see https://github.com/openlayers/ol3/issues/2076
|
||||
@@ -212,6 +220,12 @@ ol.SIMPLIFY_TOLERANCE = 0.5;
|
||||
ol.WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK = 1024;
|
||||
|
||||
|
||||
/**
|
||||
* @define {string} OpenLayers version.
|
||||
*/
|
||||
ol.VERSION = '';
|
||||
|
||||
|
||||
/**
|
||||
* The maximum supported WebGL texture size in pixels. If WebGL is not
|
||||
* supported, the value is set to `undefined`.
|
||||
@@ -297,3 +311,48 @@ if (typeof window !== 'undefined') {
|
||||
} else if (typeof self !== 'undefined') {
|
||||
ol.global = self;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Error object thrown when an assertion failed. This is an ECMA-262 Error,
|
||||
* extended with a `code` property.
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error}
|
||||
* @constructor
|
||||
* @extends {Error}
|
||||
* @implements {oli.AssertionError}
|
||||
* @param {number} code Error code.
|
||||
*/
|
||||
ol.AssertionError = function(code) {
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.message = 'Assertion failed. See ' +
|
||||
(ol.VERSION ? 'http://openlayers.org/en/' + ol.VERSION.split('-')[0] : '') +
|
||||
'/doc/errors.html#' + code + ' for details.';
|
||||
|
||||
/**
|
||||
* Error code. The meaning of the code can be found on
|
||||
* {@link http://openlayers.org/en/latest/errors.html} (replace `latest` with
|
||||
* the version found in the OpenLayers script's header comment if a version
|
||||
* other than the latest is used).
|
||||
* @type {number}
|
||||
* @api
|
||||
*/
|
||||
this.code = code;
|
||||
|
||||
this.name = 'AssertionError';
|
||||
|
||||
};
|
||||
ol.inherits(ol.AssertionError, Error);
|
||||
|
||||
|
||||
/**
|
||||
* @param {*} assertion Assertion we expected to be truthy.
|
||||
* @param {number} errorCode Error code.
|
||||
*/
|
||||
ol.assert = function(assertion, errorCode) {
|
||||
if (!assertion) {
|
||||
throw new ol.AssertionError(errorCode);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user