You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
7.2 KiB

  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const impl = utils.implSymbol;
  5. const ctorRegistry = utils.ctorRegistrySymbol;
  6. const iface = {
  7. // When an interface-module that implements this interface as a mixin is loaded, it will append its own `.is()`
  8. // method into this array. It allows objects that directly implements *those* interfaces to be recognized as
  9. // implementing this mixin interface.
  10. _mixedIntoPredicates: [],
  11. is(obj) {
  12. if (obj) {
  13. if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) {
  14. return true;
  15. }
  16. for (const isMixedInto of module.exports._mixedIntoPredicates) {
  17. if (isMixedInto(obj)) {
  18. return true;
  19. }
  20. }
  21. }
  22. return false;
  23. },
  24. isImpl(obj) {
  25. if (obj) {
  26. if (obj instanceof Impl.implementation) {
  27. return true;
  28. }
  29. const wrapper = utils.wrapperForImpl(obj);
  30. for (const isMixedInto of module.exports._mixedIntoPredicates) {
  31. if (isMixedInto(wrapper)) {
  32. return true;
  33. }
  34. }
  35. }
  36. return false;
  37. },
  38. convert(obj, { context = "The provided value" } = {}) {
  39. if (module.exports.is(obj)) {
  40. return utils.implForWrapper(obj);
  41. }
  42. throw new TypeError(`${context} is not of type 'DOMException'.`);
  43. },
  44. create(globalObject, constructorArgs, privateData) {
  45. if (globalObject[ctorRegistry] === undefined) {
  46. throw new Error("Internal error: invalid global object");
  47. }
  48. const ctor = globalObject[ctorRegistry]["DOMException"];
  49. if (ctor === undefined) {
  50. throw new Error("Internal error: constructor DOMException is not installed on the passed global object");
  51. }
  52. let obj = Object.create(ctor.prototype);
  53. obj = iface.setup(obj, globalObject, constructorArgs, privateData);
  54. return obj;
  55. },
  56. createImpl(globalObject, constructorArgs, privateData) {
  57. const obj = iface.create(globalObject, constructorArgs, privateData);
  58. return utils.implForWrapper(obj);
  59. },
  60. _internalSetup(obj) {},
  61. setup(obj, globalObject, constructorArgs = [], privateData = {}) {
  62. privateData.wrapper = obj;
  63. iface._internalSetup(obj);
  64. Object.defineProperty(obj, impl, {
  65. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  66. configurable: true
  67. });
  68. obj[impl][utils.wrapperSymbol] = obj;
  69. if (Impl.init) {
  70. Impl.init(obj[impl], privateData);
  71. }
  72. return obj;
  73. },
  74. install(globalObject) {
  75. class DOMException {
  76. constructor() {
  77. const args = [];
  78. {
  79. let curArg = arguments[0];
  80. if (curArg !== undefined) {
  81. curArg = conversions["DOMString"](curArg, { context: "Failed to construct 'DOMException': parameter 1" });
  82. } else {
  83. curArg = "";
  84. }
  85. args.push(curArg);
  86. }
  87. {
  88. let curArg = arguments[1];
  89. if (curArg !== undefined) {
  90. curArg = conversions["DOMString"](curArg, { context: "Failed to construct 'DOMException': parameter 2" });
  91. } else {
  92. curArg = "Error";
  93. }
  94. args.push(curArg);
  95. }
  96. return iface.setup(Object.create(new.target.prototype), globalObject, args);
  97. }
  98. get name() {
  99. if (!this || !module.exports.is(this)) {
  100. throw new TypeError("Illegal invocation");
  101. }
  102. return this[impl]["name"];
  103. }
  104. get message() {
  105. if (!this || !module.exports.is(this)) {
  106. throw new TypeError("Illegal invocation");
  107. }
  108. return this[impl]["message"];
  109. }
  110. get code() {
  111. if (!this || !module.exports.is(this)) {
  112. throw new TypeError("Illegal invocation");
  113. }
  114. return this[impl]["code"];
  115. }
  116. }
  117. Object.defineProperties(DOMException.prototype, {
  118. name: { enumerable: true },
  119. message: { enumerable: true },
  120. code: { enumerable: true },
  121. [Symbol.toStringTag]: { value: "DOMException", configurable: true },
  122. INDEX_SIZE_ERR: { value: 1, enumerable: true },
  123. DOMSTRING_SIZE_ERR: { value: 2, enumerable: true },
  124. HIERARCHY_REQUEST_ERR: { value: 3, enumerable: true },
  125. WRONG_DOCUMENT_ERR: { value: 4, enumerable: true },
  126. INVALID_CHARACTER_ERR: { value: 5, enumerable: true },
  127. NO_DATA_ALLOWED_ERR: { value: 6, enumerable: true },
  128. NO_MODIFICATION_ALLOWED_ERR: { value: 7, enumerable: true },
  129. NOT_FOUND_ERR: { value: 8, enumerable: true },
  130. NOT_SUPPORTED_ERR: { value: 9, enumerable: true },
  131. INUSE_ATTRIBUTE_ERR: { value: 10, enumerable: true },
  132. INVALID_STATE_ERR: { value: 11, enumerable: true },
  133. SYNTAX_ERR: { value: 12, enumerable: true },
  134. INVALID_MODIFICATION_ERR: { value: 13, enumerable: true },
  135. NAMESPACE_ERR: { value: 14, enumerable: true },
  136. INVALID_ACCESS_ERR: { value: 15, enumerable: true },
  137. VALIDATION_ERR: { value: 16, enumerable: true },
  138. TYPE_MISMATCH_ERR: { value: 17, enumerable: true },
  139. SECURITY_ERR: { value: 18, enumerable: true },
  140. NETWORK_ERR: { value: 19, enumerable: true },
  141. ABORT_ERR: { value: 20, enumerable: true },
  142. URL_MISMATCH_ERR: { value: 21, enumerable: true },
  143. QUOTA_EXCEEDED_ERR: { value: 22, enumerable: true },
  144. TIMEOUT_ERR: { value: 23, enumerable: true },
  145. INVALID_NODE_TYPE_ERR: { value: 24, enumerable: true },
  146. DATA_CLONE_ERR: { value: 25, enumerable: true }
  147. });
  148. Object.defineProperties(DOMException, {
  149. INDEX_SIZE_ERR: { value: 1, enumerable: true },
  150. DOMSTRING_SIZE_ERR: { value: 2, enumerable: true },
  151. HIERARCHY_REQUEST_ERR: { value: 3, enumerable: true },
  152. WRONG_DOCUMENT_ERR: { value: 4, enumerable: true },
  153. INVALID_CHARACTER_ERR: { value: 5, enumerable: true },
  154. NO_DATA_ALLOWED_ERR: { value: 6, enumerable: true },
  155. NO_MODIFICATION_ALLOWED_ERR: { value: 7, enumerable: true },
  156. NOT_FOUND_ERR: { value: 8, enumerable: true },
  157. NOT_SUPPORTED_ERR: { value: 9, enumerable: true },
  158. INUSE_ATTRIBUTE_ERR: { value: 10, enumerable: true },
  159. INVALID_STATE_ERR: { value: 11, enumerable: true },
  160. SYNTAX_ERR: { value: 12, enumerable: true },
  161. INVALID_MODIFICATION_ERR: { value: 13, enumerable: true },
  162. NAMESPACE_ERR: { value: 14, enumerable: true },
  163. INVALID_ACCESS_ERR: { value: 15, enumerable: true },
  164. VALIDATION_ERR: { value: 16, enumerable: true },
  165. TYPE_MISMATCH_ERR: { value: 17, enumerable: true },
  166. SECURITY_ERR: { value: 18, enumerable: true },
  167. NETWORK_ERR: { value: 19, enumerable: true },
  168. ABORT_ERR: { value: 20, enumerable: true },
  169. URL_MISMATCH_ERR: { value: 21, enumerable: true },
  170. QUOTA_EXCEEDED_ERR: { value: 22, enumerable: true },
  171. TIMEOUT_ERR: { value: 23, enumerable: true },
  172. INVALID_NODE_TYPE_ERR: { value: 24, enumerable: true },
  173. DATA_CLONE_ERR: { value: 25, enumerable: true }
  174. });
  175. if (globalObject[ctorRegistry] === undefined) {
  176. globalObject[ctorRegistry] = Object.create(null);
  177. }
  178. globalObject[ctorRegistry]["DOMException"] = DOMException;
  179. Object.defineProperty(globalObject, "DOMException", {
  180. configurable: true,
  181. writable: true,
  182. value: DOMException
  183. });
  184. }
  185. }; // iface
  186. module.exports = iface;
  187. const Impl = require("./DOMException-impl.js");