HTMLFontElement.js 7.7 KB

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