HTMLTrackElement.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 = "HTMLTrackElement";
 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 'HTMLTrackElement'.`);
 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]["HTMLTrackElement"];
 37    if (ctor === undefined) {
 38      throw new Error("Internal error: constructor HTMLTrackElement 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 HTMLTrackElement before HTMLElement");
 99    }
100    class HTMLTrackElement extends globalObject.HTMLElement {
101      constructor() {
102        return HTMLConstructor_helpers_html_constructor(globalObject, interfaceName, new.target);
103      }
104  
105      get kind() {
106        const esValue = this !== null && this !== undefined ? this : globalObject;
107  
108        if (!exports.is(esValue)) {
109          throw new TypeError("'get kind' called on an object that is not a valid instance of HTMLTrackElement.");
110        }
111  
112        ceReactionsPreSteps_helpers_custom_elements(globalObject);
113        try {
114          const value = esValue[implSymbol].getAttributeNS(null, "kind");
115          return value === null ? "" : value;
116        } finally {
117          ceReactionsPostSteps_helpers_custom_elements(globalObject);
118        }
119      }
120  
121      set kind(V) {
122        const esValue = this !== null && this !== undefined ? this : globalObject;
123  
124        if (!exports.is(esValue)) {
125          throw new TypeError("'set kind' called on an object that is not a valid instance of HTMLTrackElement.");
126        }
127  
128        V = conversions["DOMString"](V, {
129          context: "Failed to set the 'kind' property on 'HTMLTrackElement': The provided value"
130        });
131  
132        ceReactionsPreSteps_helpers_custom_elements(globalObject);
133        try {
134          esValue[implSymbol].setAttributeNS(null, "kind", V);
135        } finally {
136          ceReactionsPostSteps_helpers_custom_elements(globalObject);
137        }
138      }
139  
140      get src() {
141        const esValue = this !== null && this !== undefined ? this : globalObject;
142  
143        if (!exports.is(esValue)) {
144          throw new TypeError("'get src' called on an object that is not a valid instance of HTMLTrackElement.");
145        }
146  
147        ceReactionsPreSteps_helpers_custom_elements(globalObject);
148        try {
149          const value = esValue[implSymbol].getAttributeNS(null, "src");
150          if (value === null) {
151            return "";
152          }
153          const urlRecord = parseURLToResultingURLRecord_helpers_document_base_url(
154            value,
155            esValue[implSymbol]._ownerDocument
156          );
157          if (urlRecord !== null) {
158            return serializeURLwhatwg_url(urlRecord);
159          }
160          return conversions.USVString(value);
161        } finally {
162          ceReactionsPostSteps_helpers_custom_elements(globalObject);
163        }
164      }
165  
166      set src(V) {
167        const esValue = this !== null && this !== undefined ? this : globalObject;
168  
169        if (!exports.is(esValue)) {
170          throw new TypeError("'set src' called on an object that is not a valid instance of HTMLTrackElement.");
171        }
172  
173        V = conversions["USVString"](V, {
174          context: "Failed to set the 'src' property on 'HTMLTrackElement': The provided value"
175        });
176  
177        ceReactionsPreSteps_helpers_custom_elements(globalObject);
178        try {
179          esValue[implSymbol].setAttributeNS(null, "src", V);
180        } finally {
181          ceReactionsPostSteps_helpers_custom_elements(globalObject);
182        }
183      }
184  
185      get srclang() {
186        const esValue = this !== null && this !== undefined ? this : globalObject;
187  
188        if (!exports.is(esValue)) {
189          throw new TypeError("'get srclang' called on an object that is not a valid instance of HTMLTrackElement.");
190        }
191  
192        ceReactionsPreSteps_helpers_custom_elements(globalObject);
193        try {
194          const value = esValue[implSymbol].getAttributeNS(null, "srclang");
195          return value === null ? "" : value;
196        } finally {
197          ceReactionsPostSteps_helpers_custom_elements(globalObject);
198        }
199      }
200  
201      set srclang(V) {
202        const esValue = this !== null && this !== undefined ? this : globalObject;
203  
204        if (!exports.is(esValue)) {
205          throw new TypeError("'set srclang' called on an object that is not a valid instance of HTMLTrackElement.");
206        }
207  
208        V = conversions["DOMString"](V, {
209          context: "Failed to set the 'srclang' property on 'HTMLTrackElement': The provided value"
210        });
211  
212        ceReactionsPreSteps_helpers_custom_elements(globalObject);
213        try {
214          esValue[implSymbol].setAttributeNS(null, "srclang", V);
215        } finally {
216          ceReactionsPostSteps_helpers_custom_elements(globalObject);
217        }
218      }
219  
220      get label() {
221        const esValue = this !== null && this !== undefined ? this : globalObject;
222  
223        if (!exports.is(esValue)) {
224          throw new TypeError("'get label' called on an object that is not a valid instance of HTMLTrackElement.");
225        }
226  
227        ceReactionsPreSteps_helpers_custom_elements(globalObject);
228        try {
229          const value = esValue[implSymbol].getAttributeNS(null, "label");
230          return value === null ? "" : value;
231        } finally {
232          ceReactionsPostSteps_helpers_custom_elements(globalObject);
233        }
234      }
235  
236      set label(V) {
237        const esValue = this !== null && this !== undefined ? this : globalObject;
238  
239        if (!exports.is(esValue)) {
240          throw new TypeError("'set label' called on an object that is not a valid instance of HTMLTrackElement.");
241        }
242  
243        V = conversions["DOMString"](V, {
244          context: "Failed to set the 'label' property on 'HTMLTrackElement': The provided value"
245        });
246  
247        ceReactionsPreSteps_helpers_custom_elements(globalObject);
248        try {
249          esValue[implSymbol].setAttributeNS(null, "label", V);
250        } finally {
251          ceReactionsPostSteps_helpers_custom_elements(globalObject);
252        }
253      }
254  
255      get default() {
256        const esValue = this !== null && this !== undefined ? this : globalObject;
257  
258        if (!exports.is(esValue)) {
259          throw new TypeError("'get default' called on an object that is not a valid instance of HTMLTrackElement.");
260        }
261  
262        ceReactionsPreSteps_helpers_custom_elements(globalObject);
263        try {
264          return esValue[implSymbol].hasAttributeNS(null, "default");
265        } finally {
266          ceReactionsPostSteps_helpers_custom_elements(globalObject);
267        }
268      }
269  
270      set default(V) {
271        const esValue = this !== null && this !== undefined ? this : globalObject;
272  
273        if (!exports.is(esValue)) {
274          throw new TypeError("'set default' called on an object that is not a valid instance of HTMLTrackElement.");
275        }
276  
277        V = conversions["boolean"](V, {
278          context: "Failed to set the 'default' property on 'HTMLTrackElement': The provided value"
279        });
280  
281        ceReactionsPreSteps_helpers_custom_elements(globalObject);
282        try {
283          if (V) {
284            esValue[implSymbol].setAttributeNS(null, "default", "");
285          } else {
286            esValue[implSymbol].removeAttributeNS(null, "default");
287          }
288        } finally {
289          ceReactionsPostSteps_helpers_custom_elements(globalObject);
290        }
291      }
292  
293      get readyState() {
294        const esValue = this !== null && this !== undefined ? this : globalObject;
295  
296        if (!exports.is(esValue)) {
297          throw new TypeError("'get readyState' called on an object that is not a valid instance of HTMLTrackElement.");
298        }
299  
300        return esValue[implSymbol]["readyState"];
301      }
302    }
303    Object.defineProperties(HTMLTrackElement.prototype, {
304      kind: { enumerable: true },
305      src: { enumerable: true },
306      srclang: { enumerable: true },
307      label: { enumerable: true },
308      default: { enumerable: true },
309      readyState: { enumerable: true },
310      [Symbol.toStringTag]: { value: "HTMLTrackElement", configurable: true },
311      NONE: { value: 0, enumerable: true },
312      LOADING: { value: 1, enumerable: true },
313      LOADED: { value: 2, enumerable: true },
314      ERROR: { value: 3, enumerable: true }
315    });
316    Object.defineProperties(HTMLTrackElement, {
317      NONE: { value: 0, enumerable: true },
318      LOADING: { value: 1, enumerable: true },
319      LOADED: { value: 2, enumerable: true },
320      ERROR: { value: 3, enumerable: true }
321    });
322    if (globalObject[ctorRegistrySymbol] === undefined) {
323      globalObject[ctorRegistrySymbol] = Object.create(null);
324    }
325    globalObject[ctorRegistrySymbol][interfaceName] = HTMLTrackElement;
326  
327    Object.defineProperty(globalObject, interfaceName, {
328      configurable: true,
329      writable: true,
330      value: HTMLTrackElement
331    });
332  };
333  
334  const Impl = require("../nodes/HTMLTrackElement-impl.js");