HTMLLinkElement.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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 serializeURLwhatwg_url = require("whatwg-url").serializeURL;
  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 = "HTMLLinkElement";
  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 'HTMLLinkElement'.`);
  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]["HTMLLinkElement"].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 HTMLLinkElement extends globalObject.HTMLElement {
  81. constructor() {
  82. return HTMLConstructor_jsdom_living_helpers_html_constructor(globalObject, interfaceName, new.target);
  83. }
  84. get href() {
  85. const esValue = this !== null && this !== undefined ? this : globalObject;
  86. if (!exports.is(esValue)) {
  87. throw new globalObject.TypeError(
  88. "'get href' called on an object that is not a valid instance of HTMLLinkElement."
  89. );
  90. }
  91. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  92. try {
  93. const impl = esValue[implSymbol];
  94. const value = impl._reflectGetTheContentAttribute("href");
  95. if (value === null) {
  96. return "";
  97. }
  98. const document = impl._ownerDocument;
  99. if (this._hrefURLCacheKey === value && this._baseURLCache === document._baseURLCache) {
  100. return this._hrefURLCache;
  101. }
  102. this._hrefURLCacheKey = value;
  103. this._baseURLCache = document._baseURLCache;
  104. const urlRecord = document.encodingParseAURL(value);
  105. if (urlRecord !== null) {
  106. this._hrefURLCache = serializeURLwhatwg_url(urlRecord);
  107. return this._hrefURLCache;
  108. }
  109. this._hrefURLCache = conversions.USVString(value);
  110. return this._hrefURLCache;
  111. } finally {
  112. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  113. }
  114. }
  115. set href(V) {
  116. const esValue = this !== null && this !== undefined ? this : globalObject;
  117. if (!exports.is(esValue)) {
  118. throw new globalObject.TypeError(
  119. "'set href' called on an object that is not a valid instance of HTMLLinkElement."
  120. );
  121. }
  122. V = conversions["USVString"](V, {
  123. context: "Failed to set the 'href' property on 'HTMLLinkElement': The provided value",
  124. globals: globalObject
  125. });
  126. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  127. try {
  128. esValue[implSymbol]._reflectSetTheContentAttribute("href", V);
  129. } finally {
  130. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  131. }
  132. }
  133. get crossOrigin() {
  134. const esValue = this !== null && this !== undefined ? this : globalObject;
  135. if (!exports.is(esValue)) {
  136. throw new globalObject.TypeError(
  137. "'get crossOrigin' called on an object that is not a valid instance of HTMLLinkElement."
  138. );
  139. }
  140. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  141. try {
  142. return esValue[implSymbol]._reflectGetTheContentAttribute("crossorigin");
  143. } finally {
  144. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  145. }
  146. }
  147. set crossOrigin(V) {
  148. const esValue = this !== null && this !== undefined ? this : globalObject;
  149. if (!exports.is(esValue)) {
  150. throw new globalObject.TypeError(
  151. "'set crossOrigin' called on an object that is not a valid instance of HTMLLinkElement."
  152. );
  153. }
  154. if (V === null || V === undefined) {
  155. V = null;
  156. } else {
  157. V = conversions["DOMString"](V, {
  158. context: "Failed to set the 'crossOrigin' property on 'HTMLLinkElement': The provided value",
  159. globals: globalObject
  160. });
  161. }
  162. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  163. try {
  164. if (V === null) {
  165. esValue[implSymbol]._reflectDeleteTheContentAttribute("crossorigin");
  166. } else {
  167. esValue[implSymbol]._reflectSetTheContentAttribute("crossorigin", V);
  168. }
  169. } finally {
  170. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  171. }
  172. }
  173. get rel() {
  174. const esValue = this !== null && this !== undefined ? this : globalObject;
  175. if (!exports.is(esValue)) {
  176. throw new globalObject.TypeError(
  177. "'get rel' called on an object that is not a valid instance of HTMLLinkElement."
  178. );
  179. }
  180. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  181. try {
  182. const value = esValue[implSymbol]._reflectGetTheContentAttribute("rel");
  183. return value === null ? "" : value;
  184. } finally {
  185. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  186. }
  187. }
  188. set rel(V) {
  189. const esValue = this !== null && this !== undefined ? this : globalObject;
  190. if (!exports.is(esValue)) {
  191. throw new globalObject.TypeError(
  192. "'set rel' called on an object that is not a valid instance of HTMLLinkElement."
  193. );
  194. }
  195. V = conversions["DOMString"](V, {
  196. context: "Failed to set the 'rel' property on 'HTMLLinkElement': The provided value",
  197. globals: globalObject
  198. });
  199. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  200. try {
  201. esValue[implSymbol]._reflectSetTheContentAttribute("rel", V);
  202. } finally {
  203. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  204. }
  205. }
  206. get relList() {
  207. const esValue = this !== null && this !== undefined ? this : globalObject;
  208. if (!exports.is(esValue)) {
  209. throw new globalObject.TypeError(
  210. "'get relList' called on an object that is not a valid instance of HTMLLinkElement."
  211. );
  212. }
  213. return utils.getSameObject(this, "relList", () => {
  214. return utils.tryWrapperForImpl(esValue[implSymbol]["relList"]);
  215. });
  216. }
  217. set relList(V) {
  218. const esValue = this !== null && this !== undefined ? this : globalObject;
  219. if (!exports.is(esValue)) {
  220. throw new globalObject.TypeError(
  221. "'set relList' called on an object that is not a valid instance of HTMLLinkElement."
  222. );
  223. }
  224. const Q = esValue["relList"];
  225. if (!utils.isObject(Q)) {
  226. throw new globalObject.TypeError("Property 'relList' is not an object");
  227. }
  228. Reflect.set(Q, "value", V);
  229. }
  230. get media() {
  231. const esValue = this !== null && this !== undefined ? this : globalObject;
  232. if (!exports.is(esValue)) {
  233. throw new globalObject.TypeError(
  234. "'get media' called on an object that is not a valid instance of HTMLLinkElement."
  235. );
  236. }
  237. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  238. try {
  239. const value = esValue[implSymbol]._reflectGetTheContentAttribute("media");
  240. return value === null ? "" : value;
  241. } finally {
  242. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  243. }
  244. }
  245. set media(V) {
  246. const esValue = this !== null && this !== undefined ? this : globalObject;
  247. if (!exports.is(esValue)) {
  248. throw new globalObject.TypeError(
  249. "'set media' called on an object that is not a valid instance of HTMLLinkElement."
  250. );
  251. }
  252. V = conversions["DOMString"](V, {
  253. context: "Failed to set the 'media' property on 'HTMLLinkElement': The provided value",
  254. globals: globalObject
  255. });
  256. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  257. try {
  258. esValue[implSymbol]._reflectSetTheContentAttribute("media", V);
  259. } finally {
  260. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  261. }
  262. }
  263. get hreflang() {
  264. const esValue = this !== null && this !== undefined ? this : globalObject;
  265. if (!exports.is(esValue)) {
  266. throw new globalObject.TypeError(
  267. "'get hreflang' called on an object that is not a valid instance of HTMLLinkElement."
  268. );
  269. }
  270. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  271. try {
  272. const value = esValue[implSymbol]._reflectGetTheContentAttribute("hreflang");
  273. return value === null ? "" : value;
  274. } finally {
  275. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  276. }
  277. }
  278. set hreflang(V) {
  279. const esValue = this !== null && this !== undefined ? this : globalObject;
  280. if (!exports.is(esValue)) {
  281. throw new globalObject.TypeError(
  282. "'set hreflang' called on an object that is not a valid instance of HTMLLinkElement."
  283. );
  284. }
  285. V = conversions["DOMString"](V, {
  286. context: "Failed to set the 'hreflang' property on 'HTMLLinkElement': The provided value",
  287. globals: globalObject
  288. });
  289. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  290. try {
  291. esValue[implSymbol]._reflectSetTheContentAttribute("hreflang", V);
  292. } finally {
  293. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  294. }
  295. }
  296. get type() {
  297. const esValue = this !== null && this !== undefined ? this : globalObject;
  298. if (!exports.is(esValue)) {
  299. throw new globalObject.TypeError(
  300. "'get type' called on an object that is not a valid instance of HTMLLinkElement."
  301. );
  302. }
  303. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  304. try {
  305. const value = esValue[implSymbol]._reflectGetTheContentAttribute("type");
  306. return value === null ? "" : value;
  307. } finally {
  308. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  309. }
  310. }
  311. set type(V) {
  312. const esValue = this !== null && this !== undefined ? this : globalObject;
  313. if (!exports.is(esValue)) {
  314. throw new globalObject.TypeError(
  315. "'set type' called on an object that is not a valid instance of HTMLLinkElement."
  316. );
  317. }
  318. V = conversions["DOMString"](V, {
  319. context: "Failed to set the 'type' property on 'HTMLLinkElement': The provided value",
  320. globals: globalObject
  321. });
  322. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  323. try {
  324. esValue[implSymbol]._reflectSetTheContentAttribute("type", V);
  325. } finally {
  326. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  327. }
  328. }
  329. get charset() {
  330. const esValue = this !== null && this !== undefined ? this : globalObject;
  331. if (!exports.is(esValue)) {
  332. throw new globalObject.TypeError(
  333. "'get charset' called on an object that is not a valid instance of HTMLLinkElement."
  334. );
  335. }
  336. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  337. try {
  338. const value = esValue[implSymbol]._reflectGetTheContentAttribute("charset");
  339. return value === null ? "" : value;
  340. } finally {
  341. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  342. }
  343. }
  344. set charset(V) {
  345. const esValue = this !== null && this !== undefined ? this : globalObject;
  346. if (!exports.is(esValue)) {
  347. throw new globalObject.TypeError(
  348. "'set charset' called on an object that is not a valid instance of HTMLLinkElement."
  349. );
  350. }
  351. V = conversions["DOMString"](V, {
  352. context: "Failed to set the 'charset' property on 'HTMLLinkElement': The provided value",
  353. globals: globalObject
  354. });
  355. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  356. try {
  357. esValue[implSymbol]._reflectSetTheContentAttribute("charset", V);
  358. } finally {
  359. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  360. }
  361. }
  362. get rev() {
  363. const esValue = this !== null && this !== undefined ? this : globalObject;
  364. if (!exports.is(esValue)) {
  365. throw new globalObject.TypeError(
  366. "'get rev' called on an object that is not a valid instance of HTMLLinkElement."
  367. );
  368. }
  369. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  370. try {
  371. const value = esValue[implSymbol]._reflectGetTheContentAttribute("rev");
  372. return value === null ? "" : value;
  373. } finally {
  374. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  375. }
  376. }
  377. set rev(V) {
  378. const esValue = this !== null && this !== undefined ? this : globalObject;
  379. if (!exports.is(esValue)) {
  380. throw new globalObject.TypeError(
  381. "'set rev' called on an object that is not a valid instance of HTMLLinkElement."
  382. );
  383. }
  384. V = conversions["DOMString"](V, {
  385. context: "Failed to set the 'rev' property on 'HTMLLinkElement': The provided value",
  386. globals: globalObject
  387. });
  388. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  389. try {
  390. esValue[implSymbol]._reflectSetTheContentAttribute("rev", V);
  391. } finally {
  392. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  393. }
  394. }
  395. get target() {
  396. const esValue = this !== null && this !== undefined ? this : globalObject;
  397. if (!exports.is(esValue)) {
  398. throw new globalObject.TypeError(
  399. "'get target' called on an object that is not a valid instance of HTMLLinkElement."
  400. );
  401. }
  402. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  403. try {
  404. const value = esValue[implSymbol]._reflectGetTheContentAttribute("target");
  405. return value === null ? "" : value;
  406. } finally {
  407. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  408. }
  409. }
  410. set target(V) {
  411. const esValue = this !== null && this !== undefined ? this : globalObject;
  412. if (!exports.is(esValue)) {
  413. throw new globalObject.TypeError(
  414. "'set target' called on an object that is not a valid instance of HTMLLinkElement."
  415. );
  416. }
  417. V = conversions["DOMString"](V, {
  418. context: "Failed to set the 'target' property on 'HTMLLinkElement': The provided value",
  419. globals: globalObject
  420. });
  421. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  422. try {
  423. esValue[implSymbol]._reflectSetTheContentAttribute("target", V);
  424. } finally {
  425. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  426. }
  427. }
  428. get sheet() {
  429. const esValue = this !== null && this !== undefined ? this : globalObject;
  430. if (!exports.is(esValue)) {
  431. throw new globalObject.TypeError(
  432. "'get sheet' called on an object that is not a valid instance of HTMLLinkElement."
  433. );
  434. }
  435. return utils.tryWrapperForImpl(esValue[implSymbol]["sheet"]);
  436. }
  437. }
  438. Object.defineProperties(HTMLLinkElement.prototype, {
  439. href: { enumerable: true },
  440. crossOrigin: { enumerable: true },
  441. rel: { enumerable: true },
  442. relList: { enumerable: true },
  443. media: { enumerable: true },
  444. hreflang: { enumerable: true },
  445. type: { enumerable: true },
  446. charset: { enumerable: true },
  447. rev: { enumerable: true },
  448. target: { enumerable: true },
  449. sheet: { enumerable: true },
  450. [Symbol.toStringTag]: { value: "HTMLLinkElement", configurable: true }
  451. });
  452. ctorRegistry[interfaceName] = HTMLLinkElement;
  453. Object.defineProperty(globalObject, interfaceName, {
  454. configurable: true,
  455. writable: true,
  456. value: HTMLLinkElement
  457. });
  458. };
  459. const Impl = require("../../jsdom/living/nodes/HTMLLinkElement-impl.js");