HTMLSelectElement.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  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 HTMLOptionElement = require("./HTMLOptionElement.js");
  7. const HTMLOptGroupElement = require("./HTMLOptGroupElement.js");
  8. const HTMLElement = require("./HTMLElement.js");
  9. const ceReactionsPreSteps_jsdom_living_helpers_custom_elements =
  10. require("../../jsdom/living/helpers/custom-elements.js").ceReactionsPreSteps;
  11. const ceReactionsPostSteps_jsdom_living_helpers_custom_elements =
  12. require("../../jsdom/living/helpers/custom-elements.js").ceReactionsPostSteps;
  13. const parseNonNegativeInteger_jsdom_living_helpers_strings =
  14. require("../../jsdom/living/helpers/strings.js").parseNonNegativeInteger;
  15. const implSymbol = utils.implSymbol;
  16. const ctorRegistrySymbol = utils.ctorRegistrySymbol;
  17. const interfaceName = "HTMLSelectElement";
  18. exports.is = value => {
  19. return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
  20. };
  21. exports.isImpl = value => {
  22. return utils.isObject(value) && value instanceof Impl.implementation;
  23. };
  24. exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
  25. if (exports.is(value)) {
  26. return utils.implForWrapper(value);
  27. }
  28. throw new globalObject.TypeError(`${context} is not of type 'HTMLSelectElement'.`);
  29. };
  30. function makeWrapper(globalObject, newTarget) {
  31. let proto;
  32. if (newTarget !== undefined) {
  33. proto = newTarget.prototype;
  34. }
  35. if (!utils.isObject(proto)) {
  36. proto = globalObject[ctorRegistrySymbol]["HTMLSelectElement"].prototype;
  37. }
  38. return Object.create(proto);
  39. }
  40. function makeProxy(wrapper, globalObject) {
  41. let proxyHandler = proxyHandlerCache.get(globalObject);
  42. if (proxyHandler === undefined) {
  43. proxyHandler = new ProxyHandler(globalObject);
  44. proxyHandlerCache.set(globalObject, proxyHandler);
  45. }
  46. return new Proxy(wrapper, proxyHandler);
  47. }
  48. exports.create = (globalObject, constructorArgs, privateData) => {
  49. const wrapper = makeWrapper(globalObject);
  50. return exports.setup(wrapper, globalObject, constructorArgs, privateData);
  51. };
  52. exports.createImpl = (globalObject, constructorArgs, privateData) => {
  53. const wrapper = exports.create(globalObject, constructorArgs, privateData);
  54. return utils.implForWrapper(wrapper);
  55. };
  56. exports._internalSetup = (wrapper, globalObject) => {
  57. HTMLElement._internalSetup(wrapper, globalObject);
  58. };
  59. exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
  60. privateData.wrapper = wrapper;
  61. exports._internalSetup(wrapper, globalObject);
  62. Object.defineProperty(wrapper, implSymbol, {
  63. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  64. configurable: true
  65. });
  66. wrapper = makeProxy(wrapper, globalObject);
  67. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  68. if (Impl.init) {
  69. Impl.init(wrapper[implSymbol]);
  70. }
  71. return wrapper;
  72. };
  73. exports.new = (globalObject, newTarget) => {
  74. let wrapper = makeWrapper(globalObject, newTarget);
  75. exports._internalSetup(wrapper, globalObject);
  76. Object.defineProperty(wrapper, implSymbol, {
  77. value: Object.create(Impl.implementation.prototype),
  78. configurable: true
  79. });
  80. wrapper = makeProxy(wrapper, globalObject);
  81. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  82. if (Impl.init) {
  83. Impl.init(wrapper[implSymbol]);
  84. }
  85. return wrapper[implSymbol];
  86. };
  87. const exposed = new Set(["Window"]);
  88. exports.install = (globalObject, globalNames) => {
  89. if (!globalNames.some(globalName => exposed.has(globalName))) {
  90. return;
  91. }
  92. const ctorRegistry = utils.initCtorRegistry(globalObject);
  93. class HTMLSelectElement extends globalObject.HTMLElement {
  94. constructor() {
  95. return HTMLConstructor_jsdom_living_helpers_html_constructor(globalObject, interfaceName, new.target);
  96. }
  97. item(index) {
  98. const esValue = this !== null && this !== undefined ? this : globalObject;
  99. if (!exports.is(esValue)) {
  100. throw new globalObject.TypeError(
  101. "'item' called on an object that is not a valid instance of HTMLSelectElement."
  102. );
  103. }
  104. if (arguments.length < 1) {
  105. throw new globalObject.TypeError(
  106. `Failed to execute 'item' on 'HTMLSelectElement': 1 argument required, but only ${arguments.length} present.`
  107. );
  108. }
  109. const args = [];
  110. {
  111. let curArg = arguments[0];
  112. curArg = conversions["unsigned long"](curArg, {
  113. context: "Failed to execute 'item' on 'HTMLSelectElement': parameter 1",
  114. globals: globalObject
  115. });
  116. args.push(curArg);
  117. }
  118. return utils.tryWrapperForImpl(esValue[implSymbol].item(...args));
  119. }
  120. namedItem(name) {
  121. const esValue = this !== null && this !== undefined ? this : globalObject;
  122. if (!exports.is(esValue)) {
  123. throw new globalObject.TypeError(
  124. "'namedItem' called on an object that is not a valid instance of HTMLSelectElement."
  125. );
  126. }
  127. if (arguments.length < 1) {
  128. throw new globalObject.TypeError(
  129. `Failed to execute 'namedItem' on 'HTMLSelectElement': 1 argument required, but only ${arguments.length} present.`
  130. );
  131. }
  132. const args = [];
  133. {
  134. let curArg = arguments[0];
  135. curArg = conversions["DOMString"](curArg, {
  136. context: "Failed to execute 'namedItem' on 'HTMLSelectElement': parameter 1",
  137. globals: globalObject
  138. });
  139. args.push(curArg);
  140. }
  141. return utils.tryWrapperForImpl(esValue[implSymbol].namedItem(...args));
  142. }
  143. add(element) {
  144. const esValue = this !== null && this !== undefined ? this : globalObject;
  145. if (!exports.is(esValue)) {
  146. throw new globalObject.TypeError(
  147. "'add' called on an object that is not a valid instance of HTMLSelectElement."
  148. );
  149. }
  150. if (arguments.length < 1) {
  151. throw new globalObject.TypeError(
  152. `Failed to execute 'add' on 'HTMLSelectElement': 1 argument required, but only ${arguments.length} present.`
  153. );
  154. }
  155. const args = [];
  156. {
  157. let curArg = arguments[0];
  158. if (HTMLOptionElement.is(curArg) || HTMLOptGroupElement.is(curArg)) {
  159. curArg = utils.implForWrapper(curArg);
  160. } else {
  161. throw new globalObject.TypeError(
  162. "Failed to execute 'add' on 'HTMLSelectElement': parameter 1" + " is not of any supported type."
  163. );
  164. }
  165. args.push(curArg);
  166. }
  167. {
  168. let curArg = arguments[1];
  169. if (curArg !== undefined) {
  170. if (curArg === null || curArg === undefined) {
  171. curArg = null;
  172. } else {
  173. if (HTMLElement.is(curArg)) {
  174. curArg = utils.implForWrapper(curArg);
  175. } else if (typeof curArg === "number") {
  176. curArg = conversions["long"](curArg, {
  177. context: "Failed to execute 'add' on 'HTMLSelectElement': parameter 2",
  178. globals: globalObject
  179. });
  180. } else {
  181. curArg = conversions["long"](curArg, {
  182. context: "Failed to execute 'add' on 'HTMLSelectElement': parameter 2",
  183. globals: globalObject
  184. });
  185. }
  186. }
  187. } else {
  188. curArg = null;
  189. }
  190. args.push(curArg);
  191. }
  192. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  193. try {
  194. return esValue[implSymbol].add(...args);
  195. } finally {
  196. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  197. }
  198. }
  199. remove() {
  200. const esValue = this !== null && this !== undefined ? this : globalObject;
  201. if (!exports.is(esValue)) {
  202. throw new globalObject.TypeError(
  203. "'remove' called on an object that is not a valid instance of HTMLSelectElement."
  204. );
  205. }
  206. const args = [];
  207. switch (arguments.length) {
  208. case 0:
  209. break;
  210. default: {
  211. let curArg = arguments[0];
  212. curArg = conversions["long"](curArg, {
  213. context: "Failed to execute 'remove' on 'HTMLSelectElement': parameter 1",
  214. globals: globalObject
  215. });
  216. args.push(curArg);
  217. }
  218. }
  219. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  220. try {
  221. return esValue[implSymbol].remove(...args);
  222. } finally {
  223. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  224. }
  225. }
  226. checkValidity() {
  227. const esValue = this !== null && this !== undefined ? this : globalObject;
  228. if (!exports.is(esValue)) {
  229. throw new globalObject.TypeError(
  230. "'checkValidity' called on an object that is not a valid instance of HTMLSelectElement."
  231. );
  232. }
  233. return esValue[implSymbol].checkValidity();
  234. }
  235. reportValidity() {
  236. const esValue = this !== null && this !== undefined ? this : globalObject;
  237. if (!exports.is(esValue)) {
  238. throw new globalObject.TypeError(
  239. "'reportValidity' called on an object that is not a valid instance of HTMLSelectElement."
  240. );
  241. }
  242. return esValue[implSymbol].reportValidity();
  243. }
  244. setCustomValidity(error) {
  245. const esValue = this !== null && this !== undefined ? this : globalObject;
  246. if (!exports.is(esValue)) {
  247. throw new globalObject.TypeError(
  248. "'setCustomValidity' called on an object that is not a valid instance of HTMLSelectElement."
  249. );
  250. }
  251. if (arguments.length < 1) {
  252. throw new globalObject.TypeError(
  253. `Failed to execute 'setCustomValidity' on 'HTMLSelectElement': 1 argument required, but only ${arguments.length} present.`
  254. );
  255. }
  256. const args = [];
  257. {
  258. let curArg = arguments[0];
  259. curArg = conversions["DOMString"](curArg, {
  260. context: "Failed to execute 'setCustomValidity' on 'HTMLSelectElement': parameter 1",
  261. globals: globalObject
  262. });
  263. args.push(curArg);
  264. }
  265. return esValue[implSymbol].setCustomValidity(...args);
  266. }
  267. get autofocus() {
  268. const esValue = this !== null && this !== undefined ? this : globalObject;
  269. if (!exports.is(esValue)) {
  270. throw new globalObject.TypeError(
  271. "'get autofocus' called on an object that is not a valid instance of HTMLSelectElement."
  272. );
  273. }
  274. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  275. try {
  276. return esValue[implSymbol]._reflectGetTheContentAttribute("autofocus") !== null;
  277. } finally {
  278. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  279. }
  280. }
  281. set autofocus(V) {
  282. const esValue = this !== null && this !== undefined ? this : globalObject;
  283. if (!exports.is(esValue)) {
  284. throw new globalObject.TypeError(
  285. "'set autofocus' called on an object that is not a valid instance of HTMLSelectElement."
  286. );
  287. }
  288. V = conversions["boolean"](V, {
  289. context: "Failed to set the 'autofocus' property on 'HTMLSelectElement': The provided value",
  290. globals: globalObject
  291. });
  292. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  293. try {
  294. if (V) {
  295. esValue[implSymbol]._reflectSetTheContentAttribute("autofocus", "");
  296. } else {
  297. esValue[implSymbol]._reflectDeleteTheContentAttribute("autofocus");
  298. }
  299. } finally {
  300. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  301. }
  302. }
  303. get disabled() {
  304. const esValue = this !== null && this !== undefined ? this : globalObject;
  305. if (!exports.is(esValue)) {
  306. throw new globalObject.TypeError(
  307. "'get disabled' called on an object that is not a valid instance of HTMLSelectElement."
  308. );
  309. }
  310. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  311. try {
  312. return esValue[implSymbol]._reflectGetTheContentAttribute("disabled") !== null;
  313. } finally {
  314. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  315. }
  316. }
  317. set disabled(V) {
  318. const esValue = this !== null && this !== undefined ? this : globalObject;
  319. if (!exports.is(esValue)) {
  320. throw new globalObject.TypeError(
  321. "'set disabled' called on an object that is not a valid instance of HTMLSelectElement."
  322. );
  323. }
  324. V = conversions["boolean"](V, {
  325. context: "Failed to set the 'disabled' property on 'HTMLSelectElement': The provided value",
  326. globals: globalObject
  327. });
  328. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  329. try {
  330. if (V) {
  331. esValue[implSymbol]._reflectSetTheContentAttribute("disabled", "");
  332. } else {
  333. esValue[implSymbol]._reflectDeleteTheContentAttribute("disabled");
  334. }
  335. } finally {
  336. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  337. }
  338. }
  339. get form() {
  340. const esValue = this !== null && this !== undefined ? this : globalObject;
  341. if (!exports.is(esValue)) {
  342. throw new globalObject.TypeError(
  343. "'get form' called on an object that is not a valid instance of HTMLSelectElement."
  344. );
  345. }
  346. return utils.tryWrapperForImpl(esValue[implSymbol]["form"]);
  347. }
  348. get multiple() {
  349. const esValue = this !== null && this !== undefined ? this : globalObject;
  350. if (!exports.is(esValue)) {
  351. throw new globalObject.TypeError(
  352. "'get multiple' called on an object that is not a valid instance of HTMLSelectElement."
  353. );
  354. }
  355. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  356. try {
  357. return esValue[implSymbol]._reflectGetTheContentAttribute("multiple") !== null;
  358. } finally {
  359. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  360. }
  361. }
  362. set multiple(V) {
  363. const esValue = this !== null && this !== undefined ? this : globalObject;
  364. if (!exports.is(esValue)) {
  365. throw new globalObject.TypeError(
  366. "'set multiple' called on an object that is not a valid instance of HTMLSelectElement."
  367. );
  368. }
  369. V = conversions["boolean"](V, {
  370. context: "Failed to set the 'multiple' property on 'HTMLSelectElement': The provided value",
  371. globals: globalObject
  372. });
  373. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  374. try {
  375. if (V) {
  376. esValue[implSymbol]._reflectSetTheContentAttribute("multiple", "");
  377. } else {
  378. esValue[implSymbol]._reflectDeleteTheContentAttribute("multiple");
  379. }
  380. } finally {
  381. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  382. }
  383. }
  384. get name() {
  385. const esValue = this !== null && this !== undefined ? this : globalObject;
  386. if (!exports.is(esValue)) {
  387. throw new globalObject.TypeError(
  388. "'get name' called on an object that is not a valid instance of HTMLSelectElement."
  389. );
  390. }
  391. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  392. try {
  393. const value = esValue[implSymbol]._reflectGetTheContentAttribute("name");
  394. return value === null ? "" : value;
  395. } finally {
  396. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  397. }
  398. }
  399. set name(V) {
  400. const esValue = this !== null && this !== undefined ? this : globalObject;
  401. if (!exports.is(esValue)) {
  402. throw new globalObject.TypeError(
  403. "'set name' called on an object that is not a valid instance of HTMLSelectElement."
  404. );
  405. }
  406. V = conversions["DOMString"](V, {
  407. context: "Failed to set the 'name' property on 'HTMLSelectElement': The provided value",
  408. globals: globalObject
  409. });
  410. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  411. try {
  412. esValue[implSymbol]._reflectSetTheContentAttribute("name", V);
  413. } finally {
  414. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  415. }
  416. }
  417. get required() {
  418. const esValue = this !== null && this !== undefined ? this : globalObject;
  419. if (!exports.is(esValue)) {
  420. throw new globalObject.TypeError(
  421. "'get required' called on an object that is not a valid instance of HTMLSelectElement."
  422. );
  423. }
  424. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  425. try {
  426. return esValue[implSymbol]._reflectGetTheContentAttribute("required") !== null;
  427. } finally {
  428. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  429. }
  430. }
  431. set required(V) {
  432. const esValue = this !== null && this !== undefined ? this : globalObject;
  433. if (!exports.is(esValue)) {
  434. throw new globalObject.TypeError(
  435. "'set required' called on an object that is not a valid instance of HTMLSelectElement."
  436. );
  437. }
  438. V = conversions["boolean"](V, {
  439. context: "Failed to set the 'required' property on 'HTMLSelectElement': The provided value",
  440. globals: globalObject
  441. });
  442. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  443. try {
  444. if (V) {
  445. esValue[implSymbol]._reflectSetTheContentAttribute("required", "");
  446. } else {
  447. esValue[implSymbol]._reflectDeleteTheContentAttribute("required");
  448. }
  449. } finally {
  450. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  451. }
  452. }
  453. get size() {
  454. const esValue = this !== null && this !== undefined ? this : globalObject;
  455. if (!exports.is(esValue)) {
  456. throw new globalObject.TypeError(
  457. "'get size' called on an object that is not a valid instance of HTMLSelectElement."
  458. );
  459. }
  460. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  461. try {
  462. let value = esValue[implSymbol]._reflectGetTheContentAttribute("size");
  463. if (value !== null) {
  464. value = parseNonNegativeInteger_jsdom_living_helpers_strings(value);
  465. if (value !== null && value >= 0 && value <= 2147483647) {
  466. return value;
  467. }
  468. }
  469. return 0;
  470. } finally {
  471. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  472. }
  473. }
  474. set size(V) {
  475. const esValue = this !== null && this !== undefined ? this : globalObject;
  476. if (!exports.is(esValue)) {
  477. throw new globalObject.TypeError(
  478. "'set size' called on an object that is not a valid instance of HTMLSelectElement."
  479. );
  480. }
  481. V = conversions["unsigned long"](V, {
  482. context: "Failed to set the 'size' property on 'HTMLSelectElement': The provided value",
  483. globals: globalObject
  484. });
  485. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  486. try {
  487. const newValue = V <= 2147483647 && V >= 0 ? V : 0;
  488. esValue[implSymbol]._reflectSetTheContentAttribute("size", String(newValue));
  489. } finally {
  490. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  491. }
  492. }
  493. get type() {
  494. const esValue = this !== null && this !== undefined ? this : globalObject;
  495. if (!exports.is(esValue)) {
  496. throw new globalObject.TypeError(
  497. "'get type' called on an object that is not a valid instance of HTMLSelectElement."
  498. );
  499. }
  500. return esValue[implSymbol]["type"];
  501. }
  502. get options() {
  503. const esValue = this !== null && this !== undefined ? this : globalObject;
  504. if (!exports.is(esValue)) {
  505. throw new globalObject.TypeError(
  506. "'get options' called on an object that is not a valid instance of HTMLSelectElement."
  507. );
  508. }
  509. return utils.getSameObject(this, "options", () => {
  510. return utils.tryWrapperForImpl(esValue[implSymbol]["options"]);
  511. });
  512. }
  513. get length() {
  514. const esValue = this !== null && this !== undefined ? this : globalObject;
  515. if (!exports.is(esValue)) {
  516. throw new globalObject.TypeError(
  517. "'get length' called on an object that is not a valid instance of HTMLSelectElement."
  518. );
  519. }
  520. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  521. try {
  522. return esValue[implSymbol]["length"];
  523. } finally {
  524. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  525. }
  526. }
  527. set length(V) {
  528. const esValue = this !== null && this !== undefined ? this : globalObject;
  529. if (!exports.is(esValue)) {
  530. throw new globalObject.TypeError(
  531. "'set length' called on an object that is not a valid instance of HTMLSelectElement."
  532. );
  533. }
  534. V = conversions["unsigned long"](V, {
  535. context: "Failed to set the 'length' property on 'HTMLSelectElement': The provided value",
  536. globals: globalObject
  537. });
  538. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  539. try {
  540. esValue[implSymbol]["length"] = V;
  541. } finally {
  542. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  543. }
  544. }
  545. get selectedOptions() {
  546. const esValue = this !== null && this !== undefined ? this : globalObject;
  547. if (!exports.is(esValue)) {
  548. throw new globalObject.TypeError(
  549. "'get selectedOptions' called on an object that is not a valid instance of HTMLSelectElement."
  550. );
  551. }
  552. return utils.getSameObject(this, "selectedOptions", () => {
  553. return utils.tryWrapperForImpl(esValue[implSymbol]["selectedOptions"]);
  554. });
  555. }
  556. get selectedIndex() {
  557. const esValue = this !== null && this !== undefined ? this : globalObject;
  558. if (!exports.is(esValue)) {
  559. throw new globalObject.TypeError(
  560. "'get selectedIndex' called on an object that is not a valid instance of HTMLSelectElement."
  561. );
  562. }
  563. return esValue[implSymbol]["selectedIndex"];
  564. }
  565. set selectedIndex(V) {
  566. const esValue = this !== null && this !== undefined ? this : globalObject;
  567. if (!exports.is(esValue)) {
  568. throw new globalObject.TypeError(
  569. "'set selectedIndex' called on an object that is not a valid instance of HTMLSelectElement."
  570. );
  571. }
  572. V = conversions["long"](V, {
  573. context: "Failed to set the 'selectedIndex' property on 'HTMLSelectElement': The provided value",
  574. globals: globalObject
  575. });
  576. esValue[implSymbol]["selectedIndex"] = V;
  577. }
  578. get value() {
  579. const esValue = this !== null && this !== undefined ? this : globalObject;
  580. if (!exports.is(esValue)) {
  581. throw new globalObject.TypeError(
  582. "'get value' called on an object that is not a valid instance of HTMLSelectElement."
  583. );
  584. }
  585. return esValue[implSymbol]["value"];
  586. }
  587. set value(V) {
  588. const esValue = this !== null && this !== undefined ? this : globalObject;
  589. if (!exports.is(esValue)) {
  590. throw new globalObject.TypeError(
  591. "'set value' called on an object that is not a valid instance of HTMLSelectElement."
  592. );
  593. }
  594. V = conversions["DOMString"](V, {
  595. context: "Failed to set the 'value' property on 'HTMLSelectElement': The provided value",
  596. globals: globalObject
  597. });
  598. esValue[implSymbol]["value"] = V;
  599. }
  600. get willValidate() {
  601. const esValue = this !== null && this !== undefined ? this : globalObject;
  602. if (!exports.is(esValue)) {
  603. throw new globalObject.TypeError(
  604. "'get willValidate' called on an object that is not a valid instance of HTMLSelectElement."
  605. );
  606. }
  607. return esValue[implSymbol]["willValidate"];
  608. }
  609. get validity() {
  610. const esValue = this !== null && this !== undefined ? this : globalObject;
  611. if (!exports.is(esValue)) {
  612. throw new globalObject.TypeError(
  613. "'get validity' called on an object that is not a valid instance of HTMLSelectElement."
  614. );
  615. }
  616. return utils.tryWrapperForImpl(esValue[implSymbol]["validity"]);
  617. }
  618. get validationMessage() {
  619. const esValue = this !== null && this !== undefined ? this : globalObject;
  620. if (!exports.is(esValue)) {
  621. throw new globalObject.TypeError(
  622. "'get validationMessage' called on an object that is not a valid instance of HTMLSelectElement."
  623. );
  624. }
  625. return esValue[implSymbol]["validationMessage"];
  626. }
  627. get labels() {
  628. const esValue = this !== null && this !== undefined ? this : globalObject;
  629. if (!exports.is(esValue)) {
  630. throw new globalObject.TypeError(
  631. "'get labels' called on an object that is not a valid instance of HTMLSelectElement."
  632. );
  633. }
  634. return utils.tryWrapperForImpl(esValue[implSymbol]["labels"]);
  635. }
  636. }
  637. Object.defineProperties(HTMLSelectElement.prototype, {
  638. item: { enumerable: true },
  639. namedItem: { enumerable: true },
  640. add: { enumerable: true },
  641. remove: { enumerable: true },
  642. checkValidity: { enumerable: true },
  643. reportValidity: { enumerable: true },
  644. setCustomValidity: { enumerable: true },
  645. autofocus: { enumerable: true },
  646. disabled: { enumerable: true },
  647. form: { enumerable: true },
  648. multiple: { enumerable: true },
  649. name: { enumerable: true },
  650. required: { enumerable: true },
  651. size: { enumerable: true },
  652. type: { enumerable: true },
  653. options: { enumerable: true },
  654. length: { enumerable: true },
  655. selectedOptions: { enumerable: true },
  656. selectedIndex: { enumerable: true },
  657. value: { enumerable: true },
  658. willValidate: { enumerable: true },
  659. validity: { enumerable: true },
  660. validationMessage: { enumerable: true },
  661. labels: { enumerable: true },
  662. [Symbol.toStringTag]: { value: "HTMLSelectElement", configurable: true },
  663. [Symbol.iterator]: { value: globalObject.Array.prototype[Symbol.iterator], configurable: true, writable: true }
  664. });
  665. ctorRegistry[interfaceName] = HTMLSelectElement;
  666. Object.defineProperty(globalObject, interfaceName, {
  667. configurable: true,
  668. writable: true,
  669. value: HTMLSelectElement
  670. });
  671. };
  672. const proxyHandlerCache = new WeakMap();
  673. class ProxyHandler {
  674. constructor(globalObject) {
  675. this._globalObject = globalObject;
  676. }
  677. get(target, P, receiver) {
  678. if (typeof P === "symbol") {
  679. return Reflect.get(target, P, receiver);
  680. }
  681. const desc = this.getOwnPropertyDescriptor(target, P);
  682. if (desc === undefined) {
  683. const parent = Object.getPrototypeOf(target);
  684. if (parent === null) {
  685. return undefined;
  686. }
  687. return Reflect.get(target, P, receiver);
  688. }
  689. if (!desc.get && !desc.set) {
  690. return desc.value;
  691. }
  692. const getter = desc.get;
  693. if (getter === undefined) {
  694. return undefined;
  695. }
  696. return Reflect.apply(getter, receiver, []);
  697. }
  698. has(target, P) {
  699. if (typeof P === "symbol") {
  700. return Reflect.has(target, P);
  701. }
  702. const desc = this.getOwnPropertyDescriptor(target, P);
  703. if (desc !== undefined) {
  704. return true;
  705. }
  706. const parent = Object.getPrototypeOf(target);
  707. if (parent !== null) {
  708. return Reflect.has(parent, P);
  709. }
  710. return false;
  711. }
  712. ownKeys(target) {
  713. const keys = new Set();
  714. for (const key of target[implSymbol][utils.supportedPropertyIndices]) {
  715. keys.add(`${key}`);
  716. }
  717. for (const key of Reflect.ownKeys(target)) {
  718. keys.add(key);
  719. }
  720. return [...keys];
  721. }
  722. getOwnPropertyDescriptor(target, P) {
  723. if (typeof P === "symbol") {
  724. return Reflect.getOwnPropertyDescriptor(target, P);
  725. }
  726. let ignoreNamedProps = false;
  727. if (utils.isArrayIndexPropName(P)) {
  728. const index = P >>> 0;
  729. const indexedValue = target[implSymbol].item(index);
  730. if (indexedValue !== null) {
  731. return {
  732. writable: true,
  733. enumerable: true,
  734. configurable: true,
  735. value: utils.tryWrapperForImpl(indexedValue)
  736. };
  737. }
  738. ignoreNamedProps = true;
  739. }
  740. return Reflect.getOwnPropertyDescriptor(target, P);
  741. }
  742. set(target, P, V, receiver) {
  743. if (typeof P === "symbol") {
  744. return Reflect.set(target, P, V, receiver);
  745. }
  746. // The `receiver` argument refers to the Proxy exotic object or an object
  747. // that inherits from it, whereas `target` refers to the Proxy target:
  748. if (target[implSymbol][utils.wrapperSymbol] === receiver) {
  749. const globalObject = this._globalObject;
  750. if (utils.isArrayIndexPropName(P)) {
  751. const index = P >>> 0;
  752. let indexedValue = V;
  753. if (indexedValue === null || indexedValue === undefined) {
  754. indexedValue = null;
  755. } else {
  756. indexedValue = HTMLOptionElement.convert(globalObject, indexedValue, {
  757. context: "Failed to set the " + index + " property on 'HTMLSelectElement': The provided value"
  758. });
  759. }
  760. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  761. try {
  762. const creating = !(target[implSymbol].item(index) !== null);
  763. if (creating) {
  764. target[implSymbol][utils.indexedSetNew](index, indexedValue);
  765. } else {
  766. target[implSymbol][utils.indexedSetExisting](index, indexedValue);
  767. }
  768. } finally {
  769. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  770. }
  771. return true;
  772. }
  773. }
  774. let ownDesc;
  775. if (utils.isArrayIndexPropName(P)) {
  776. const index = P >>> 0;
  777. const indexedValue = target[implSymbol].item(index);
  778. if (indexedValue !== null) {
  779. ownDesc = {
  780. writable: true,
  781. enumerable: true,
  782. configurable: true,
  783. value: utils.tryWrapperForImpl(indexedValue)
  784. };
  785. }
  786. }
  787. if (ownDesc === undefined) {
  788. ownDesc = Reflect.getOwnPropertyDescriptor(target, P);
  789. }
  790. return utils.ordinarySetWithOwnDescriptor(target, P, V, receiver, ownDesc);
  791. }
  792. defineProperty(target, P, desc) {
  793. if (typeof P === "symbol") {
  794. return Reflect.defineProperty(target, P, desc);
  795. }
  796. const globalObject = this._globalObject;
  797. if (utils.isArrayIndexPropName(P)) {
  798. if (desc.get || desc.set) {
  799. return false;
  800. }
  801. const index = P >>> 0;
  802. let indexedValue = desc.value;
  803. if (indexedValue === null || indexedValue === undefined) {
  804. indexedValue = null;
  805. } else {
  806. indexedValue = HTMLOptionElement.convert(globalObject, indexedValue, {
  807. context: "Failed to set the " + index + " property on 'HTMLSelectElement': The provided value"
  808. });
  809. }
  810. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  811. try {
  812. const creating = !(target[implSymbol].item(index) !== null);
  813. if (creating) {
  814. target[implSymbol][utils.indexedSetNew](index, indexedValue);
  815. } else {
  816. target[implSymbol][utils.indexedSetExisting](index, indexedValue);
  817. }
  818. } finally {
  819. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  820. }
  821. return true;
  822. }
  823. return Reflect.defineProperty(target, P, desc);
  824. }
  825. deleteProperty(target, P) {
  826. if (typeof P === "symbol") {
  827. return Reflect.deleteProperty(target, P);
  828. }
  829. const globalObject = this._globalObject;
  830. if (utils.isArrayIndexPropName(P)) {
  831. const index = P >>> 0;
  832. return !(target[implSymbol].item(index) !== null);
  833. }
  834. return Reflect.deleteProperty(target, P);
  835. }
  836. preventExtensions() {
  837. return false;
  838. }
  839. }
  840. const Impl = require("../../jsdom/living/nodes/HTMLSelectElement-impl.js");