CSSGroupingRule.js 5.7 KB

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