DOMException.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const impl = utils.implSymbol;
  5. function DOMException() {
  6. const args = [];
  7. for (let i = 0; i < arguments.length && i < 2; ++i) {
  8. args[i] = arguments[i];
  9. }
  10. if (args[0] !== undefined) {
  11. args[0] = conversions["DOMString"](args[0], { context: "Failed to construct 'DOMException': parameter 1" });
  12. } else {
  13. args[0] = "";
  14. }
  15. if (args[1] !== undefined) {
  16. args[1] = conversions["DOMString"](args[1], { context: "Failed to construct 'DOMException': parameter 2" });
  17. } else {
  18. args[1] = "Error";
  19. }
  20. iface.setup(this, args);
  21. }
  22. Object.defineProperty(DOMException, "prototype", {
  23. value: DOMException.prototype,
  24. writable: false,
  25. enumerable: false,
  26. configurable: false
  27. });
  28. Object.defineProperty(DOMException.prototype, "name", {
  29. get() {
  30. return this[impl]["name"];
  31. },
  32. enumerable: true,
  33. configurable: true
  34. });
  35. Object.defineProperty(DOMException.prototype, "message", {
  36. get() {
  37. return this[impl]["message"];
  38. },
  39. enumerable: true,
  40. configurable: true
  41. });
  42. Object.defineProperty(DOMException.prototype, "code", {
  43. get() {
  44. return this[impl]["code"];
  45. },
  46. enumerable: true,
  47. configurable: true
  48. });
  49. Object.defineProperty(DOMException, "INDEX_SIZE_ERR", {
  50. value: 1,
  51. enumerable: true
  52. });
  53. Object.defineProperty(DOMException.prototype, "INDEX_SIZE_ERR", {
  54. value: 1,
  55. enumerable: true
  56. });
  57. Object.defineProperty(DOMException, "DOMSTRING_SIZE_ERR", {
  58. value: 2,
  59. enumerable: true
  60. });
  61. Object.defineProperty(DOMException.prototype, "DOMSTRING_SIZE_ERR", {
  62. value: 2,
  63. enumerable: true
  64. });
  65. Object.defineProperty(DOMException, "HIERARCHY_REQUEST_ERR", {
  66. value: 3,
  67. enumerable: true
  68. });
  69. Object.defineProperty(DOMException.prototype, "HIERARCHY_REQUEST_ERR", {
  70. value: 3,
  71. enumerable: true
  72. });
  73. Object.defineProperty(DOMException, "WRONG_DOCUMENT_ERR", {
  74. value: 4,
  75. enumerable: true
  76. });
  77. Object.defineProperty(DOMException.prototype, "WRONG_DOCUMENT_ERR", {
  78. value: 4,
  79. enumerable: true
  80. });
  81. Object.defineProperty(DOMException, "INVALID_CHARACTER_ERR", {
  82. value: 5,
  83. enumerable: true
  84. });
  85. Object.defineProperty(DOMException.prototype, "INVALID_CHARACTER_ERR", {
  86. value: 5,
  87. enumerable: true
  88. });
  89. Object.defineProperty(DOMException, "NO_DATA_ALLOWED_ERR", {
  90. value: 6,
  91. enumerable: true
  92. });
  93. Object.defineProperty(DOMException.prototype, "NO_DATA_ALLOWED_ERR", {
  94. value: 6,
  95. enumerable: true
  96. });
  97. Object.defineProperty(DOMException, "NO_MODIFICATION_ALLOWED_ERR", {
  98. value: 7,
  99. enumerable: true
  100. });
  101. Object.defineProperty(DOMException.prototype, "NO_MODIFICATION_ALLOWED_ERR", {
  102. value: 7,
  103. enumerable: true
  104. });
  105. Object.defineProperty(DOMException, "NOT_FOUND_ERR", {
  106. value: 8,
  107. enumerable: true
  108. });
  109. Object.defineProperty(DOMException.prototype, "NOT_FOUND_ERR", {
  110. value: 8,
  111. enumerable: true
  112. });
  113. Object.defineProperty(DOMException, "NOT_SUPPORTED_ERR", {
  114. value: 9,
  115. enumerable: true
  116. });
  117. Object.defineProperty(DOMException.prototype, "NOT_SUPPORTED_ERR", {
  118. value: 9,
  119. enumerable: true
  120. });
  121. Object.defineProperty(DOMException, "INUSE_ATTRIBUTE_ERR", {
  122. value: 10,
  123. enumerable: true
  124. });
  125. Object.defineProperty(DOMException.prototype, "INUSE_ATTRIBUTE_ERR", {
  126. value: 10,
  127. enumerable: true
  128. });
  129. Object.defineProperty(DOMException, "INVALID_STATE_ERR", {
  130. value: 11,
  131. enumerable: true
  132. });
  133. Object.defineProperty(DOMException.prototype, "INVALID_STATE_ERR", {
  134. value: 11,
  135. enumerable: true
  136. });
  137. Object.defineProperty(DOMException, "SYNTAX_ERR", {
  138. value: 12,
  139. enumerable: true
  140. });
  141. Object.defineProperty(DOMException.prototype, "SYNTAX_ERR", {
  142. value: 12,
  143. enumerable: true
  144. });
  145. Object.defineProperty(DOMException, "INVALID_MODIFICATION_ERR", {
  146. value: 13,
  147. enumerable: true
  148. });
  149. Object.defineProperty(DOMException.prototype, "INVALID_MODIFICATION_ERR", {
  150. value: 13,
  151. enumerable: true
  152. });
  153. Object.defineProperty(DOMException, "NAMESPACE_ERR", {
  154. value: 14,
  155. enumerable: true
  156. });
  157. Object.defineProperty(DOMException.prototype, "NAMESPACE_ERR", {
  158. value: 14,
  159. enumerable: true
  160. });
  161. Object.defineProperty(DOMException, "INVALID_ACCESS_ERR", {
  162. value: 15,
  163. enumerable: true
  164. });
  165. Object.defineProperty(DOMException.prototype, "INVALID_ACCESS_ERR", {
  166. value: 15,
  167. enumerable: true
  168. });
  169. Object.defineProperty(DOMException, "VALIDATION_ERR", {
  170. value: 16,
  171. enumerable: true
  172. });
  173. Object.defineProperty(DOMException.prototype, "VALIDATION_ERR", {
  174. value: 16,
  175. enumerable: true
  176. });
  177. Object.defineProperty(DOMException, "TYPE_MISMATCH_ERR", {
  178. value: 17,
  179. enumerable: true
  180. });
  181. Object.defineProperty(DOMException.prototype, "TYPE_MISMATCH_ERR", {
  182. value: 17,
  183. enumerable: true
  184. });
  185. Object.defineProperty(DOMException, "SECURITY_ERR", {
  186. value: 18,
  187. enumerable: true
  188. });
  189. Object.defineProperty(DOMException.prototype, "SECURITY_ERR", {
  190. value: 18,
  191. enumerable: true
  192. });
  193. Object.defineProperty(DOMException, "NETWORK_ERR", {
  194. value: 19,
  195. enumerable: true
  196. });
  197. Object.defineProperty(DOMException.prototype, "NETWORK_ERR", {
  198. value: 19,
  199. enumerable: true
  200. });
  201. Object.defineProperty(DOMException, "ABORT_ERR", {
  202. value: 20,
  203. enumerable: true
  204. });
  205. Object.defineProperty(DOMException.prototype, "ABORT_ERR", {
  206. value: 20,
  207. enumerable: true
  208. });
  209. Object.defineProperty(DOMException, "URL_MISMATCH_ERR", {
  210. value: 21,
  211. enumerable: true
  212. });
  213. Object.defineProperty(DOMException.prototype, "URL_MISMATCH_ERR", {
  214. value: 21,
  215. enumerable: true
  216. });
  217. Object.defineProperty(DOMException, "QUOTA_EXCEEDED_ERR", {
  218. value: 22,
  219. enumerable: true
  220. });
  221. Object.defineProperty(DOMException.prototype, "QUOTA_EXCEEDED_ERR", {
  222. value: 22,
  223. enumerable: true
  224. });
  225. Object.defineProperty(DOMException, "TIMEOUT_ERR", {
  226. value: 23,
  227. enumerable: true
  228. });
  229. Object.defineProperty(DOMException.prototype, "TIMEOUT_ERR", {
  230. value: 23,
  231. enumerable: true
  232. });
  233. Object.defineProperty(DOMException, "INVALID_NODE_TYPE_ERR", {
  234. value: 24,
  235. enumerable: true
  236. });
  237. Object.defineProperty(DOMException.prototype, "INVALID_NODE_TYPE_ERR", {
  238. value: 24,
  239. enumerable: true
  240. });
  241. Object.defineProperty(DOMException, "DATA_CLONE_ERR", {
  242. value: 25,
  243. enumerable: true
  244. });
  245. Object.defineProperty(DOMException.prototype, "DATA_CLONE_ERR", {
  246. value: 25,
  247. enumerable: true
  248. });
  249. Object.defineProperty(DOMException.prototype, Symbol.toStringTag, {
  250. value: "DOMException",
  251. writable: false,
  252. enumerable: false,
  253. configurable: true
  254. });
  255. const iface = {
  256. mixedInto: [],
  257. is(obj) {
  258. if (obj) {
  259. if (obj[impl] instanceof Impl.implementation) {
  260. return true;
  261. }
  262. for (let i = 0; i < module.exports.mixedInto.length; ++i) {
  263. if (obj instanceof module.exports.mixedInto[i]) {
  264. return true;
  265. }
  266. }
  267. }
  268. return false;
  269. },
  270. isImpl(obj) {
  271. if (obj) {
  272. if (obj instanceof Impl.implementation) {
  273. return true;
  274. }
  275. const wrapper = utils.wrapperForImpl(obj);
  276. for (let i = 0; i < module.exports.mixedInto.length; ++i) {
  277. if (wrapper instanceof module.exports.mixedInto[i]) {
  278. return true;
  279. }
  280. }
  281. }
  282. return false;
  283. },
  284. convert(obj, { context = "The provided value" } = {}) {
  285. if (module.exports.is(obj)) {
  286. return utils.implForWrapper(obj);
  287. }
  288. throw new TypeError(`${context} is not of type 'DOMException'.`);
  289. },
  290. create(constructorArgs, privateData) {
  291. let obj = Object.create(DOMException.prototype);
  292. this.setup(obj, constructorArgs, privateData);
  293. return obj;
  294. },
  295. createImpl(constructorArgs, privateData) {
  296. let obj = Object.create(DOMException.prototype);
  297. this.setup(obj, constructorArgs, privateData);
  298. return utils.implForWrapper(obj);
  299. },
  300. _internalSetup(obj) {},
  301. setup(obj, constructorArgs, privateData) {
  302. if (!privateData) privateData = {};
  303. privateData.wrapper = obj;
  304. this._internalSetup(obj);
  305. Object.defineProperty(obj, impl, {
  306. value: new Impl.implementation(constructorArgs, privateData),
  307. writable: false,
  308. enumerable: false,
  309. configurable: true
  310. });
  311. obj[impl][utils.wrapperSymbol] = obj;
  312. if (Impl.init) {
  313. Impl.init(obj[impl], privateData);
  314. }
  315. },
  316. interface: DOMException,
  317. expose: {
  318. Window: { DOMException },
  319. Worker: { DOMException }
  320. }
  321. }; // iface
  322. module.exports = iface;
  323. const Impl = require(".//DOMException-impl.js");