HTMLOptionElement.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 = "HTMLOptionElement";
  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 'HTMLOptionElement'.`);
  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]["HTMLOptionElement"].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 HTMLOptionElement extends globalObject.HTMLElement {
  80. constructor() {
  81. return HTMLConstructor_jsdom_living_helpers_html_constructor(globalObject, interfaceName, new.target);
  82. }
  83. get disabled() {
  84. const esValue = this !== null && this !== undefined ? this : globalObject;
  85. if (!exports.is(esValue)) {
  86. throw new globalObject.TypeError(
  87. "'get disabled' called on an object that is not a valid instance of HTMLOptionElement."
  88. );
  89. }
  90. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  91. try {
  92. return esValue[implSymbol]._reflectGetTheContentAttribute("disabled") !== null;
  93. } finally {
  94. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  95. }
  96. }
  97. set disabled(V) {
  98. const esValue = this !== null && this !== undefined ? this : globalObject;
  99. if (!exports.is(esValue)) {
  100. throw new globalObject.TypeError(
  101. "'set disabled' called on an object that is not a valid instance of HTMLOptionElement."
  102. );
  103. }
  104. V = conversions["boolean"](V, {
  105. context: "Failed to set the 'disabled' property on 'HTMLOptionElement': The provided value",
  106. globals: globalObject
  107. });
  108. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  109. try {
  110. if (V) {
  111. esValue[implSymbol]._reflectSetTheContentAttribute("disabled", "");
  112. } else {
  113. esValue[implSymbol]._reflectDeleteTheContentAttribute("disabled");
  114. }
  115. } finally {
  116. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  117. }
  118. }
  119. get form() {
  120. const esValue = this !== null && this !== undefined ? this : globalObject;
  121. if (!exports.is(esValue)) {
  122. throw new globalObject.TypeError(
  123. "'get form' called on an object that is not a valid instance of HTMLOptionElement."
  124. );
  125. }
  126. return utils.tryWrapperForImpl(esValue[implSymbol]["form"]);
  127. }
  128. get label() {
  129. const esValue = this !== null && this !== undefined ? this : globalObject;
  130. if (!exports.is(esValue)) {
  131. throw new globalObject.TypeError(
  132. "'get label' called on an object that is not a valid instance of HTMLOptionElement."
  133. );
  134. }
  135. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  136. try {
  137. return esValue[implSymbol]["label"];
  138. } finally {
  139. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  140. }
  141. }
  142. set label(V) {
  143. const esValue = this !== null && this !== undefined ? this : globalObject;
  144. if (!exports.is(esValue)) {
  145. throw new globalObject.TypeError(
  146. "'set label' called on an object that is not a valid instance of HTMLOptionElement."
  147. );
  148. }
  149. V = conversions["DOMString"](V, {
  150. context: "Failed to set the 'label' property on 'HTMLOptionElement': The provided value",
  151. globals: globalObject
  152. });
  153. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  154. try {
  155. esValue[implSymbol]["label"] = V;
  156. } finally {
  157. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  158. }
  159. }
  160. get defaultSelected() {
  161. const esValue = this !== null && this !== undefined ? this : globalObject;
  162. if (!exports.is(esValue)) {
  163. throw new globalObject.TypeError(
  164. "'get defaultSelected' called on an object that is not a valid instance of HTMLOptionElement."
  165. );
  166. }
  167. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  168. try {
  169. return esValue[implSymbol]._reflectGetTheContentAttribute("selected") !== null;
  170. } finally {
  171. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  172. }
  173. }
  174. set defaultSelected(V) {
  175. const esValue = this !== null && this !== undefined ? this : globalObject;
  176. if (!exports.is(esValue)) {
  177. throw new globalObject.TypeError(
  178. "'set defaultSelected' called on an object that is not a valid instance of HTMLOptionElement."
  179. );
  180. }
  181. V = conversions["boolean"](V, {
  182. context: "Failed to set the 'defaultSelected' property on 'HTMLOptionElement': The provided value",
  183. globals: globalObject
  184. });
  185. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  186. try {
  187. if (V) {
  188. esValue[implSymbol]._reflectSetTheContentAttribute("selected", "");
  189. } else {
  190. esValue[implSymbol]._reflectDeleteTheContentAttribute("selected");
  191. }
  192. } finally {
  193. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  194. }
  195. }
  196. get selected() {
  197. const esValue = this !== null && this !== undefined ? this : globalObject;
  198. if (!exports.is(esValue)) {
  199. throw new globalObject.TypeError(
  200. "'get selected' called on an object that is not a valid instance of HTMLOptionElement."
  201. );
  202. }
  203. return esValue[implSymbol]["selected"];
  204. }
  205. set selected(V) {
  206. const esValue = this !== null && this !== undefined ? this : globalObject;
  207. if (!exports.is(esValue)) {
  208. throw new globalObject.TypeError(
  209. "'set selected' called on an object that is not a valid instance of HTMLOptionElement."
  210. );
  211. }
  212. V = conversions["boolean"](V, {
  213. context: "Failed to set the 'selected' property on 'HTMLOptionElement': The provided value",
  214. globals: globalObject
  215. });
  216. esValue[implSymbol]["selected"] = V;
  217. }
  218. get value() {
  219. const esValue = this !== null && this !== undefined ? this : globalObject;
  220. if (!exports.is(esValue)) {
  221. throw new globalObject.TypeError(
  222. "'get value' called on an object that is not a valid instance of HTMLOptionElement."
  223. );
  224. }
  225. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  226. try {
  227. return esValue[implSymbol]["value"];
  228. } finally {
  229. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  230. }
  231. }
  232. set value(V) {
  233. const esValue = this !== null && this !== undefined ? this : globalObject;
  234. if (!exports.is(esValue)) {
  235. throw new globalObject.TypeError(
  236. "'set value' called on an object that is not a valid instance of HTMLOptionElement."
  237. );
  238. }
  239. V = conversions["DOMString"](V, {
  240. context: "Failed to set the 'value' property on 'HTMLOptionElement': The provided value",
  241. globals: globalObject
  242. });
  243. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  244. try {
  245. esValue[implSymbol]["value"] = V;
  246. } finally {
  247. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  248. }
  249. }
  250. get text() {
  251. const esValue = this !== null && this !== undefined ? this : globalObject;
  252. if (!exports.is(esValue)) {
  253. throw new globalObject.TypeError(
  254. "'get text' called on an object that is not a valid instance of HTMLOptionElement."
  255. );
  256. }
  257. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  258. try {
  259. return esValue[implSymbol]["text"];
  260. } finally {
  261. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  262. }
  263. }
  264. set text(V) {
  265. const esValue = this !== null && this !== undefined ? this : globalObject;
  266. if (!exports.is(esValue)) {
  267. throw new globalObject.TypeError(
  268. "'set text' called on an object that is not a valid instance of HTMLOptionElement."
  269. );
  270. }
  271. V = conversions["DOMString"](V, {
  272. context: "Failed to set the 'text' property on 'HTMLOptionElement': The provided value",
  273. globals: globalObject
  274. });
  275. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  276. try {
  277. esValue[implSymbol]["text"] = V;
  278. } finally {
  279. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  280. }
  281. }
  282. get index() {
  283. const esValue = this !== null && this !== undefined ? this : globalObject;
  284. if (!exports.is(esValue)) {
  285. throw new globalObject.TypeError(
  286. "'get index' called on an object that is not a valid instance of HTMLOptionElement."
  287. );
  288. }
  289. return esValue[implSymbol]["index"];
  290. }
  291. }
  292. Object.defineProperties(HTMLOptionElement.prototype, {
  293. disabled: { enumerable: true },
  294. form: { enumerable: true },
  295. label: { enumerable: true },
  296. defaultSelected: { enumerable: true },
  297. selected: { enumerable: true },
  298. value: { enumerable: true },
  299. text: { enumerable: true },
  300. index: { enumerable: true },
  301. [Symbol.toStringTag]: { value: "HTMLOptionElement", configurable: true }
  302. });
  303. ctorRegistry[interfaceName] = HTMLOptionElement;
  304. Object.defineProperty(globalObject, interfaceName, {
  305. configurable: true,
  306. writable: true,
  307. value: HTMLOptionElement
  308. });
  309. };
  310. const Impl = require("../../jsdom/living/nodes/HTMLOptionElement-impl.js");