Check-da037458.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defined-26bd4a03'], function (exports, defined) { 'use strict';
  3. /**
  4. * Constructs an exception object that is thrown due to a developer error, e.g., invalid argument,
  5. * argument out of range, etc. This exception should only be thrown during development;
  6. * it usually indicates a bug in the calling code. This exception should never be
  7. * caught; instead the calling code should strive not to generate it.
  8. * <br /><br />
  9. * On the other hand, a {@link RuntimeError} indicates an exception that may
  10. * be thrown at runtime, e.g., out of memory, that the calling code should be prepared
  11. * to catch.
  12. *
  13. * @alias DeveloperError
  14. * @constructor
  15. * @extends Error
  16. *
  17. * @param {String} [message] The error message for this exception.
  18. *
  19. * @see RuntimeError
  20. */
  21. function DeveloperError(message) {
  22. /**
  23. * 'DeveloperError' indicating that this exception was thrown due to a developer error.
  24. * @type {String}
  25. * @readonly
  26. */
  27. this.name = 'DeveloperError';
  28. /**
  29. * The explanation for why this exception was thrown.
  30. * @type {String}
  31. * @readonly
  32. */
  33. this.message = message;
  34. //Browsers such as IE don't have a stack property until you actually throw the error.
  35. var stack;
  36. try {
  37. throw new Error();
  38. } catch (e) {
  39. stack = e.stack;
  40. }
  41. /**
  42. * The stack trace of this exception, if available.
  43. * @type {String}
  44. * @readonly
  45. */
  46. this.stack = stack;
  47. }
  48. if (defined.defined(Object.create)) {
  49. DeveloperError.prototype = Object.create(Error.prototype);
  50. DeveloperError.prototype.constructor = DeveloperError;
  51. }
  52. DeveloperError.prototype.toString = function() {
  53. var str = this.name + ': ' + this.message;
  54. if (defined.defined(this.stack)) {
  55. str += '\n' + this.stack.toString();
  56. }
  57. return str;
  58. };
  59. /**
  60. * @private
  61. */
  62. DeveloperError.throwInstantiationError = function() {
  63. throw new DeveloperError('This function defines an interface and should not be called directly.');
  64. };
  65. /**
  66. * Contains functions for checking that supplied arguments are of a specified type
  67. * or meet specified conditions
  68. * @private
  69. */
  70. var Check = {};
  71. /**
  72. * Contains type checking functions, all using the typeof operator
  73. */
  74. Check.typeOf = {};
  75. function getUndefinedErrorMessage(name) {
  76. return name + ' is required, actual value was undefined';
  77. }
  78. function getFailedTypeErrorMessage(actual, expected, name) {
  79. return 'Expected ' + name + ' to be typeof ' + expected + ', actual typeof was ' + actual;
  80. }
  81. /**
  82. * Throws if test is not defined
  83. *
  84. * @param {String} name The name of the variable being tested
  85. * @param {*} test The value that is to be checked
  86. * @exception {DeveloperError} test must be defined
  87. */
  88. Check.defined = function (name, test) {
  89. if (!defined.defined(test)) {
  90. throw new DeveloperError(getUndefinedErrorMessage(name));
  91. }
  92. };
  93. /**
  94. * Throws if test is not typeof 'function'
  95. *
  96. * @param {String} name The name of the variable being tested
  97. * @param {*} test The value to test
  98. * @exception {DeveloperError} test must be typeof 'function'
  99. */
  100. Check.typeOf.func = function (name, test) {
  101. if (typeof test !== 'function') {
  102. throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'function', name));
  103. }
  104. };
  105. /**
  106. * Throws if test is not typeof 'string'
  107. *
  108. * @param {String} name The name of the variable being tested
  109. * @param {*} test The value to test
  110. * @exception {DeveloperError} test must be typeof 'string'
  111. */
  112. Check.typeOf.string = function (name, test) {
  113. if (typeof test !== 'string') {
  114. throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'string', name));
  115. }
  116. };
  117. /**
  118. * Throws if test is not typeof 'number'
  119. *
  120. * @param {String} name The name of the variable being tested
  121. * @param {*} test The value to test
  122. * @exception {DeveloperError} test must be typeof 'number'
  123. */
  124. Check.typeOf.number = function (name, test) {
  125. if (typeof test !== 'number') {
  126. throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'number', name));
  127. }
  128. };
  129. /**
  130. * Throws if test is not typeof 'number' and less than limit
  131. *
  132. * @param {String} name The name of the variable being tested
  133. * @param {*} test The value to test
  134. * @param {Number} limit The limit value to compare against
  135. * @exception {DeveloperError} test must be typeof 'number' and less than limit
  136. */
  137. Check.typeOf.number.lessThan = function (name, test, limit) {
  138. Check.typeOf.number(name, test);
  139. if (test >= limit) {
  140. throw new DeveloperError('Expected ' + name + ' to be less than ' + limit + ', actual value was ' + test);
  141. }
  142. };
  143. /**
  144. * Throws if test is not typeof 'number' and less than or equal to limit
  145. *
  146. * @param {String} name The name of the variable being tested
  147. * @param {*} test The value to test
  148. * @param {Number} limit The limit value to compare against
  149. * @exception {DeveloperError} test must be typeof 'number' and less than or equal to limit
  150. */
  151. Check.typeOf.number.lessThanOrEquals = function (name, test, limit) {
  152. Check.typeOf.number(name, test);
  153. if (test > limit) {
  154. throw new DeveloperError('Expected ' + name + ' to be less than or equal to ' + limit + ', actual value was ' + test);
  155. }
  156. };
  157. /**
  158. * Throws if test is not typeof 'number' and greater than limit
  159. *
  160. * @param {String} name The name of the variable being tested
  161. * @param {*} test The value to test
  162. * @param {Number} limit The limit value to compare against
  163. * @exception {DeveloperError} test must be typeof 'number' and greater than limit
  164. */
  165. Check.typeOf.number.greaterThan = function (name, test, limit) {
  166. Check.typeOf.number(name, test);
  167. if (test <= limit) {
  168. throw new DeveloperError('Expected ' + name + ' to be greater than ' + limit + ', actual value was ' + test);
  169. }
  170. };
  171. /**
  172. * Throws if test is not typeof 'number' and greater than or equal to limit
  173. *
  174. * @param {String} name The name of the variable being tested
  175. * @param {*} test The value to test
  176. * @param {Number} limit The limit value to compare against
  177. * @exception {DeveloperError} test must be typeof 'number' and greater than or equal to limit
  178. */
  179. Check.typeOf.number.greaterThanOrEquals = function (name, test, limit) {
  180. Check.typeOf.number(name, test);
  181. if (test < limit) {
  182. throw new DeveloperError('Expected ' + name + ' to be greater than or equal to' + limit + ', actual value was ' + test);
  183. }
  184. };
  185. /**
  186. * Throws if test is not typeof 'object'
  187. *
  188. * @param {String} name The name of the variable being tested
  189. * @param {*} test The value to test
  190. * @exception {DeveloperError} test must be typeof 'object'
  191. */
  192. Check.typeOf.object = function (name, test) {
  193. if (typeof test !== 'object') {
  194. throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'object', name));
  195. }
  196. };
  197. /**
  198. * Throws if test is not typeof 'boolean'
  199. *
  200. * @param {String} name The name of the variable being tested
  201. * @param {*} test The value to test
  202. * @exception {DeveloperError} test must be typeof 'boolean'
  203. */
  204. Check.typeOf.bool = function (name, test) {
  205. if (typeof test !== 'boolean') {
  206. throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'boolean', name));
  207. }
  208. };
  209. /**
  210. * Throws if test1 and test2 is not typeof 'number' and not equal in value
  211. *
  212. * @param {String} name1 The name of the first variable being tested
  213. * @param {String} name2 The name of the second variable being tested against
  214. * @param {*} test1 The value to test
  215. * @param {*} test2 The value to test against
  216. * @exception {DeveloperError} test1 and test2 should be type of 'number' and be equal in value
  217. */
  218. Check.typeOf.number.equals = function (name1, name2, test1, test2) {
  219. Check.typeOf.number(name1, test1);
  220. Check.typeOf.number(name2, test2);
  221. if (test1 !== test2) {
  222. throw new DeveloperError(name1 + ' must be equal to ' + name2 + ', the actual values are ' + test1 + ' and ' + test2);
  223. }
  224. };
  225. exports.Check = Check;
  226. exports.DeveloperError = DeveloperError;
  227. });