RuntimeError-8952249c.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /**
  2. * Cesium - https://github.com/CesiumGS/cesium
  3. *
  4. * Copyright 2011-2020 Cesium Contributors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Columbus View (Pat. Pend.)
  19. *
  20. * Portions licensed separately.
  21. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  22. */
  23. define(['exports', './defaultValue-81eec7ed'], (function (exports, defaultValue) { 'use strict';
  24. /**
  25. * Constructs an exception object that is thrown due to a developer error, e.g., invalid argument,
  26. * argument out of range, etc. This exception should only be thrown during development;
  27. * it usually indicates a bug in the calling code. This exception should never be
  28. * caught; instead the calling code should strive not to generate it.
  29. * <br /><br />
  30. * On the other hand, a {@link RuntimeError} indicates an exception that may
  31. * be thrown at runtime, e.g., out of memory, that the calling code should be prepared
  32. * to catch.
  33. *
  34. * @alias DeveloperError
  35. * @constructor
  36. * @extends Error
  37. *
  38. * @param {String} [message] The error message for this exception.
  39. *
  40. * @see RuntimeError
  41. */
  42. function DeveloperError(message) {
  43. /**
  44. * 'DeveloperError' indicating that this exception was thrown due to a developer error.
  45. * @type {String}
  46. * @readonly
  47. */
  48. this.name = "DeveloperError";
  49. /**
  50. * The explanation for why this exception was thrown.
  51. * @type {String}
  52. * @readonly
  53. */
  54. this.message = message;
  55. //Browsers such as IE don't have a stack property until you actually throw the error.
  56. let stack;
  57. try {
  58. throw new Error();
  59. } catch (e) {
  60. stack = e.stack;
  61. }
  62. /**
  63. * The stack trace of this exception, if available.
  64. * @type {String}
  65. * @readonly
  66. */
  67. this.stack = stack;
  68. }
  69. if (defaultValue.defined(Object.create)) {
  70. DeveloperError.prototype = Object.create(Error.prototype);
  71. DeveloperError.prototype.constructor = DeveloperError;
  72. }
  73. DeveloperError.prototype.toString = function () {
  74. let str = `${this.name}: ${this.message}`;
  75. if (defaultValue.defined(this.stack)) {
  76. str += `\n${this.stack.toString()}`;
  77. }
  78. return str;
  79. };
  80. /**
  81. * @private
  82. */
  83. DeveloperError.throwInstantiationError = function () {
  84. throw new DeveloperError(
  85. "This function defines an interface and should not be called directly."
  86. );
  87. };
  88. /**
  89. * Contains functions for checking that supplied arguments are of a specified type
  90. * or meet specified conditions
  91. * @private
  92. */
  93. const Check = {};
  94. /**
  95. * Contains type checking functions, all using the typeof operator
  96. */
  97. Check.typeOf = {};
  98. function getUndefinedErrorMessage(name) {
  99. return `${name} is required, actual value was undefined`;
  100. }
  101. function getFailedTypeErrorMessage(actual, expected, name) {
  102. return `Expected ${name} to be typeof ${expected}, actual typeof was ${actual}`;
  103. }
  104. /**
  105. * Throws if test is not defined
  106. *
  107. * @param {String} name The name of the variable being tested
  108. * @param {*} test The value that is to be checked
  109. * @exception {DeveloperError} test must be defined
  110. */
  111. Check.defined = function (name, test) {
  112. if (!defaultValue.defined(test)) {
  113. throw new DeveloperError(getUndefinedErrorMessage(name));
  114. }
  115. };
  116. /**
  117. * Throws if test is not typeof 'function'
  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 'function'
  122. */
  123. Check.typeOf.func = function (name, test) {
  124. if (typeof test !== "function") {
  125. throw new DeveloperError(
  126. getFailedTypeErrorMessage(typeof test, "function", name)
  127. );
  128. }
  129. };
  130. /**
  131. * Throws if test is not typeof 'string'
  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 'string'
  136. */
  137. Check.typeOf.string = function (name, test) {
  138. if (typeof test !== "string") {
  139. throw new DeveloperError(
  140. getFailedTypeErrorMessage(typeof test, "string", name)
  141. );
  142. }
  143. };
  144. /**
  145. * Throws if test is not typeof 'number'
  146. *
  147. * @param {String} name The name of the variable being tested
  148. * @param {*} test The value to test
  149. * @exception {DeveloperError} test must be typeof 'number'
  150. */
  151. Check.typeOf.number = function (name, test) {
  152. if (typeof test !== "number") {
  153. throw new DeveloperError(
  154. getFailedTypeErrorMessage(typeof test, "number", name)
  155. );
  156. }
  157. };
  158. /**
  159. * Throws if test is not typeof 'number' and less than limit
  160. *
  161. * @param {String} name The name of the variable being tested
  162. * @param {*} test The value to test
  163. * @param {Number} limit The limit value to compare against
  164. * @exception {DeveloperError} test must be typeof 'number' and less than limit
  165. */
  166. Check.typeOf.number.lessThan = function (name, test, limit) {
  167. Check.typeOf.number(name, test);
  168. if (test >= limit) {
  169. throw new DeveloperError(
  170. `Expected ${name} to be less than ${limit}, actual value was ${test}`
  171. );
  172. }
  173. };
  174. /**
  175. * Throws if test is not typeof 'number' and less than or equal to limit
  176. *
  177. * @param {String} name The name of the variable being tested
  178. * @param {*} test The value to test
  179. * @param {Number} limit The limit value to compare against
  180. * @exception {DeveloperError} test must be typeof 'number' and less than or equal to limit
  181. */
  182. Check.typeOf.number.lessThanOrEquals = function (name, test, limit) {
  183. Check.typeOf.number(name, test);
  184. if (test > limit) {
  185. throw new DeveloperError(
  186. `Expected ${name} to be less than or equal to ${limit}, actual value was ${test}`
  187. );
  188. }
  189. };
  190. /**
  191. * Throws if test is not typeof 'number' and greater than limit
  192. *
  193. * @param {String} name The name of the variable being tested
  194. * @param {*} test The value to test
  195. * @param {Number} limit The limit value to compare against
  196. * @exception {DeveloperError} test must be typeof 'number' and greater than limit
  197. */
  198. Check.typeOf.number.greaterThan = function (name, test, limit) {
  199. Check.typeOf.number(name, test);
  200. if (test <= limit) {
  201. throw new DeveloperError(
  202. `Expected ${name} to be greater than ${limit}, actual value was ${test}`
  203. );
  204. }
  205. };
  206. /**
  207. * Throws if test is not typeof 'number' and greater than or equal to limit
  208. *
  209. * @param {String} name The name of the variable being tested
  210. * @param {*} test The value to test
  211. * @param {Number} limit The limit value to compare against
  212. * @exception {DeveloperError} test must be typeof 'number' and greater than or equal to limit
  213. */
  214. Check.typeOf.number.greaterThanOrEquals = function (name, test, limit) {
  215. Check.typeOf.number(name, test);
  216. if (test < limit) {
  217. throw new DeveloperError(
  218. `Expected ${name} to be greater than or equal to ${limit}, actual value was ${test}`
  219. );
  220. }
  221. };
  222. /**
  223. * Throws if test is not typeof 'object'
  224. *
  225. * @param {String} name The name of the variable being tested
  226. * @param {*} test The value to test
  227. * @exception {DeveloperError} test must be typeof 'object'
  228. */
  229. Check.typeOf.object = function (name, test) {
  230. if (typeof test !== "object") {
  231. throw new DeveloperError(
  232. getFailedTypeErrorMessage(typeof test, "object", name)
  233. );
  234. }
  235. };
  236. /**
  237. * Throws if test is not typeof 'boolean'
  238. *
  239. * @param {String} name The name of the variable being tested
  240. * @param {*} test The value to test
  241. * @exception {DeveloperError} test must be typeof 'boolean'
  242. */
  243. Check.typeOf.bool = function (name, test) {
  244. if (typeof test !== "boolean") {
  245. throw new DeveloperError(
  246. getFailedTypeErrorMessage(typeof test, "boolean", name)
  247. );
  248. }
  249. };
  250. /**
  251. * Throws if test is not typeof 'bigint'
  252. *
  253. * @param {String} name The name of the variable being tested
  254. * @param {*} test The value to test
  255. * @exception {DeveloperError} test must be typeof 'bigint'
  256. */
  257. Check.typeOf.bigint = function (name, test) {
  258. if (typeof test !== "bigint") {
  259. throw new DeveloperError(
  260. getFailedTypeErrorMessage(typeof test, "bigint", name)
  261. );
  262. }
  263. };
  264. /**
  265. * Throws if test1 and test2 is not typeof 'number' and not equal in value
  266. *
  267. * @param {String} name1 The name of the first variable being tested
  268. * @param {String} name2 The name of the second variable being tested against
  269. * @param {*} test1 The value to test
  270. * @param {*} test2 The value to test against
  271. * @exception {DeveloperError} test1 and test2 should be type of 'number' and be equal in value
  272. */
  273. Check.typeOf.number.equals = function (name1, name2, test1, test2) {
  274. Check.typeOf.number(name1, test1);
  275. Check.typeOf.number(name2, test2);
  276. if (test1 !== test2) {
  277. throw new DeveloperError(
  278. `${name1} must be equal to ${name2}, the actual values are ${test1} and ${test2}`
  279. );
  280. }
  281. };
  282. /**
  283. * Constructs an exception object that is thrown due to an error that can occur at runtime, e.g.,
  284. * out of memory, could not compile shader, etc. If a function may throw this
  285. * exception, the calling code should be prepared to catch it.
  286. * <br /><br />
  287. * On the other hand, a {@link DeveloperError} indicates an exception due
  288. * to a developer error, e.g., invalid argument, that usually indicates a bug in the
  289. * calling code.
  290. *
  291. * @alias RuntimeError
  292. * @constructor
  293. * @extends Error
  294. *
  295. * @param {String} [message] The error message for this exception.
  296. *
  297. * @see DeveloperError
  298. */
  299. function RuntimeError(message) {
  300. /**
  301. * 'RuntimeError' indicating that this exception was thrown due to a runtime error.
  302. * @type {String}
  303. * @readonly
  304. */
  305. this.name = "RuntimeError";
  306. /**
  307. * The explanation for why this exception was thrown.
  308. * @type {String}
  309. * @readonly
  310. */
  311. this.message = message;
  312. //Browsers such as IE don't have a stack property until you actually throw the error.
  313. let stack;
  314. try {
  315. throw new Error();
  316. } catch (e) {
  317. stack = e.stack;
  318. }
  319. /**
  320. * The stack trace of this exception, if available.
  321. * @type {String}
  322. * @readonly
  323. */
  324. this.stack = stack;
  325. }
  326. if (defaultValue.defined(Object.create)) {
  327. RuntimeError.prototype = Object.create(Error.prototype);
  328. RuntimeError.prototype.constructor = RuntimeError;
  329. }
  330. RuntimeError.prototype.toString = function () {
  331. let str = `${this.name}: ${this.message}`;
  332. if (defaultValue.defined(this.stack)) {
  333. str += `\n${this.stack.toString()}`;
  334. }
  335. return str;
  336. };
  337. exports.Check = Check;
  338. exports.DeveloperError = DeveloperError;
  339. exports.RuntimeError = RuntimeError;
  340. }));
  341. //# sourceMappingURL=RuntimeError-8952249c.js.map