source: frontend/node_modules/domexception/lib/DOMException.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

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