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