HTMLFrameElement.js 17 KB

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