HTMLButtonElement.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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 = "HTMLButtonElement";
  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 'HTMLButtonElement'.`);
  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]["HTMLButtonElement"].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 HTMLButtonElement 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 HTMLButtonElement."
  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 HTMLButtonElement."
  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 HTMLButtonElement."
  106. );
  107. }
  108. if (arguments.length < 1) {
  109. throw new globalObject.TypeError(
  110. `Failed to execute 'setCustomValidity' on 'HTMLButtonElement': 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 'HTMLButtonElement': parameter 1",
  118. globals: globalObject
  119. });
  120. args.push(curArg);
  121. }
  122. return esValue[implSymbol].setCustomValidity(...args);
  123. }
  124. get autofocus() {
  125. const esValue = this !== null && this !== undefined ? this : globalObject;
  126. if (!exports.is(esValue)) {
  127. throw new globalObject.TypeError(
  128. "'get autofocus' called on an object that is not a valid instance of HTMLButtonElement."
  129. );
  130. }
  131. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  132. try {
  133. return esValue[implSymbol]._reflectGetTheContentAttribute("autofocus") !== null;
  134. } finally {
  135. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  136. }
  137. }
  138. set autofocus(V) {
  139. const esValue = this !== null && this !== undefined ? this : globalObject;
  140. if (!exports.is(esValue)) {
  141. throw new globalObject.TypeError(
  142. "'set autofocus' called on an object that is not a valid instance of HTMLButtonElement."
  143. );
  144. }
  145. V = conversions["boolean"](V, {
  146. context: "Failed to set the 'autofocus' property on 'HTMLButtonElement': The provided value",
  147. globals: globalObject
  148. });
  149. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  150. try {
  151. if (V) {
  152. esValue[implSymbol]._reflectSetTheContentAttribute("autofocus", "");
  153. } else {
  154. esValue[implSymbol]._reflectDeleteTheContentAttribute("autofocus");
  155. }
  156. } finally {
  157. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  158. }
  159. }
  160. get disabled() {
  161. const esValue = this !== null && this !== undefined ? this : globalObject;
  162. if (!exports.is(esValue)) {
  163. throw new globalObject.TypeError(
  164. "'get disabled' called on an object that is not a valid instance of HTMLButtonElement."
  165. );
  166. }
  167. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  168. try {
  169. return esValue[implSymbol]._reflectGetTheContentAttribute("disabled") !== null;
  170. } finally {
  171. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  172. }
  173. }
  174. set disabled(V) {
  175. const esValue = this !== null && this !== undefined ? this : globalObject;
  176. if (!exports.is(esValue)) {
  177. throw new globalObject.TypeError(
  178. "'set disabled' called on an object that is not a valid instance of HTMLButtonElement."
  179. );
  180. }
  181. V = conversions["boolean"](V, {
  182. context: "Failed to set the 'disabled' property on 'HTMLButtonElement': The provided value",
  183. globals: globalObject
  184. });
  185. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  186. try {
  187. if (V) {
  188. esValue[implSymbol]._reflectSetTheContentAttribute("disabled", "");
  189. } else {
  190. esValue[implSymbol]._reflectDeleteTheContentAttribute("disabled");
  191. }
  192. } finally {
  193. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  194. }
  195. }
  196. get form() {
  197. const esValue = this !== null && this !== undefined ? this : globalObject;
  198. if (!exports.is(esValue)) {
  199. throw new globalObject.TypeError(
  200. "'get form' called on an object that is not a valid instance of HTMLButtonElement."
  201. );
  202. }
  203. return utils.tryWrapperForImpl(esValue[implSymbol]["form"]);
  204. }
  205. get formNoValidate() {
  206. const esValue = this !== null && this !== undefined ? this : globalObject;
  207. if (!exports.is(esValue)) {
  208. throw new globalObject.TypeError(
  209. "'get formNoValidate' called on an object that is not a valid instance of HTMLButtonElement."
  210. );
  211. }
  212. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  213. try {
  214. return esValue[implSymbol]._reflectGetTheContentAttribute("formnovalidate") !== null;
  215. } finally {
  216. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  217. }
  218. }
  219. set formNoValidate(V) {
  220. const esValue = this !== null && this !== undefined ? this : globalObject;
  221. if (!exports.is(esValue)) {
  222. throw new globalObject.TypeError(
  223. "'set formNoValidate' called on an object that is not a valid instance of HTMLButtonElement."
  224. );
  225. }
  226. V = conversions["boolean"](V, {
  227. context: "Failed to set the 'formNoValidate' property on 'HTMLButtonElement': The provided value",
  228. globals: globalObject
  229. });
  230. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  231. try {
  232. if (V) {
  233. esValue[implSymbol]._reflectSetTheContentAttribute("formnovalidate", "");
  234. } else {
  235. esValue[implSymbol]._reflectDeleteTheContentAttribute("formnovalidate");
  236. }
  237. } finally {
  238. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  239. }
  240. }
  241. get formTarget() {
  242. const esValue = this !== null && this !== undefined ? this : globalObject;
  243. if (!exports.is(esValue)) {
  244. throw new globalObject.TypeError(
  245. "'get formTarget' called on an object that is not a valid instance of HTMLButtonElement."
  246. );
  247. }
  248. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  249. try {
  250. const value = esValue[implSymbol]._reflectGetTheContentAttribute("formtarget");
  251. return value === null ? "" : value;
  252. } finally {
  253. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  254. }
  255. }
  256. set formTarget(V) {
  257. const esValue = this !== null && this !== undefined ? this : globalObject;
  258. if (!exports.is(esValue)) {
  259. throw new globalObject.TypeError(
  260. "'set formTarget' called on an object that is not a valid instance of HTMLButtonElement."
  261. );
  262. }
  263. V = conversions["DOMString"](V, {
  264. context: "Failed to set the 'formTarget' property on 'HTMLButtonElement': The provided value",
  265. globals: globalObject
  266. });
  267. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  268. try {
  269. esValue[implSymbol]._reflectSetTheContentAttribute("formtarget", V);
  270. } finally {
  271. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  272. }
  273. }
  274. get name() {
  275. const esValue = this !== null && this !== undefined ? this : globalObject;
  276. if (!exports.is(esValue)) {
  277. throw new globalObject.TypeError(
  278. "'get name' called on an object that is not a valid instance of HTMLButtonElement."
  279. );
  280. }
  281. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  282. try {
  283. const value = esValue[implSymbol]._reflectGetTheContentAttribute("name");
  284. return value === null ? "" : value;
  285. } finally {
  286. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  287. }
  288. }
  289. set name(V) {
  290. const esValue = this !== null && this !== undefined ? this : globalObject;
  291. if (!exports.is(esValue)) {
  292. throw new globalObject.TypeError(
  293. "'set name' called on an object that is not a valid instance of HTMLButtonElement."
  294. );
  295. }
  296. V = conversions["DOMString"](V, {
  297. context: "Failed to set the 'name' property on 'HTMLButtonElement': The provided value",
  298. globals: globalObject
  299. });
  300. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  301. try {
  302. esValue[implSymbol]._reflectSetTheContentAttribute("name", V);
  303. } finally {
  304. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  305. }
  306. }
  307. get type() {
  308. const esValue = this !== null && this !== undefined ? this : globalObject;
  309. if (!exports.is(esValue)) {
  310. throw new globalObject.TypeError(
  311. "'get type' called on an object that is not a valid instance of HTMLButtonElement."
  312. );
  313. }
  314. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  315. try {
  316. return esValue[implSymbol]["type"];
  317. } finally {
  318. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  319. }
  320. }
  321. set type(V) {
  322. const esValue = this !== null && this !== undefined ? this : globalObject;
  323. if (!exports.is(esValue)) {
  324. throw new globalObject.TypeError(
  325. "'set type' called on an object that is not a valid instance of HTMLButtonElement."
  326. );
  327. }
  328. V = conversions["DOMString"](V, {
  329. context: "Failed to set the 'type' property on 'HTMLButtonElement': The provided value",
  330. globals: globalObject
  331. });
  332. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  333. try {
  334. esValue[implSymbol]["type"] = V;
  335. } finally {
  336. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  337. }
  338. }
  339. get value() {
  340. const esValue = this !== null && this !== undefined ? this : globalObject;
  341. if (!exports.is(esValue)) {
  342. throw new globalObject.TypeError(
  343. "'get value' called on an object that is not a valid instance of HTMLButtonElement."
  344. );
  345. }
  346. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  347. try {
  348. const value = esValue[implSymbol]._reflectGetTheContentAttribute("value");
  349. return value === null ? "" : value;
  350. } finally {
  351. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  352. }
  353. }
  354. set value(V) {
  355. const esValue = this !== null && this !== undefined ? this : globalObject;
  356. if (!exports.is(esValue)) {
  357. throw new globalObject.TypeError(
  358. "'set value' called on an object that is not a valid instance of HTMLButtonElement."
  359. );
  360. }
  361. V = conversions["DOMString"](V, {
  362. context: "Failed to set the 'value' property on 'HTMLButtonElement': The provided value",
  363. globals: globalObject
  364. });
  365. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  366. try {
  367. esValue[implSymbol]._reflectSetTheContentAttribute("value", V);
  368. } finally {
  369. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  370. }
  371. }
  372. get willValidate() {
  373. const esValue = this !== null && this !== undefined ? this : globalObject;
  374. if (!exports.is(esValue)) {
  375. throw new globalObject.TypeError(
  376. "'get willValidate' called on an object that is not a valid instance of HTMLButtonElement."
  377. );
  378. }
  379. return esValue[implSymbol]["willValidate"];
  380. }
  381. get validity() {
  382. const esValue = this !== null && this !== undefined ? this : globalObject;
  383. if (!exports.is(esValue)) {
  384. throw new globalObject.TypeError(
  385. "'get validity' called on an object that is not a valid instance of HTMLButtonElement."
  386. );
  387. }
  388. return utils.tryWrapperForImpl(esValue[implSymbol]["validity"]);
  389. }
  390. get validationMessage() {
  391. const esValue = this !== null && this !== undefined ? this : globalObject;
  392. if (!exports.is(esValue)) {
  393. throw new globalObject.TypeError(
  394. "'get validationMessage' called on an object that is not a valid instance of HTMLButtonElement."
  395. );
  396. }
  397. return esValue[implSymbol]["validationMessage"];
  398. }
  399. get labels() {
  400. const esValue = this !== null && this !== undefined ? this : globalObject;
  401. if (!exports.is(esValue)) {
  402. throw new globalObject.TypeError(
  403. "'get labels' called on an object that is not a valid instance of HTMLButtonElement."
  404. );
  405. }
  406. return utils.tryWrapperForImpl(esValue[implSymbol]["labels"]);
  407. }
  408. }
  409. Object.defineProperties(HTMLButtonElement.prototype, {
  410. checkValidity: { enumerable: true },
  411. reportValidity: { enumerable: true },
  412. setCustomValidity: { enumerable: true },
  413. autofocus: { enumerable: true },
  414. disabled: { enumerable: true },
  415. form: { enumerable: true },
  416. formNoValidate: { enumerable: true },
  417. formTarget: { enumerable: true },
  418. name: { enumerable: true },
  419. type: { enumerable: true },
  420. value: { enumerable: true },
  421. willValidate: { enumerable: true },
  422. validity: { enumerable: true },
  423. validationMessage: { enumerable: true },
  424. labels: { enumerable: true },
  425. [Symbol.toStringTag]: { value: "HTMLButtonElement", configurable: true }
  426. });
  427. ctorRegistry[interfaceName] = HTMLButtonElement;
  428. Object.defineProperty(globalObject, interfaceName, {
  429. configurable: true,
  430. writable: true,
  431. value: HTMLButtonElement
  432. });
  433. };
  434. const Impl = require("../../jsdom/living/nodes/HTMLButtonElement-impl.js");