CSSPageRule.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 CSSGroupingRule = require("./CSSGroupingRule.js");
  7. const interfaceName = "CSSPageRule";
  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 'CSSPageRule'.`);
  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]["CSSPageRule"].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. CSSGroupingRule._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 CSSPageRule extends globalObject.CSSGroupingRule {
  74. constructor() {
  75. throw new globalObject.TypeError("Illegal constructor");
  76. }
  77. get selectorText() {
  78. const esValue = this !== null && this !== undefined ? this : globalObject;
  79. if (!exports.is(esValue)) {
  80. throw new globalObject.TypeError(
  81. "'get selectorText' called on an object that is not a valid instance of CSSPageRule."
  82. );
  83. }
  84. return utils.tryWrapperForImpl(esValue[implSymbol]["selectorText"]);
  85. }
  86. set selectorText(V) {
  87. const esValue = this !== null && this !== undefined ? this : globalObject;
  88. if (!exports.is(esValue)) {
  89. throw new globalObject.TypeError(
  90. "'set selectorText' called on an object that is not a valid instance of CSSPageRule."
  91. );
  92. }
  93. V = conversions["DOMString"](V, {
  94. context: "Failed to set the 'selectorText' property on 'CSSPageRule': The provided value",
  95. globals: globalObject
  96. });
  97. esValue[implSymbol]["selectorText"] = V;
  98. }
  99. get style() {
  100. const esValue = this !== null && this !== undefined ? this : globalObject;
  101. if (!exports.is(esValue)) {
  102. throw new globalObject.TypeError(
  103. "'get style' called on an object that is not a valid instance of CSSPageRule."
  104. );
  105. }
  106. return utils.getSameObject(this, "style", () => {
  107. return utils.tryWrapperForImpl(esValue[implSymbol]["style"]);
  108. });
  109. }
  110. set style(V) {
  111. const esValue = this !== null && this !== undefined ? this : globalObject;
  112. if (!exports.is(esValue)) {
  113. throw new globalObject.TypeError(
  114. "'set style' called on an object that is not a valid instance of CSSPageRule."
  115. );
  116. }
  117. const Q = esValue["style"];
  118. if (!utils.isObject(Q)) {
  119. throw new globalObject.TypeError("Property 'style' is not an object");
  120. }
  121. Reflect.set(Q, "cssText", V);
  122. }
  123. }
  124. Object.defineProperties(CSSPageRule.prototype, {
  125. selectorText: { enumerable: true },
  126. style: { enumerable: true },
  127. [Symbol.toStringTag]: { value: "CSSPageRule", configurable: true }
  128. });
  129. ctorRegistry[interfaceName] = CSSPageRule;
  130. Object.defineProperty(globalObject, interfaceName, {
  131. configurable: true,
  132. writable: true,
  133. value: CSSPageRule
  134. });
  135. };
  136. const Impl = require("../../jsdom/living/css/CSSPageRule-impl.js");