HTMLOutputElement.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const HTMLConstructor_jsdom_living_helpers_html_constructor =
  5. require("../../jsdom/living/helpers/html-constructor.js").HTMLConstructor;
  6. const ceReactionsPreSteps_jsdom_living_helpers_custom_elements =
  7. require("../../jsdom/living/helpers/custom-elements.js").ceReactionsPreSteps;
  8. const ceReactionsPostSteps_jsdom_living_helpers_custom_elements =
  9. require("../../jsdom/living/helpers/custom-elements.js").ceReactionsPostSteps;
  10. const implSymbol = utils.implSymbol;
  11. const ctorRegistrySymbol = utils.ctorRegistrySymbol;
  12. const HTMLElement = require("./HTMLElement.js");
  13. const interfaceName = "HTMLOutputElement";
  14. exports.is = value => {
  15. return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
  16. };
  17. exports.isImpl = value => {
  18. return utils.isObject(value) && value instanceof Impl.implementation;
  19. };
  20. exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
  21. if (exports.is(value)) {
  22. return utils.implForWrapper(value);
  23. }
  24. throw new globalObject.TypeError(`${context} is not of type 'HTMLOutputElement'.`);
  25. };
  26. function makeWrapper(globalObject, newTarget) {
  27. let proto;
  28. if (newTarget !== undefined) {
  29. proto = newTarget.prototype;
  30. }
  31. if (!utils.isObject(proto)) {
  32. proto = globalObject[ctorRegistrySymbol]["HTMLOutputElement"].prototype;
  33. }
  34. return Object.create(proto);
  35. }
  36. exports.create = (globalObject, constructorArgs, privateData) => {
  37. const wrapper = makeWrapper(globalObject);
  38. return exports.setup(wrapper, globalObject, constructorArgs, privateData);
  39. };
  40. exports.createImpl = (globalObject, constructorArgs, privateData) => {
  41. const wrapper = exports.create(globalObject, constructorArgs, privateData);
  42. return utils.implForWrapper(wrapper);
  43. };
  44. exports._internalSetup = (wrapper, globalObject) => {
  45. HTMLElement._internalSetup(wrapper, globalObject);
  46. };
  47. exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
  48. privateData.wrapper = wrapper;
  49. exports._internalSetup(wrapper, globalObject);
  50. Object.defineProperty(wrapper, implSymbol, {
  51. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  52. configurable: true
  53. });
  54. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  55. if (Impl.init) {
  56. Impl.init(wrapper[implSymbol]);
  57. }
  58. return wrapper;
  59. };
  60. exports.new = (globalObject, newTarget) => {
  61. const wrapper = makeWrapper(globalObject, newTarget);
  62. exports._internalSetup(wrapper, globalObject);
  63. Object.defineProperty(wrapper, implSymbol, {
  64. value: Object.create(Impl.implementation.prototype),
  65. configurable: true
  66. });
  67. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  68. if (Impl.init) {
  69. Impl.init(wrapper[implSymbol]);
  70. }
  71. return wrapper[implSymbol];
  72. };
  73. const exposed = new Set(["Window"]);
  74. exports.install = (globalObject, globalNames) => {
  75. if (!globalNames.some(globalName => exposed.has(globalName))) {
  76. return;
  77. }
  78. const ctorRegistry = utils.initCtorRegistry(globalObject);
  79. class HTMLOutputElement extends globalObject.HTMLElement {
  80. constructor() {
  81. return HTMLConstructor_jsdom_living_helpers_html_constructor(globalObject, interfaceName, new.target);
  82. }
  83. checkValidity() {
  84. const esValue = this !== null && this !== undefined ? this : globalObject;
  85. if (!exports.is(esValue)) {
  86. throw new globalObject.TypeError(
  87. "'checkValidity' called on an object that is not a valid instance of HTMLOutputElement."
  88. );
  89. }
  90. return esValue[implSymbol].checkValidity();
  91. }
  92. reportValidity() {
  93. const esValue = this !== null && this !== undefined ? this : globalObject;
  94. if (!exports.is(esValue)) {
  95. throw new globalObject.TypeError(
  96. "'reportValidity' called on an object that is not a valid instance of HTMLOutputElement."
  97. );
  98. }
  99. return esValue[implSymbol].reportValidity();
  100. }
  101. setCustomValidity(error) {
  102. const esValue = this !== null && this !== undefined ? this : globalObject;
  103. if (!exports.is(esValue)) {
  104. throw new globalObject.TypeError(
  105. "'setCustomValidity' called on an object that is not a valid instance of HTMLOutputElement."
  106. );
  107. }
  108. if (arguments.length < 1) {
  109. throw new globalObject.TypeError(
  110. `Failed to execute 'setCustomValidity' on 'HTMLOutputElement': 1 argument required, but only ${arguments.length} present.`
  111. );
  112. }
  113. const args = [];
  114. {
  115. let curArg = arguments[0];
  116. curArg = conversions["DOMString"](curArg, {
  117. context: "Failed to execute 'setCustomValidity' on 'HTMLOutputElement': parameter 1",
  118. globals: globalObject
  119. });
  120. args.push(curArg);
  121. }
  122. return esValue[implSymbol].setCustomValidity(...args);
  123. }
  124. get htmlFor() {
  125. const esValue = this !== null && this !== undefined ? this : globalObject;
  126. if (!exports.is(esValue)) {
  127. throw new globalObject.TypeError(
  128. "'get htmlFor' called on an object that is not a valid instance of HTMLOutputElement."
  129. );
  130. }
  131. return utils.getSameObject(this, "htmlFor", () => {
  132. return utils.tryWrapperForImpl(esValue[implSymbol]["htmlFor"]);
  133. });
  134. }
  135. set htmlFor(V) {
  136. const esValue = this !== null && this !== undefined ? this : globalObject;
  137. if (!exports.is(esValue)) {
  138. throw new globalObject.TypeError(
  139. "'set htmlFor' called on an object that is not a valid instance of HTMLOutputElement."
  140. );
  141. }
  142. const Q = esValue["htmlFor"];
  143. if (!utils.isObject(Q)) {
  144. throw new globalObject.TypeError("Property 'htmlFor' is not an object");
  145. }
  146. Reflect.set(Q, "value", V);
  147. }
  148. get form() {
  149. const esValue = this !== null && this !== undefined ? this : globalObject;
  150. if (!exports.is(esValue)) {
  151. throw new globalObject.TypeError(
  152. "'get form' called on an object that is not a valid instance of HTMLOutputElement."
  153. );
  154. }
  155. return utils.tryWrapperForImpl(esValue[implSymbol]["form"]);
  156. }
  157. get name() {
  158. const esValue = this !== null && this !== undefined ? this : globalObject;
  159. if (!exports.is(esValue)) {
  160. throw new globalObject.TypeError(
  161. "'get name' called on an object that is not a valid instance of HTMLOutputElement."
  162. );
  163. }
  164. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  165. try {
  166. const value = esValue[implSymbol]._reflectGetTheContentAttribute("name");
  167. return value === null ? "" : value;
  168. } finally {
  169. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  170. }
  171. }
  172. set name(V) {
  173. const esValue = this !== null && this !== undefined ? this : globalObject;
  174. if (!exports.is(esValue)) {
  175. throw new globalObject.TypeError(
  176. "'set name' called on an object that is not a valid instance of HTMLOutputElement."
  177. );
  178. }
  179. V = conversions["DOMString"](V, {
  180. context: "Failed to set the 'name' property on 'HTMLOutputElement': The provided value",
  181. globals: globalObject
  182. });
  183. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  184. try {
  185. esValue[implSymbol]._reflectSetTheContentAttribute("name", V);
  186. } finally {
  187. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  188. }
  189. }
  190. get type() {
  191. const esValue = this !== null && this !== undefined ? this : globalObject;
  192. if (!exports.is(esValue)) {
  193. throw new globalObject.TypeError(
  194. "'get type' called on an object that is not a valid instance of HTMLOutputElement."
  195. );
  196. }
  197. return esValue[implSymbol]["type"];
  198. }
  199. get defaultValue() {
  200. const esValue = this !== null && this !== undefined ? this : globalObject;
  201. if (!exports.is(esValue)) {
  202. throw new globalObject.TypeError(
  203. "'get defaultValue' called on an object that is not a valid instance of HTMLOutputElement."
  204. );
  205. }
  206. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  207. try {
  208. return esValue[implSymbol]["defaultValue"];
  209. } finally {
  210. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  211. }
  212. }
  213. set defaultValue(V) {
  214. const esValue = this !== null && this !== undefined ? this : globalObject;
  215. if (!exports.is(esValue)) {
  216. throw new globalObject.TypeError(
  217. "'set defaultValue' called on an object that is not a valid instance of HTMLOutputElement."
  218. );
  219. }
  220. V = conversions["DOMString"](V, {
  221. context: "Failed to set the 'defaultValue' property on 'HTMLOutputElement': The provided value",
  222. globals: globalObject
  223. });
  224. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  225. try {
  226. esValue[implSymbol]["defaultValue"] = V;
  227. } finally {
  228. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  229. }
  230. }
  231. get value() {
  232. const esValue = this !== null && this !== undefined ? this : globalObject;
  233. if (!exports.is(esValue)) {
  234. throw new globalObject.TypeError(
  235. "'get value' called on an object that is not a valid instance of HTMLOutputElement."
  236. );
  237. }
  238. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  239. try {
  240. return esValue[implSymbol]["value"];
  241. } finally {
  242. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  243. }
  244. }
  245. set value(V) {
  246. const esValue = this !== null && this !== undefined ? this : globalObject;
  247. if (!exports.is(esValue)) {
  248. throw new globalObject.TypeError(
  249. "'set value' called on an object that is not a valid instance of HTMLOutputElement."
  250. );
  251. }
  252. V = conversions["DOMString"](V, {
  253. context: "Failed to set the 'value' property on 'HTMLOutputElement': The provided value",
  254. globals: globalObject
  255. });
  256. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  257. try {
  258. esValue[implSymbol]["value"] = V;
  259. } finally {
  260. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  261. }
  262. }
  263. get willValidate() {
  264. const esValue = this !== null && this !== undefined ? this : globalObject;
  265. if (!exports.is(esValue)) {
  266. throw new globalObject.TypeError(
  267. "'get willValidate' called on an object that is not a valid instance of HTMLOutputElement."
  268. );
  269. }
  270. return esValue[implSymbol]["willValidate"];
  271. }
  272. get validity() {
  273. const esValue = this !== null && this !== undefined ? this : globalObject;
  274. if (!exports.is(esValue)) {
  275. throw new globalObject.TypeError(
  276. "'get validity' called on an object that is not a valid instance of HTMLOutputElement."
  277. );
  278. }
  279. return utils.tryWrapperForImpl(esValue[implSymbol]["validity"]);
  280. }
  281. get validationMessage() {
  282. const esValue = this !== null && this !== undefined ? this : globalObject;
  283. if (!exports.is(esValue)) {
  284. throw new globalObject.TypeError(
  285. "'get validationMessage' called on an object that is not a valid instance of HTMLOutputElement."
  286. );
  287. }
  288. return esValue[implSymbol]["validationMessage"];
  289. }
  290. get labels() {
  291. const esValue = this !== null && this !== undefined ? this : globalObject;
  292. if (!exports.is(esValue)) {
  293. throw new globalObject.TypeError(
  294. "'get labels' called on an object that is not a valid instance of HTMLOutputElement."
  295. );
  296. }
  297. return utils.tryWrapperForImpl(esValue[implSymbol]["labels"]);
  298. }
  299. }
  300. Object.defineProperties(HTMLOutputElement.prototype, {
  301. checkValidity: { enumerable: true },
  302. reportValidity: { enumerable: true },
  303. setCustomValidity: { enumerable: true },
  304. htmlFor: { enumerable: true },
  305. form: { enumerable: true },
  306. name: { enumerable: true },
  307. type: { enumerable: true },
  308. defaultValue: { enumerable: true },
  309. value: { enumerable: true },
  310. willValidate: { enumerable: true },
  311. validity: { enumerable: true },
  312. validationMessage: { enumerable: true },
  313. labels: { enumerable: true },
  314. [Symbol.toStringTag]: { value: "HTMLOutputElement", configurable: true }
  315. });
  316. ctorRegistry[interfaceName] = HTMLOutputElement;
  317. Object.defineProperty(globalObject, interfaceName, {
  318. configurable: true,
  319. writable: true,
  320. value: HTMLOutputElement
  321. });
  322. };
  323. const Impl = require("../../jsdom/living/nodes/HTMLOutputElement-impl.js");