HTMLTrackElement.js 12 KB

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