HTMLParamElement.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 = "HTMLParamElement";
  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 'HTMLParamElement'.`);
  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]["HTMLParamElement"].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 HTMLParamElement extends globalObject.HTMLElement {
  80. constructor() {
  81. return HTMLConstructor_jsdom_living_helpers_html_constructor(globalObject, interfaceName, new.target);
  82. }
  83. get name() {
  84. const esValue = this !== null && this !== undefined ? this : globalObject;
  85. if (!exports.is(esValue)) {
  86. throw new globalObject.TypeError(
  87. "'get name' called on an object that is not a valid instance of HTMLParamElement."
  88. );
  89. }
  90. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  91. try {
  92. const value = esValue[implSymbol]._reflectGetTheContentAttribute("name");
  93. return value === null ? "" : value;
  94. } finally {
  95. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  96. }
  97. }
  98. set name(V) {
  99. const esValue = this !== null && this !== undefined ? this : globalObject;
  100. if (!exports.is(esValue)) {
  101. throw new globalObject.TypeError(
  102. "'set name' called on an object that is not a valid instance of HTMLParamElement."
  103. );
  104. }
  105. V = conversions["DOMString"](V, {
  106. context: "Failed to set the 'name' property on 'HTMLParamElement': The provided value",
  107. globals: globalObject
  108. });
  109. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  110. try {
  111. esValue[implSymbol]._reflectSetTheContentAttribute("name", V);
  112. } finally {
  113. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  114. }
  115. }
  116. get value() {
  117. const esValue = this !== null && this !== undefined ? this : globalObject;
  118. if (!exports.is(esValue)) {
  119. throw new globalObject.TypeError(
  120. "'get value' called on an object that is not a valid instance of HTMLParamElement."
  121. );
  122. }
  123. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  124. try {
  125. const value = esValue[implSymbol]._reflectGetTheContentAttribute("value");
  126. return value === null ? "" : value;
  127. } finally {
  128. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  129. }
  130. }
  131. set value(V) {
  132. const esValue = this !== null && this !== undefined ? this : globalObject;
  133. if (!exports.is(esValue)) {
  134. throw new globalObject.TypeError(
  135. "'set value' called on an object that is not a valid instance of HTMLParamElement."
  136. );
  137. }
  138. V = conversions["DOMString"](V, {
  139. context: "Failed to set the 'value' property on 'HTMLParamElement': The provided value",
  140. globals: globalObject
  141. });
  142. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  143. try {
  144. esValue[implSymbol]._reflectSetTheContentAttribute("value", V);
  145. } finally {
  146. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  147. }
  148. }
  149. get type() {
  150. const esValue = this !== null && this !== undefined ? this : globalObject;
  151. if (!exports.is(esValue)) {
  152. throw new globalObject.TypeError(
  153. "'get type' called on an object that is not a valid instance of HTMLParamElement."
  154. );
  155. }
  156. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  157. try {
  158. const value = esValue[implSymbol]._reflectGetTheContentAttribute("type");
  159. return value === null ? "" : value;
  160. } finally {
  161. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  162. }
  163. }
  164. set type(V) {
  165. const esValue = this !== null && this !== undefined ? this : globalObject;
  166. if (!exports.is(esValue)) {
  167. throw new globalObject.TypeError(
  168. "'set type' called on an object that is not a valid instance of HTMLParamElement."
  169. );
  170. }
  171. V = conversions["DOMString"](V, {
  172. context: "Failed to set the 'type' property on 'HTMLParamElement': The provided value",
  173. globals: globalObject
  174. });
  175. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  176. try {
  177. esValue[implSymbol]._reflectSetTheContentAttribute("type", V);
  178. } finally {
  179. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  180. }
  181. }
  182. get valueType() {
  183. const esValue = this !== null && this !== undefined ? this : globalObject;
  184. if (!exports.is(esValue)) {
  185. throw new globalObject.TypeError(
  186. "'get valueType' called on an object that is not a valid instance of HTMLParamElement."
  187. );
  188. }
  189. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  190. try {
  191. const value = esValue[implSymbol]._reflectGetTheContentAttribute("valuetype");
  192. return value === null ? "" : value;
  193. } finally {
  194. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  195. }
  196. }
  197. set valueType(V) {
  198. const esValue = this !== null && this !== undefined ? this : globalObject;
  199. if (!exports.is(esValue)) {
  200. throw new globalObject.TypeError(
  201. "'set valueType' called on an object that is not a valid instance of HTMLParamElement."
  202. );
  203. }
  204. V = conversions["DOMString"](V, {
  205. context: "Failed to set the 'valueType' property on 'HTMLParamElement': The provided value",
  206. globals: globalObject
  207. });
  208. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  209. try {
  210. esValue[implSymbol]._reflectSetTheContentAttribute("valuetype", V);
  211. } finally {
  212. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  213. }
  214. }
  215. }
  216. Object.defineProperties(HTMLParamElement.prototype, {
  217. name: { enumerable: true },
  218. value: { enumerable: true },
  219. type: { enumerable: true },
  220. valueType: { enumerable: true },
  221. [Symbol.toStringTag]: { value: "HTMLParamElement", configurable: true }
  222. });
  223. ctorRegistry[interfaceName] = HTMLParamElement;
  224. Object.defineProperty(globalObject, interfaceName, {
  225. configurable: true,
  226. writable: true,
  227. value: HTMLParamElement
  228. });
  229. };
  230. const Impl = require("../../jsdom/living/nodes/HTMLParamElement-impl.js");