Attr.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const ceReactionsPreSteps_jsdom_living_helpers_custom_elements =
  5. require("../../jsdom/living/helpers/custom-elements.js").ceReactionsPreSteps;
  6. const ceReactionsPostSteps_jsdom_living_helpers_custom_elements =
  7. require("../../jsdom/living/helpers/custom-elements.js").ceReactionsPostSteps;
  8. const implSymbol = utils.implSymbol;
  9. const ctorRegistrySymbol = utils.ctorRegistrySymbol;
  10. const Node = require("./Node.js");
  11. const interfaceName = "Attr";
  12. exports.is = value => {
  13. return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
  14. };
  15. exports.isImpl = value => {
  16. return utils.isObject(value) && value instanceof Impl.implementation;
  17. };
  18. exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
  19. if (exports.is(value)) {
  20. return utils.implForWrapper(value);
  21. }
  22. throw new globalObject.TypeError(`${context} is not of type 'Attr'.`);
  23. };
  24. function makeWrapper(globalObject, newTarget) {
  25. let proto;
  26. if (newTarget !== undefined) {
  27. proto = newTarget.prototype;
  28. }
  29. if (!utils.isObject(proto)) {
  30. proto = globalObject[ctorRegistrySymbol]["Attr"].prototype;
  31. }
  32. return Object.create(proto);
  33. }
  34. exports.create = (globalObject, constructorArgs, privateData) => {
  35. const wrapper = makeWrapper(globalObject);
  36. return exports.setup(wrapper, globalObject, constructorArgs, privateData);
  37. };
  38. exports.createImpl = (globalObject, constructorArgs, privateData) => {
  39. const wrapper = exports.create(globalObject, constructorArgs, privateData);
  40. return utils.implForWrapper(wrapper);
  41. };
  42. exports._internalSetup = (wrapper, globalObject) => {
  43. Node._internalSetup(wrapper, globalObject);
  44. };
  45. exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
  46. privateData.wrapper = wrapper;
  47. exports._internalSetup(wrapper, globalObject);
  48. Object.defineProperty(wrapper, implSymbol, {
  49. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  50. configurable: true
  51. });
  52. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  53. if (Impl.init) {
  54. Impl.init(wrapper[implSymbol]);
  55. }
  56. return wrapper;
  57. };
  58. exports.new = (globalObject, newTarget) => {
  59. const wrapper = makeWrapper(globalObject, newTarget);
  60. exports._internalSetup(wrapper, globalObject);
  61. Object.defineProperty(wrapper, implSymbol, {
  62. value: Object.create(Impl.implementation.prototype),
  63. configurable: true
  64. });
  65. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  66. if (Impl.init) {
  67. Impl.init(wrapper[implSymbol]);
  68. }
  69. return wrapper[implSymbol];
  70. };
  71. const exposed = new Set(["Window"]);
  72. exports.install = (globalObject, globalNames) => {
  73. if (!globalNames.some(globalName => exposed.has(globalName))) {
  74. return;
  75. }
  76. const ctorRegistry = utils.initCtorRegistry(globalObject);
  77. class Attr extends globalObject.Node {
  78. constructor() {
  79. throw new globalObject.TypeError("Illegal constructor");
  80. }
  81. get namespaceURI() {
  82. const esValue = this !== null && this !== undefined ? this : globalObject;
  83. if (!exports.is(esValue)) {
  84. throw new globalObject.TypeError(
  85. "'get namespaceURI' called on an object that is not a valid instance of Attr."
  86. );
  87. }
  88. return esValue[implSymbol]["namespaceURI"];
  89. }
  90. get prefix() {
  91. const esValue = this !== null && this !== undefined ? this : globalObject;
  92. if (!exports.is(esValue)) {
  93. throw new globalObject.TypeError("'get prefix' called on an object that is not a valid instance of Attr.");
  94. }
  95. return esValue[implSymbol]["prefix"];
  96. }
  97. get localName() {
  98. const esValue = this !== null && this !== undefined ? this : globalObject;
  99. if (!exports.is(esValue)) {
  100. throw new globalObject.TypeError("'get localName' called on an object that is not a valid instance of Attr.");
  101. }
  102. return esValue[implSymbol]["localName"];
  103. }
  104. get name() {
  105. const esValue = this !== null && this !== undefined ? this : globalObject;
  106. if (!exports.is(esValue)) {
  107. throw new globalObject.TypeError("'get name' called on an object that is not a valid instance of Attr.");
  108. }
  109. return esValue[implSymbol]["name"];
  110. }
  111. get value() {
  112. const esValue = this !== null && this !== undefined ? this : globalObject;
  113. if (!exports.is(esValue)) {
  114. throw new globalObject.TypeError("'get value' called on an object that is not a valid instance of Attr.");
  115. }
  116. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  117. try {
  118. return esValue[implSymbol]["value"];
  119. } finally {
  120. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  121. }
  122. }
  123. set value(V) {
  124. const esValue = this !== null && this !== undefined ? this : globalObject;
  125. if (!exports.is(esValue)) {
  126. throw new globalObject.TypeError("'set value' called on an object that is not a valid instance of Attr.");
  127. }
  128. V = conversions["DOMString"](V, {
  129. context: "Failed to set the 'value' property on 'Attr': The provided value",
  130. globals: globalObject
  131. });
  132. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  133. try {
  134. esValue[implSymbol]["value"] = V;
  135. } finally {
  136. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  137. }
  138. }
  139. get ownerElement() {
  140. const esValue = this !== null && this !== undefined ? this : globalObject;
  141. if (!exports.is(esValue)) {
  142. throw new globalObject.TypeError(
  143. "'get ownerElement' called on an object that is not a valid instance of Attr."
  144. );
  145. }
  146. return utils.tryWrapperForImpl(esValue[implSymbol]["ownerElement"]);
  147. }
  148. get specified() {
  149. const esValue = this !== null && this !== undefined ? this : globalObject;
  150. if (!exports.is(esValue)) {
  151. throw new globalObject.TypeError("'get specified' called on an object that is not a valid instance of Attr.");
  152. }
  153. return esValue[implSymbol]["specified"];
  154. }
  155. }
  156. Object.defineProperties(Attr.prototype, {
  157. namespaceURI: { enumerable: true },
  158. prefix: { enumerable: true },
  159. localName: { enumerable: true },
  160. name: { enumerable: true },
  161. value: { enumerable: true },
  162. ownerElement: { enumerable: true },
  163. specified: { enumerable: true },
  164. [Symbol.toStringTag]: { value: "Attr", configurable: true }
  165. });
  166. ctorRegistry[interfaceName] = Attr;
  167. Object.defineProperty(globalObject, interfaceName, {
  168. configurable: true,
  169. writable: true,
  170. value: Attr
  171. });
  172. };
  173. const Impl = require("../../jsdom/living/attributes/Attr-impl.js");