HTMLFrameElement.js
  1  "use strict";
  2  
  3  const conversions = require("webidl-conversions");
  4  const utils = require("./utils.js");
  5  
  6  const HTMLConstructor_helpers_html_constructor = require("../helpers/html-constructor.js").HTMLConstructor;
  7  const ceReactionsPreSteps_helpers_custom_elements = require("../helpers/custom-elements.js").ceReactionsPreSteps;
  8  const ceReactionsPostSteps_helpers_custom_elements = require("../helpers/custom-elements.js").ceReactionsPostSteps;
  9  const parseURLToResultingURLRecord_helpers_document_base_url =
 10    require("../helpers/document-base-url.js").parseURLToResultingURLRecord;
 11  const serializeURLwhatwg_url = require("whatwg-url").serializeURL;
 12  const implSymbol = utils.implSymbol;
 13  const ctorRegistrySymbol = utils.ctorRegistrySymbol;
 14  const HTMLElement = require("./HTMLElement.js");
 15  
 16  const interfaceName = "HTMLFrameElement";
 17  
 18  exports.is = value => {
 19    return utils.isObject(value) && utils.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
 20  };
 21  exports.isImpl = value => {
 22    return utils.isObject(value) && value instanceof Impl.implementation;
 23  };
 24  exports.convert = (value, { context = "The provided value" } = {}) => {
 25    if (exports.is(value)) {
 26      return utils.implForWrapper(value);
 27    }
 28    throw new TypeError(`${context} is not of type 'HTMLFrameElement'.`);
 29  };
 30  
 31  function makeWrapper(globalObject) {
 32    if (globalObject[ctorRegistrySymbol] === undefined) {
 33      throw new Error("Internal error: invalid global object");
 34    }
 35  
 36    const ctor = globalObject[ctorRegistrySymbol]["HTMLFrameElement"];
 37    if (ctor === undefined) {
 38      throw new Error("Internal error: constructor HTMLFrameElement is not installed on the passed global object");
 39    }
 40  
 41    return Object.create(ctor.prototype);
 42  }
 43  
 44  exports.create = (globalObject, constructorArgs, privateData) => {
 45    const wrapper = makeWrapper(globalObject);
 46    return exports.setup(wrapper, globalObject, constructorArgs, privateData);
 47  };
 48  
 49  exports.createImpl = (globalObject, constructorArgs, privateData) => {
 50    const wrapper = exports.create(globalObject, constructorArgs, privateData);
 51    return utils.implForWrapper(wrapper);
 52  };
 53  
 54  exports._internalSetup = (wrapper, globalObject) => {
 55    HTMLElement._internalSetup(wrapper, globalObject);
 56  };
 57  
 58  exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
 59    privateData.wrapper = wrapper;
 60  
 61    exports._internalSetup(wrapper, globalObject);
 62    Object.defineProperty(wrapper, implSymbol, {
 63      value: new Impl.implementation(globalObject, constructorArgs, privateData),
 64      configurable: true
 65    });
 66  
 67    wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
 68    if (Impl.init) {
 69      Impl.init(wrapper[implSymbol]);
 70    }
 71    return wrapper;
 72  };
 73  
 74  exports.new = globalObject => {
 75    const wrapper = makeWrapper(globalObject);
 76  
 77    exports._internalSetup(wrapper, globalObject);
 78    Object.defineProperty(wrapper, implSymbol, {
 79      value: Object.create(Impl.implementation.prototype),
 80      configurable: true
 81    });
 82  
 83    wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
 84    if (Impl.init) {
 85      Impl.init(wrapper[implSymbol]);
 86    }
 87    return wrapper[implSymbol];
 88  };
 89  
 90  const exposed = new Set(["Window"]);
 91  
 92  exports.install = (globalObject, globalNames) => {
 93    if (!globalNames.some(globalName => exposed.has(globalName))) {
 94      return;
 95    }
 96  
 97    if (globalObject.HTMLElement === undefined) {
 98      throw new Error("Internal error: attempting to evaluate HTMLFrameElement before HTMLElement");
 99    }
100    class HTMLFrameElement extends globalObject.HTMLElement {
101      constructor() {
102        return HTMLConstructor_helpers_html_constructor(globalObject, interfaceName, new.target);
103      }
104  
105      get name() {
106        const esValue = this !== null && this !== undefined ? this : globalObject;
107  
108        if (!exports.is(esValue)) {
109          throw new TypeError("'get name' called on an object that is not a valid instance of HTMLFrameElement.");
110        }
111  
112        ceReactionsPreSteps_helpers_custom_elements(globalObject);
113        try {
114          const value = esValue[implSymbol].getAttributeNS(null, "name");
115          return value === null ? "" : value;
116        } finally {
117          ceReactionsPostSteps_helpers_custom_elements(globalObject);
118        }
119      }
120  
121      set name(V) {
122        const esValue = this !== null && this !== undefined ? this : globalObject;
123  
124        if (!exports.is(esValue)) {
125          throw new TypeError("'set name' called on an object that is not a valid instance of HTMLFrameElement.");
126        }
127  
128        V = conversions["DOMString"](V, {
129          context: "Failed to set the 'name' property on 'HTMLFrameElement': The provided value"
130        });
131  
132        ceReactionsPreSteps_helpers_custom_elements(globalObject);
133        try {
134          esValue[implSymbol].setAttributeNS(null, "name", V);
135        } finally {
136          ceReactionsPostSteps_helpers_custom_elements(globalObject);
137        }
138      }
139  
140      get scrolling() {
141        const esValue = this !== null && this !== undefined ? this : globalObject;
142  
143        if (!exports.is(esValue)) {
144          throw new TypeError("'get scrolling' called on an object that is not a valid instance of HTMLFrameElement.");
145        }
146  
147        ceReactionsPreSteps_helpers_custom_elements(globalObject);
148        try {
149          const value = esValue[implSymbol].getAttributeNS(null, "scrolling");
150          return value === null ? "" : value;
151        } finally {
152          ceReactionsPostSteps_helpers_custom_elements(globalObject);
153        }
154      }
155  
156      set scrolling(V) {
157        const esValue = this !== null && this !== undefined ? this : globalObject;
158  
159        if (!exports.is(esValue)) {
160          throw new TypeError("'set scrolling' called on an object that is not a valid instance of HTMLFrameElement.");
161        }
162  
163        V = conversions["DOMString"](V, {
164          context: "Failed to set the 'scrolling' property on 'HTMLFrameElement': The provided value"
165        });
166  
167        ceReactionsPreSteps_helpers_custom_elements(globalObject);
168        try {
169          esValue[implSymbol].setAttributeNS(null, "scrolling", V);
170        } finally {
171          ceReactionsPostSteps_helpers_custom_elements(globalObject);
172        }
173      }
174  
175      get src() {
176        const esValue = this !== null && this !== undefined ? this : globalObject;
177  
178        if (!exports.is(esValue)) {
179          throw new TypeError("'get src' called on an object that is not a valid instance of HTMLFrameElement.");
180        }
181  
182        ceReactionsPreSteps_helpers_custom_elements(globalObject);
183        try {
184          const value = esValue[implSymbol].getAttributeNS(null, "src");
185          if (value === null) {
186            return "";
187          }
188          const urlRecord = parseURLToResultingURLRecord_helpers_document_base_url(
189            value,
190            esValue[implSymbol]._ownerDocument
191          );
192          if (urlRecord !== null) {
193            return serializeURLwhatwg_url(urlRecord);
194          }
195          return conversions.USVString(value);
196        } finally {
197          ceReactionsPostSteps_helpers_custom_elements(globalObject);
198        }
199      }
200  
201      set src(V) {
202        const esValue = this !== null && this !== undefined ? this : globalObject;
203  
204        if (!exports.is(esValue)) {
205          throw new TypeError("'set src' called on an object that is not a valid instance of HTMLFrameElement.");
206        }
207  
208        V = conversions["USVString"](V, {
209          context: "Failed to set the 'src' property on 'HTMLFrameElement': The provided value"
210        });
211  
212        ceReactionsPreSteps_helpers_custom_elements(globalObject);
213        try {
214          esValue[implSymbol].setAttributeNS(null, "src", V);
215        } finally {
216          ceReactionsPostSteps_helpers_custom_elements(globalObject);
217        }
218      }
219  
220      get frameBorder() {
221        const esValue = this !== null && this !== undefined ? this : globalObject;
222  
223        if (!exports.is(esValue)) {
224          throw new TypeError("'get frameBorder' called on an object that is not a valid instance of HTMLFrameElement.");
225        }
226  
227        ceReactionsPreSteps_helpers_custom_elements(globalObject);
228        try {
229          const value = esValue[implSymbol].getAttributeNS(null, "frameborder");
230          return value === null ? "" : value;
231        } finally {
232          ceReactionsPostSteps_helpers_custom_elements(globalObject);
233        }
234      }
235  
236      set frameBorder(V) {
237        const esValue = this !== null && this !== undefined ? this : globalObject;
238  
239        if (!exports.is(esValue)) {
240          throw new TypeError("'set frameBorder' called on an object that is not a valid instance of HTMLFrameElement.");
241        }
242  
243        V = conversions["DOMString"](V, {
244          context: "Failed to set the 'frameBorder' property on 'HTMLFrameElement': The provided value"
245        });
246  
247        ceReactionsPreSteps_helpers_custom_elements(globalObject);
248        try {
249          esValue[implSymbol].setAttributeNS(null, "frameborder", V);
250        } finally {
251          ceReactionsPostSteps_helpers_custom_elements(globalObject);
252        }
253      }
254  
255      get longDesc() {
256        const esValue = this !== null && this !== undefined ? this : globalObject;
257  
258        if (!exports.is(esValue)) {
259          throw new TypeError("'get longDesc' called on an object that is not a valid instance of HTMLFrameElement.");
260        }
261  
262        ceReactionsPreSteps_helpers_custom_elements(globalObject);
263        try {
264          const value = esValue[implSymbol].getAttributeNS(null, "longdesc");
265          if (value === null) {
266            return "";
267          }
268          const urlRecord = parseURLToResultingURLRecord_helpers_document_base_url(
269            value,
270            esValue[implSymbol]._ownerDocument
271          );
272          if (urlRecord !== null) {
273            return serializeURLwhatwg_url(urlRecord);
274          }
275          return conversions.USVString(value);
276        } finally {
277          ceReactionsPostSteps_helpers_custom_elements(globalObject);
278        }
279      }
280  
281      set longDesc(V) {
282        const esValue = this !== null && this !== undefined ? this : globalObject;
283  
284        if (!exports.is(esValue)) {
285          throw new TypeError("'set longDesc' called on an object that is not a valid instance of HTMLFrameElement.");
286        }
287  
288        V = conversions["USVString"](V, {
289          context: "Failed to set the 'longDesc' property on 'HTMLFrameElement': The provided value"
290        });
291  
292        ceReactionsPreSteps_helpers_custom_elements(globalObject);
293        try {
294          esValue[implSymbol].setAttributeNS(null, "longdesc", V);
295        } finally {
296          ceReactionsPostSteps_helpers_custom_elements(globalObject);
297        }
298      }
299  
300      get noResize() {
301        const esValue = this !== null && this !== undefined ? this : globalObject;
302  
303        if (!exports.is(esValue)) {
304          throw new TypeError("'get noResize' called on an object that is not a valid instance of HTMLFrameElement.");
305        }
306  
307        ceReactionsPreSteps_helpers_custom_elements(globalObject);
308        try {
309          return esValue[implSymbol].hasAttributeNS(null, "noresize");
310        } finally {
311          ceReactionsPostSteps_helpers_custom_elements(globalObject);
312        }
313      }
314  
315      set noResize(V) {
316        const esValue = this !== null && this !== undefined ? this : globalObject;
317  
318        if (!exports.is(esValue)) {
319          throw new TypeError("'set noResize' called on an object that is not a valid instance of HTMLFrameElement.");
320        }
321  
322        V = conversions["boolean"](V, {
323          context: "Failed to set the 'noResize' property on 'HTMLFrameElement': The provided value"
324        });
325  
326        ceReactionsPreSteps_helpers_custom_elements(globalObject);
327        try {
328          if (V) {
329            esValue[implSymbol].setAttributeNS(null, "noresize", "");
330          } else {
331            esValue[implSymbol].removeAttributeNS(null, "noresize");
332          }
333        } finally {
334          ceReactionsPostSteps_helpers_custom_elements(globalObject);
335        }
336      }
337  
338      get contentDocument() {
339        const esValue = this !== null && this !== undefined ? this : globalObject;
340  
341        if (!exports.is(esValue)) {
342          throw new TypeError(
343            "'get contentDocument' called on an object that is not a valid instance of HTMLFrameElement."
344          );
345        }
346  
347        return utils.tryWrapperForImpl(esValue[implSymbol]["contentDocument"]);
348      }
349  
350      get contentWindow() {
351        const esValue = this !== null && this !== undefined ? this : globalObject;
352  
353        if (!exports.is(esValue)) {
354          throw new TypeError(
355            "'get contentWindow' called on an object that is not a valid instance of HTMLFrameElement."
356          );
357        }
358  
359        return utils.tryWrapperForImpl(esValue[implSymbol]["contentWindow"]);
360      }
361  
362      get marginHeight() {
363        const esValue = this !== null && this !== undefined ? this : globalObject;
364  
365        if (!exports.is(esValue)) {
366          throw new TypeError("'get marginHeight' called on an object that is not a valid instance of HTMLFrameElement.");
367        }
368  
369        ceReactionsPreSteps_helpers_custom_elements(globalObject);
370        try {
371          const value = esValue[implSymbol].getAttributeNS(null, "marginheight");
372          return value === null ? "" : value;
373        } finally {
374          ceReactionsPostSteps_helpers_custom_elements(globalObject);
375        }
376      }
377  
378      set marginHeight(V) {
379        const esValue = this !== null && this !== undefined ? this : globalObject;
380  
381        if (!exports.is(esValue)) {
382          throw new TypeError("'set marginHeight' called on an object that is not a valid instance of HTMLFrameElement.");
383        }
384  
385        V = conversions["DOMString"](V, {
386          context: "Failed to set the 'marginHeight' property on 'HTMLFrameElement': The provided value",
387          treatNullAsEmptyString: true
388        });
389  
390        ceReactionsPreSteps_helpers_custom_elements(globalObject);
391        try {
392          esValue[implSymbol].setAttributeNS(null, "marginheight", V);
393        } finally {
394          ceReactionsPostSteps_helpers_custom_elements(globalObject);
395        }
396      }
397  
398      get marginWidth() {
399        const esValue = this !== null && this !== undefined ? this : globalObject;
400  
401        if (!exports.is(esValue)) {
402          throw new TypeError("'get marginWidth' called on an object that is not a valid instance of HTMLFrameElement.");
403        }
404  
405        ceReactionsPreSteps_helpers_custom_elements(globalObject);
406        try {
407          const value = esValue[implSymbol].getAttributeNS(null, "marginwidth");
408          return value === null ? "" : value;
409        } finally {
410          ceReactionsPostSteps_helpers_custom_elements(globalObject);
411        }
412      }
413  
414      set marginWidth(V) {
415        const esValue = this !== null && this !== undefined ? this : globalObject;
416  
417        if (!exports.is(esValue)) {
418          throw new TypeError("'set marginWidth' called on an object that is not a valid instance of HTMLFrameElement.");
419        }
420  
421        V = conversions["DOMString"](V, {
422          context: "Failed to set the 'marginWidth' property on 'HTMLFrameElement': The provided value",
423          treatNullAsEmptyString: true
424        });
425  
426        ceReactionsPreSteps_helpers_custom_elements(globalObject);
427        try {
428          esValue[implSymbol].setAttributeNS(null, "marginwidth", V);
429        } finally {
430          ceReactionsPostSteps_helpers_custom_elements(globalObject);
431        }
432      }
433    }
434    Object.defineProperties(HTMLFrameElement.prototype, {
435      name: { enumerable: true },
436      scrolling: { enumerable: true },
437      src: { enumerable: true },
438      frameBorder: { enumerable: true },
439      longDesc: { enumerable: true },
440      noResize: { enumerable: true },
441      contentDocument: { enumerable: true },
442      contentWindow: { enumerable: true },
443      marginHeight: { enumerable: true },
444      marginWidth: { enumerable: true },
445      [Symbol.toStringTag]: { value: "HTMLFrameElement", configurable: true }
446    });
447    if (globalObject[ctorRegistrySymbol] === undefined) {
448      globalObject[ctorRegistrySymbol] = Object.create(null);
449    }
450    globalObject[ctorRegistrySymbol][interfaceName] = HTMLFrameElement;
451  
452    Object.defineProperty(globalObject, interfaceName, {
453      configurable: true,
454      writable: true,
455      value: HTMLFrameElement
456    });
457  };
458  
459  const Impl = require("../nodes/HTMLFrameElement-impl.js");