SVGSymbolElement.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const create_SVGAnimatedRect = require("./SVGAnimatedRect.js").create;
  5. const create_SVGAnimatedPreserveAspectRatio = require("./SVGAnimatedPreserveAspectRatio.js").create;
  6. const implSymbol = utils.implSymbol;
  7. const ctorRegistrySymbol = utils.ctorRegistrySymbol;
  8. const SVGGraphicsElement = require("./SVGGraphicsElement.js");
  9. const interfaceName = "SVGSymbolElement";
  10. exports.is = value => {
  11. return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
  12. };
  13. exports.isImpl = value => {
  14. return utils.isObject(value) && value instanceof Impl.implementation;
  15. };
  16. exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
  17. if (exports.is(value)) {
  18. return utils.implForWrapper(value);
  19. }
  20. throw new globalObject.TypeError(`${context} is not of type 'SVGSymbolElement'.`);
  21. };
  22. function makeWrapper(globalObject, newTarget) {
  23. let proto;
  24. if (newTarget !== undefined) {
  25. proto = newTarget.prototype;
  26. }
  27. if (!utils.isObject(proto)) {
  28. proto = globalObject[ctorRegistrySymbol]["SVGSymbolElement"].prototype;
  29. }
  30. return Object.create(proto);
  31. }
  32. exports.create = (globalObject, constructorArgs, privateData) => {
  33. const wrapper = makeWrapper(globalObject);
  34. return exports.setup(wrapper, globalObject, constructorArgs, privateData);
  35. };
  36. exports.createImpl = (globalObject, constructorArgs, privateData) => {
  37. const wrapper = exports.create(globalObject, constructorArgs, privateData);
  38. return utils.implForWrapper(wrapper);
  39. };
  40. exports._internalSetup = (wrapper, globalObject) => {
  41. SVGGraphicsElement._internalSetup(wrapper, globalObject);
  42. };
  43. exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
  44. privateData.wrapper = wrapper;
  45. exports._internalSetup(wrapper, globalObject);
  46. Object.defineProperty(wrapper, implSymbol, {
  47. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  48. configurable: true
  49. });
  50. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  51. if (Impl.init) {
  52. Impl.init(wrapper[implSymbol]);
  53. }
  54. return wrapper;
  55. };
  56. exports.new = (globalObject, newTarget) => {
  57. const wrapper = makeWrapper(globalObject, newTarget);
  58. exports._internalSetup(wrapper, globalObject);
  59. Object.defineProperty(wrapper, implSymbol, {
  60. value: Object.create(Impl.implementation.prototype),
  61. configurable: true
  62. });
  63. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  64. if (Impl.init) {
  65. Impl.init(wrapper[implSymbol]);
  66. }
  67. return wrapper[implSymbol];
  68. };
  69. const exposed = new Set(["Window"]);
  70. exports.install = (globalObject, globalNames) => {
  71. if (!globalNames.some(globalName => exposed.has(globalName))) {
  72. return;
  73. }
  74. const ctorRegistry = utils.initCtorRegistry(globalObject);
  75. class SVGSymbolElement extends globalObject.SVGGraphicsElement {
  76. constructor() {
  77. throw new globalObject.TypeError("Illegal constructor");
  78. }
  79. get viewBox() {
  80. const esValue = this !== null && this !== undefined ? this : globalObject;
  81. if (!exports.is(esValue)) {
  82. throw new globalObject.TypeError(
  83. "'get viewBox' called on an object that is not a valid instance of SVGSymbolElement."
  84. );
  85. }
  86. return utils.getSameObject(this, "viewBox", () => {
  87. return create_SVGAnimatedRect(globalObject, [], {
  88. element: esValue[implSymbol],
  89. attribute: "viewBox"
  90. });
  91. });
  92. }
  93. get preserveAspectRatio() {
  94. const esValue = this !== null && this !== undefined ? this : globalObject;
  95. if (!exports.is(esValue)) {
  96. throw new globalObject.TypeError(
  97. "'get preserveAspectRatio' called on an object that is not a valid instance of SVGSymbolElement."
  98. );
  99. }
  100. return utils.getSameObject(this, "preserveAspectRatio", () => {
  101. return create_SVGAnimatedPreserveAspectRatio(globalObject, [], {
  102. element: esValue[implSymbol]
  103. });
  104. });
  105. }
  106. }
  107. Object.defineProperties(SVGSymbolElement.prototype, {
  108. viewBox: { enumerable: true },
  109. preserveAspectRatio: { enumerable: true },
  110. [Symbol.toStringTag]: { value: "SVGSymbolElement", configurable: true }
  111. });
  112. ctorRegistry[interfaceName] = SVGSymbolElement;
  113. Object.defineProperty(globalObject, interfaceName, {
  114. configurable: true,
  115. writable: true,
  116. value: SVGSymbolElement
  117. });
  118. };
  119. const Impl = require("../../jsdom/living/nodes/SVGSymbolElement-impl.js");