RuntimeError-c581ca93.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defaultValue-94c3e563'], (function (exports, defaultValue) { '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. let 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 (defaultValue.defined(Object.create)) {
  49. DeveloperError.prototype = Object.create(Error.prototype);
  50. DeveloperError.prototype.constructor = DeveloperError;
  51. }
  52. DeveloperError.prototype.toString = function () {
  53. let str = `${this.name}: ${this.message}`;
  54. if (defaultValue.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. const 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 `Expected ${name} to be typeof ${expected}, actual typeof was ${actual}`;
  82. }
  83. /**
  84. * Throws if test is not defined
  85. *
  86. * @param {String} name The name of the variable being tested
  87. * @param {*} test The value that is to be checked
  88. * @exception {DeveloperError} test must be defined
  89. */
  90. Check.defined = function (name, test) {
  91. if (!defaultValue.defined(test)) {
  92. throw new DeveloperError(getUndefinedErrorMessage(name));
  93. }
  94. };
  95. /**
  96. * Throws if test is not typeof 'function'
  97. *
  98. * @param {String} name The name of the variable being tested
  99. * @param {*} test The value to test
  100. * @exception {DeveloperError} test must be typeof 'function'
  101. */
  102. Check.typeOf.func = function (name, test) {
  103. if (typeof test !== "function") {
  104. throw new DeveloperError(
  105. getFailedTypeErrorMessage(typeof test, "function", name)
  106. );
  107. }
  108. };
  109. /**
  110. * Throws if test is not typeof 'string'
  111. *
  112. * @param {String} name The name of the variable being tested
  113. * @param {*} test The value to test
  114. * @exception {DeveloperError} test must be typeof 'string'
  115. */
  116. Check.typeOf.string = function (name, test) {
  117. if (typeof test !== "string") {
  118. throw new DeveloperError(
  119. getFailedTypeErrorMessage(typeof test, "string", name)
  120. );
  121. }
  122. };
  123. /**
  124. * Throws if test is not typeof 'number'
  125. *
  126. * @param {String} name The name of the variable being tested
  127. * @param {*} test The value to test
  128. * @exception {DeveloperError} test must be typeof 'number'
  129. */
  130. Check.typeOf.number = function (name, test) {
  131. if (typeof test !== "number") {
  132. throw new DeveloperError(
  133. getFailedTypeErrorMessage(typeof test, "number", name)
  134. );
  135. }
  136. };
  137. /**
  138. * Throws if test is not typeof 'number' and less than limit
  139. *
  140. * @param {String} name The name of the variable being tested
  141. * @param {*} test The value to test
  142. * @param {Number} limit The limit value to compare against
  143. * @exception {DeveloperError} test must be typeof 'number' and less than limit
  144. */
  145. Check.typeOf.number.lessThan = function (name, test, limit) {
  146. Check.typeOf.number(name, test);
  147. if (test >= limit) {
  148. throw new DeveloperError(
  149. `Expected ${name} to be less than ${limit}, actual value was ${test}`
  150. );
  151. }
  152. };
  153. /**
  154. * Throws if test is not typeof 'number' and less than or equal to limit
  155. *
  156. * @param {String} name The name of the variable being tested
  157. * @param {*} test The value to test
  158. * @param {Number} limit The limit value to compare against
  159. * @exception {DeveloperError} test must be typeof 'number' and less than or equal to limit
  160. */
  161. Check.typeOf.number.lessThanOrEquals = function (name, test, limit) {
  162. Check.typeOf.number(name, test);
  163. if (test > limit) {
  164. throw new DeveloperError(
  165. `Expected ${name} to be less than or equal to ${limit}, actual value was ${test}`
  166. );
  167. }
  168. };
  169. /**
  170. * Throws if test is not typeof 'number' and greater than limit
  171. *
  172. * @param {String} name The name of the variable being tested
  173. * @param {*} test The value to test
  174. * @param {Number} limit The limit value to compare against
  175. * @exception {DeveloperError} test must be typeof 'number' and greater than limit
  176. */
  177. Check.typeOf.number.greaterThan = function (name, test, limit) {
  178. Check.typeOf.number(name, test);
  179. if (test <= limit) {
  180. throw new DeveloperError(
  181. `Expected ${name} to be greater than ${limit}, actual value was ${test}`
  182. );
  183. }
  184. };
  185. /**
  186. * Throws if test is not typeof 'number' and greater than or equal to limit
  187. *
  188. * @param {String} name The name of the variable being tested
  189. * @param {*} test The value to test
  190. * @param {Number} limit The limit value to compare against
  191. * @exception {DeveloperError} test must be typeof 'number' and greater than or equal to limit
  192. */
  193. Check.typeOf.number.greaterThanOrEquals = function (name, test, limit) {
  194. Check.typeOf.number(name, test);
  195. if (test < limit) {
  196. throw new DeveloperError(
  197. `Expected ${name} to be greater than or equal to ${limit}, actual value was ${test}`
  198. );
  199. }
  200. };
  201. /**
  202. * Throws if test is not typeof 'object'
  203. *
  204. * @param {String} name The name of the variable being tested
  205. * @param {*} test The value to test
  206. * @exception {DeveloperError} test must be typeof 'object'
  207. */
  208. Check.typeOf.object = function (name, test) {
  209. if (typeof test !== "object") {
  210. throw new DeveloperError(
  211. getFailedTypeErrorMessage(typeof test, "object", name)
  212. );
  213. }
  214. };
  215. /**
  216. * Throws if test is not typeof 'boolean'
  217. *
  218. * @param {String} name The name of the variable being tested
  219. * @param {*} test The value to test
  220. * @exception {DeveloperError} test must be typeof 'boolean'
  221. */
  222. Check.typeOf.bool = function (name, test) {
  223. if (typeof test !== "boolean") {
  224. throw new DeveloperError(
  225. getFailedTypeErrorMessage(typeof test, "boolean", name)
  226. );
  227. }
  228. };
  229. /**
  230. * Throws if test is not typeof 'bigint'
  231. *
  232. * @param {String} name The name of the variable being tested
  233. * @param {*} test The value to test
  234. * @exception {DeveloperError} test must be typeof 'bigint'
  235. */
  236. Check.typeOf.bigint = function (name, test) {
  237. if (typeof test !== "bigint") {
  238. throw new DeveloperError(
  239. getFailedTypeErrorMessage(typeof test, "bigint", name)
  240. );
  241. }
  242. };
  243. /**
  244. * Throws if test1 and test2 is not typeof 'number' and not equal in value
  245. *
  246. * @param {String} name1 The name of the first variable being tested
  247. * @param {String} name2 The name of the second variable being tested against
  248. * @param {*} test1 The value to test
  249. * @param {*} test2 The value to test against
  250. * @exception {DeveloperError} test1 and test2 should be type of 'number' and be equal in value
  251. */
  252. Check.typeOf.number.equals = function (name1, name2, test1, test2) {
  253. Check.typeOf.number(name1, test1);
  254. Check.typeOf.number(name2, test2);
  255. if (test1 !== test2) {
  256. throw new DeveloperError(
  257. `${name1} must be equal to ${name2}, the actual values are ${test1} and ${test2}`
  258. );
  259. }
  260. };
  261. /**
  262. * Constructs an exception object that is thrown due to an error that can occur at runtime, e.g.,
  263. * out of memory, could not compile shader, etc. If a function may throw this
  264. * exception, the calling code should be prepared to catch it.
  265. * <br /><br />
  266. * On the other hand, a {@link DeveloperError} indicates an exception due
  267. * to a developer error, e.g., invalid argument, that usually indicates a bug in the
  268. * calling code.
  269. *
  270. * @alias RuntimeError
  271. * @constructor
  272. * @extends Error
  273. *
  274. * @param {String} [message] The error message for this exception.
  275. *
  276. * @see DeveloperError
  277. */
  278. function RuntimeError(message) {
  279. /**
  280. * 'RuntimeError' indicating that this exception was thrown due to a runtime error.
  281. * @type {String}
  282. * @readonly
  283. */
  284. this.name = "RuntimeError";
  285. /**
  286. * The explanation for why this exception was thrown.
  287. * @type {String}
  288. * @readonly
  289. */
  290. this.message = message;
  291. //Browsers such as IE don't have a stack property until you actually throw the error.
  292. let stack;
  293. try {
  294. throw new Error();
  295. } catch (e) {
  296. stack = e.stack;
  297. }
  298. /**
  299. * The stack trace of this exception, if available.
  300. * @type {String}
  301. * @readonly
  302. */
  303. this.stack = stack;
  304. }
  305. if (defaultValue.defined(Object.create)) {
  306. RuntimeError.prototype = Object.create(Error.prototype);
  307. RuntimeError.prototype.constructor = RuntimeError;
  308. }
  309. RuntimeError.prototype.toString = function () {
  310. let str = `${this.name}: ${this.message}`;
  311. if (defaultValue.defined(this.stack)) {
  312. str += `\n${this.stack.toString()}`;
  313. }
  314. return str;
  315. };
  316. exports.Check = Check;
  317. exports.DeveloperError = DeveloperError;
  318. exports.RuntimeError = RuntimeError;
  319. }));