HTMLPreElement.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 parseInteger_helpers_strings = require("../helpers/strings.js").parseInteger;
  8  const ceReactionsPreSteps_helpers_custom_elements = require("../helpers/custom-elements.js").ceReactionsPreSteps;
  9  const ceReactionsPostSteps_helpers_custom_elements = require("../helpers/custom-elements.js").ceReactionsPostSteps;
 10  const implSymbol = utils.implSymbol;
 11  const ctorRegistrySymbol = utils.ctorRegistrySymbol;
 12  const HTMLElement = require("./HTMLElement.js");
 13  
 14  const interfaceName = "HTMLPreElement";
 15  
 16  exports.is = value => {
 17    return utils.isObject(value) && utils.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
 18  };
 19  exports.isImpl = value => {
 20    return utils.isObject(value) && value instanceof Impl.implementation;
 21  };
 22  exports.convert = (value, { context = "The provided value" } = {}) => {
 23    if (exports.is(value)) {
 24      return utils.implForWrapper(value);
 25    }
 26    throw new TypeError(`${context} is not of type 'HTMLPreElement'.`);
 27  };
 28  
 29  function makeWrapper(globalObject) {
 30    if (globalObject[ctorRegistrySymbol] === undefined) {
 31      throw new Error("Internal error: invalid global object");
 32    }
 33  
 34    const ctor = globalObject[ctorRegistrySymbol]["HTMLPreElement"];
 35    if (ctor === undefined) {
 36      throw new Error("Internal error: constructor HTMLPreElement is not installed on the passed global object");
 37    }
 38  
 39    return Object.create(ctor.prototype);
 40  }
 41  
 42  exports.create = (globalObject, constructorArgs, privateData) => {
 43    const wrapper = makeWrapper(globalObject);
 44    return exports.setup(wrapper, globalObject, constructorArgs, privateData);
 45  };
 46  
 47  exports.createImpl = (globalObject, constructorArgs, privateData) => {
 48    const wrapper = exports.create(globalObject, constructorArgs, privateData);
 49    return utils.implForWrapper(wrapper);
 50  };
 51  
 52  exports._internalSetup = (wrapper, globalObject) => {
 53    HTMLElement._internalSetup(wrapper, globalObject);
 54  };
 55  
 56  exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
 57    privateData.wrapper = wrapper;
 58  
 59    exports._internalSetup(wrapper, globalObject);
 60    Object.defineProperty(wrapper, implSymbol, {
 61      value: new Impl.implementation(globalObject, constructorArgs, privateData),
 62      configurable: true
 63    });
 64  
 65    wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
 66    if (Impl.init) {
 67      Impl.init(wrapper[implSymbol]);
 68    }
 69    return wrapper;
 70  };
 71  
 72  exports.new = globalObject => {
 73    const wrapper = makeWrapper(globalObject);
 74  
 75    exports._internalSetup(wrapper, globalObject);
 76    Object.defineProperty(wrapper, implSymbol, {
 77      value: Object.create(Impl.implementation.prototype),
 78      configurable: true
 79    });
 80  
 81    wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
 82    if (Impl.init) {
 83      Impl.init(wrapper[implSymbol]);
 84    }
 85    return wrapper[implSymbol];
 86  };
 87  
 88  const exposed = new Set(["Window"]);
 89  
 90  exports.install = (globalObject, globalNames) => {
 91    if (!globalNames.some(globalName => exposed.has(globalName))) {
 92      return;
 93    }
 94  
 95    if (globalObject.HTMLElement === undefined) {
 96      throw new Error("Internal error: attempting to evaluate HTMLPreElement before HTMLElement");
 97    }
 98    class HTMLPreElement extends globalObject.HTMLElement {
 99      constructor() {
100        return HTMLConstructor_helpers_html_constructor(globalObject, interfaceName, new.target);
101      }
102  
103      get width() {
104        const esValue = this !== null && this !== undefined ? this : globalObject;
105  
106        if (!exports.is(esValue)) {
107          throw new TypeError("'get width' called on an object that is not a valid instance of HTMLPreElement.");
108        }
109  
110        ceReactionsPreSteps_helpers_custom_elements(globalObject);
111        try {
112          let value = esValue[implSymbol].getAttributeNS(null, "width");
113          if (value === null) {
114            return 0;
115          }
116          value = parseInteger_helpers_strings(value);
117          return value !== null && conversions.long(value) === value ? value : 0;
118        } finally {
119          ceReactionsPostSteps_helpers_custom_elements(globalObject);
120        }
121      }
122  
123      set width(V) {
124        const esValue = this !== null && this !== undefined ? this : globalObject;
125  
126        if (!exports.is(esValue)) {
127          throw new TypeError("'set width' called on an object that is not a valid instance of HTMLPreElement.");
128        }
129  
130        V = conversions["long"](V, {
131          context: "Failed to set the 'width' property on 'HTMLPreElement': The provided value"
132        });
133  
134        ceReactionsPreSteps_helpers_custom_elements(globalObject);
135        try {
136          esValue[implSymbol].setAttributeNS(null, "width", String(V));
137        } finally {
138          ceReactionsPostSteps_helpers_custom_elements(globalObject);
139        }
140      }
141    }
142    Object.defineProperties(HTMLPreElement.prototype, {
143      width: { enumerable: true },
144      [Symbol.toStringTag]: { value: "HTMLPreElement", configurable: true }
145    });
146    if (globalObject[ctorRegistrySymbol] === undefined) {
147      globalObject[ctorRegistrySymbol] = Object.create(null);
148    }
149    globalObject[ctorRegistrySymbol][interfaceName] = HTMLPreElement;
150  
151    Object.defineProperty(globalObject, interfaceName, {
152      configurable: true,
153      writable: true,
154      value: HTMLPreElement
155    });
156  };
157  
158  const Impl = require("../nodes/HTMLPreElement-impl.js");