CSSScopeRule.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 = "CSSScopeRule";
  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 'CSSScopeRule'.`);
  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]["CSSScopeRule"].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 CSSScopeRule extends globalObject.CSSGroupingRule {
  74. constructor() {
  75. throw new globalObject.TypeError("Illegal constructor");
  76. }
  77. get start() {
  78. const esValue = this !== null && this !== undefined ? this : globalObject;
  79. if (!exports.is(esValue)) {
  80. throw new globalObject.TypeError(
  81. "'get start' called on an object that is not a valid instance of CSSScopeRule."
  82. );
  83. }
  84. return utils.tryWrapperForImpl(esValue[implSymbol]["start"]);
  85. }
  86. get end() {
  87. const esValue = this !== null && this !== undefined ? this : globalObject;
  88. if (!exports.is(esValue)) {
  89. throw new globalObject.TypeError("'get end' called on an object that is not a valid instance of CSSScopeRule.");
  90. }
  91. return utils.tryWrapperForImpl(esValue[implSymbol]["end"]);
  92. }
  93. }
  94. Object.defineProperties(CSSScopeRule.prototype, {
  95. start: { enumerable: true },
  96. end: { enumerable: true },
  97. [Symbol.toStringTag]: { value: "CSSScopeRule", configurable: true }
  98. });
  99. ctorRegistry[interfaceName] = CSSScopeRule;
  100. Object.defineProperty(globalObject, interfaceName, {
  101. configurable: true,
  102. writable: true,
  103. value: CSSScopeRule
  104. });
  105. };
  106. const Impl = require("../../jsdom/living/css/CSSScopeRule-impl.js");