HTMLSlotElement.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 AssignedNodesOptions = require("./AssignedNodesOptions.js");
  7. const ceReactionsPreSteps_jsdom_living_helpers_custom_elements =
  8. require("../../jsdom/living/helpers/custom-elements.js").ceReactionsPreSteps;
  9. const ceReactionsPostSteps_jsdom_living_helpers_custom_elements =
  10. require("../../jsdom/living/helpers/custom-elements.js").ceReactionsPostSteps;
  11. const implSymbol = utils.implSymbol;
  12. const ctorRegistrySymbol = utils.ctorRegistrySymbol;
  13. const HTMLElement = require("./HTMLElement.js");
  14. const interfaceName = "HTMLSlotElement";
  15. exports.is = value => {
  16. return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
  17. };
  18. exports.isImpl = value => {
  19. return utils.isObject(value) && value instanceof Impl.implementation;
  20. };
  21. exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
  22. if (exports.is(value)) {
  23. return utils.implForWrapper(value);
  24. }
  25. throw new globalObject.TypeError(`${context} is not of type 'HTMLSlotElement'.`);
  26. };
  27. function makeWrapper(globalObject, newTarget) {
  28. let proto;
  29. if (newTarget !== undefined) {
  30. proto = newTarget.prototype;
  31. }
  32. if (!utils.isObject(proto)) {
  33. proto = globalObject[ctorRegistrySymbol]["HTMLSlotElement"].prototype;
  34. }
  35. return Object.create(proto);
  36. }
  37. exports.create = (globalObject, constructorArgs, privateData) => {
  38. const wrapper = makeWrapper(globalObject);
  39. return exports.setup(wrapper, globalObject, constructorArgs, privateData);
  40. };
  41. exports.createImpl = (globalObject, constructorArgs, privateData) => {
  42. const wrapper = exports.create(globalObject, constructorArgs, privateData);
  43. return utils.implForWrapper(wrapper);
  44. };
  45. exports._internalSetup = (wrapper, globalObject) => {
  46. HTMLElement._internalSetup(wrapper, globalObject);
  47. };
  48. exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
  49. privateData.wrapper = wrapper;
  50. exports._internalSetup(wrapper, globalObject);
  51. Object.defineProperty(wrapper, implSymbol, {
  52. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  53. configurable: true
  54. });
  55. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  56. if (Impl.init) {
  57. Impl.init(wrapper[implSymbol]);
  58. }
  59. return wrapper;
  60. };
  61. exports.new = (globalObject, newTarget) => {
  62. const wrapper = makeWrapper(globalObject, newTarget);
  63. exports._internalSetup(wrapper, globalObject);
  64. Object.defineProperty(wrapper, implSymbol, {
  65. value: Object.create(Impl.implementation.prototype),
  66. configurable: true
  67. });
  68. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  69. if (Impl.init) {
  70. Impl.init(wrapper[implSymbol]);
  71. }
  72. return wrapper[implSymbol];
  73. };
  74. const exposed = new Set(["Window"]);
  75. exports.install = (globalObject, globalNames) => {
  76. if (!globalNames.some(globalName => exposed.has(globalName))) {
  77. return;
  78. }
  79. const ctorRegistry = utils.initCtorRegistry(globalObject);
  80. class HTMLSlotElement extends globalObject.HTMLElement {
  81. constructor() {
  82. return HTMLConstructor_jsdom_living_helpers_html_constructor(globalObject, interfaceName, new.target);
  83. }
  84. assignedNodes() {
  85. const esValue = this !== null && this !== undefined ? this : globalObject;
  86. if (!exports.is(esValue)) {
  87. throw new globalObject.TypeError(
  88. "'assignedNodes' called on an object that is not a valid instance of HTMLSlotElement."
  89. );
  90. }
  91. const args = [];
  92. {
  93. let curArg = arguments[0];
  94. curArg = AssignedNodesOptions.convert(globalObject, curArg, {
  95. context: "Failed to execute 'assignedNodes' on 'HTMLSlotElement': parameter 1"
  96. });
  97. args.push(curArg);
  98. }
  99. return utils.tryWrapperForImpl(esValue[implSymbol].assignedNodes(...args));
  100. }
  101. assignedElements() {
  102. const esValue = this !== null && this !== undefined ? this : globalObject;
  103. if (!exports.is(esValue)) {
  104. throw new globalObject.TypeError(
  105. "'assignedElements' called on an object that is not a valid instance of HTMLSlotElement."
  106. );
  107. }
  108. const args = [];
  109. {
  110. let curArg = arguments[0];
  111. curArg = AssignedNodesOptions.convert(globalObject, curArg, {
  112. context: "Failed to execute 'assignedElements' on 'HTMLSlotElement': parameter 1"
  113. });
  114. args.push(curArg);
  115. }
  116. return utils.tryWrapperForImpl(esValue[implSymbol].assignedElements(...args));
  117. }
  118. get name() {
  119. const esValue = this !== null && this !== undefined ? this : globalObject;
  120. if (!exports.is(esValue)) {
  121. throw new globalObject.TypeError(
  122. "'get name' called on an object that is not a valid instance of HTMLSlotElement."
  123. );
  124. }
  125. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  126. try {
  127. const value = esValue[implSymbol]._reflectGetTheContentAttribute("name");
  128. return value === null ? "" : value;
  129. } finally {
  130. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  131. }
  132. }
  133. set name(V) {
  134. const esValue = this !== null && this !== undefined ? this : globalObject;
  135. if (!exports.is(esValue)) {
  136. throw new globalObject.TypeError(
  137. "'set name' called on an object that is not a valid instance of HTMLSlotElement."
  138. );
  139. }
  140. V = conversions["DOMString"](V, {
  141. context: "Failed to set the 'name' property on 'HTMLSlotElement': The provided value",
  142. globals: globalObject
  143. });
  144. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  145. try {
  146. esValue[implSymbol]._reflectSetTheContentAttribute("name", V);
  147. } finally {
  148. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  149. }
  150. }
  151. }
  152. Object.defineProperties(HTMLSlotElement.prototype, {
  153. assignedNodes: { enumerable: true },
  154. assignedElements: { enumerable: true },
  155. name: { enumerable: true },
  156. [Symbol.toStringTag]: { value: "HTMLSlotElement", configurable: true }
  157. });
  158. ctorRegistry[interfaceName] = HTMLSlotElement;
  159. Object.defineProperty(globalObject, interfaceName, {
  160. configurable: true,
  161. writable: true,
  162. value: HTMLSlotElement
  163. });
  164. };
  165. const Impl = require("../../jsdom/living/nodes/HTMLSlotElement-impl.js");