HTMLProgressElement.js 7.4 KB

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