Check-6ede7e26.js 8.7 KB

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