HTMLScriptElement.js 15 KB

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