Check-24cae389.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './when-e6985d2a'], function (exports, when) { '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 (when.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 (when.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(
  64. "This function defines an interface and should not be called directly."
  65. );
  66. };
  67. /**
  68. * Contains functions for checking that supplied arguments are of a specified type
  69. * or meet specified conditions
  70. * @private
  71. */
  72. var Check = {};
  73. /**
  74. * Contains type checking functions, all using the typeof operator
  75. */
  76. Check.typeOf = {};
  77. function getUndefinedErrorMessage(name) {
  78. return name + " is required, actual value was undefined";
  79. }
  80. function getFailedTypeErrorMessage(actual, expected, name) {
  81. return (
  82. "Expected " +
  83. name +
  84. " to be typeof " +
  85. expected +
  86. ", actual typeof was " +
  87. actual
  88. );
  89. }
  90. /**
  91. * Throws if test is not defined
  92. *
  93. * @param {String} name The name of the variable being tested
  94. * @param {*} test The value that is to be checked
  95. * @exception {DeveloperError} test must be defined
  96. */
  97. Check.defined = function (name, test) {
  98. if (!when.defined(test)) {
  99. throw new DeveloperError(getUndefinedErrorMessage(name));
  100. }
  101. };
  102. /**
  103. * Throws if test is not typeof 'function'
  104. *
  105. * @param {String} name The name of the variable being tested
  106. * @param {*} test The value to test
  107. * @exception {DeveloperError} test must be typeof 'function'
  108. */
  109. Check.typeOf.func = function (name, test) {
  110. if (typeof test !== "function") {
  111. throw new DeveloperError(
  112. getFailedTypeErrorMessage(typeof test, "function", name)
  113. );
  114. }
  115. };
  116. /**
  117. * Throws if test is not typeof 'string'
  118. *
  119. * @param {String} name The name of the variable being tested
  120. * @param {*} test The value to test
  121. * @exception {DeveloperError} test must be typeof 'string'
  122. */
  123. Check.typeOf.string = function (name, test) {
  124. if (typeof test !== "string") {
  125. throw new DeveloperError(
  126. getFailedTypeErrorMessage(typeof test, "string", name)
  127. );
  128. }
  129. };
  130. /**
  131. * Throws if test is not typeof 'number'
  132. *
  133. * @param {String} name The name of the variable being tested
  134. * @param {*} test The value to test
  135. * @exception {DeveloperError} test must be typeof 'number'
  136. */
  137. Check.typeOf.number = function (name, test) {
  138. if (typeof test !== "number") {
  139. throw new DeveloperError(
  140. getFailedTypeErrorMessage(typeof test, "number", name)
  141. );
  142. }
  143. };
  144. /**
  145. * Throws if test is not typeof 'number' and less than limit
  146. *
  147. * @param {String} name The name of the variable being tested
  148. * @param {*} test The value to test
  149. * @param {Number} limit The limit value to compare against
  150. * @exception {DeveloperError} test must be typeof 'number' and less than limit
  151. */
  152. Check.typeOf.number.lessThan = function (name, test, limit) {
  153. Check.typeOf.number(name, test);
  154. if (test >= limit) {
  155. throw new DeveloperError(
  156. "Expected " +
  157. name +
  158. " to be less than " +
  159. limit +
  160. ", actual value was " +
  161. test
  162. );
  163. }
  164. };
  165. /**
  166. * Throws if test is not typeof 'number' and less than or equal to limit
  167. *
  168. * @param {String} name The name of the variable being tested
  169. * @param {*} test The value to test
  170. * @param {Number} limit The limit value to compare against
  171. * @exception {DeveloperError} test must be typeof 'number' and less than or equal to limit
  172. */
  173. Check.typeOf.number.lessThanOrEquals = function (name, test, limit) {
  174. Check.typeOf.number(name, test);
  175. if (test > limit) {
  176. throw new DeveloperError(
  177. "Expected " +
  178. name +
  179. " to be less than or equal to " +
  180. limit +
  181. ", actual value was " +
  182. test
  183. );
  184. }
  185. };
  186. /**
  187. * Throws if test is not typeof 'number' and greater than limit
  188. *
  189. * @param {String} name The name of the variable being tested
  190. * @param {*} test The value to test
  191. * @param {Number} limit The limit value to compare against
  192. * @exception {DeveloperError} test must be typeof 'number' and greater than limit
  193. */
  194. Check.typeOf.number.greaterThan = function (name, test, limit) {
  195. Check.typeOf.number(name, test);
  196. if (test <= limit) {
  197. throw new DeveloperError(
  198. "Expected " +
  199. name +
  200. " to be greater than " +
  201. limit +
  202. ", actual value was " +
  203. test
  204. );
  205. }
  206. };
  207. /**
  208. * Throws if test is not typeof 'number' and greater than or equal to limit
  209. *
  210. * @param {String} name The name of the variable being tested
  211. * @param {*} test The value to test
  212. * @param {Number} limit The limit value to compare against
  213. * @exception {DeveloperError} test must be typeof 'number' and greater than or equal to limit
  214. */
  215. Check.typeOf.number.greaterThanOrEquals = function (name, test, limit) {
  216. Check.typeOf.number(name, test);
  217. if (test < limit) {
  218. throw new DeveloperError(
  219. "Expected " +
  220. name +
  221. " to be greater than or equal to" +
  222. limit +
  223. ", actual value was " +
  224. test
  225. );
  226. }
  227. };
  228. /**
  229. * Throws if test is not typeof 'object'
  230. *
  231. * @param {String} name The name of the variable being tested
  232. * @param {*} test The value to test
  233. * @exception {DeveloperError} test must be typeof 'object'
  234. */
  235. Check.typeOf.object = function (name, test) {
  236. if (typeof test !== "object") {
  237. throw new DeveloperError(
  238. getFailedTypeErrorMessage(typeof test, "object", name)
  239. );
  240. }
  241. };
  242. /**
  243. * Throws if test is not typeof 'boolean'
  244. *
  245. * @param {String} name The name of the variable being tested
  246. * @param {*} test The value to test
  247. * @exception {DeveloperError} test must be typeof 'boolean'
  248. */
  249. Check.typeOf.bool = function (name, test) {
  250. if (typeof test !== "boolean") {
  251. throw new DeveloperError(
  252. getFailedTypeErrorMessage(typeof test, "boolean", name)
  253. );
  254. }
  255. };
  256. /**
  257. * Throws if test1 and test2 is not typeof 'number' and not equal in value
  258. *
  259. * @param {String} name1 The name of the first variable being tested
  260. * @param {String} name2 The name of the second variable being tested against
  261. * @param {*} test1 The value to test
  262. * @param {*} test2 The value to test against
  263. * @exception {DeveloperError} test1 and test2 should be type of 'number' and be equal in value
  264. */
  265. Check.typeOf.number.equals = function (name1, name2, test1, test2) {
  266. Check.typeOf.number(name1, test1);
  267. Check.typeOf.number(name2, test2);
  268. if (test1 !== test2) {
  269. throw new DeveloperError(
  270. name1 +
  271. " must be equal to " +
  272. name2 +
  273. ", the actual values are " +
  274. test1 +
  275. " and " +
  276. test2
  277. );
  278. }
  279. };
  280. exports.Check = Check;
  281. exports.DeveloperError = DeveloperError;
  282. });