DOMRectReadOnly.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const DOMRectInit = require("./DOMRectInit.js");
  5. const implSymbol = utils.implSymbol;
  6. const ctorRegistrySymbol = utils.ctorRegistrySymbol;
  7. const interfaceName = "DOMRectReadOnly";
  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 'DOMRectReadOnly'.`);
  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]["DOMRectReadOnly"].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. exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
  40. privateData.wrapper = wrapper;
  41. exports._internalSetup(wrapper, globalObject);
  42. Object.defineProperty(wrapper, implSymbol, {
  43. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  44. configurable: true
  45. });
  46. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  47. if (Impl.init) {
  48. Impl.init(wrapper[implSymbol]);
  49. }
  50. return wrapper;
  51. };
  52. exports.new = (globalObject, newTarget) => {
  53. const wrapper = makeWrapper(globalObject, newTarget);
  54. exports._internalSetup(wrapper, globalObject);
  55. Object.defineProperty(wrapper, implSymbol, {
  56. value: Object.create(Impl.implementation.prototype),
  57. configurable: true
  58. });
  59. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  60. if (Impl.init) {
  61. Impl.init(wrapper[implSymbol]);
  62. }
  63. return wrapper[implSymbol];
  64. };
  65. const exposed = new Set(["Window", "Worker"]);
  66. exports.install = (globalObject, globalNames) => {
  67. if (!globalNames.some(globalName => exposed.has(globalName))) {
  68. return;
  69. }
  70. const ctorRegistry = utils.initCtorRegistry(globalObject);
  71. class DOMRectReadOnly {
  72. constructor() {
  73. const args = [];
  74. {
  75. let curArg = arguments[0];
  76. if (curArg !== undefined) {
  77. curArg = conversions["unrestricted double"](curArg, {
  78. context: "Failed to construct 'DOMRectReadOnly': parameter 1",
  79. globals: globalObject
  80. });
  81. } else {
  82. curArg = 0;
  83. }
  84. args.push(curArg);
  85. }
  86. {
  87. let curArg = arguments[1];
  88. if (curArg !== undefined) {
  89. curArg = conversions["unrestricted double"](curArg, {
  90. context: "Failed to construct 'DOMRectReadOnly': parameter 2",
  91. globals: globalObject
  92. });
  93. } else {
  94. curArg = 0;
  95. }
  96. args.push(curArg);
  97. }
  98. {
  99. let curArg = arguments[2];
  100. if (curArg !== undefined) {
  101. curArg = conversions["unrestricted double"](curArg, {
  102. context: "Failed to construct 'DOMRectReadOnly': parameter 3",
  103. globals: globalObject
  104. });
  105. } else {
  106. curArg = 0;
  107. }
  108. args.push(curArg);
  109. }
  110. {
  111. let curArg = arguments[3];
  112. if (curArg !== undefined) {
  113. curArg = conversions["unrestricted double"](curArg, {
  114. context: "Failed to construct 'DOMRectReadOnly': parameter 4",
  115. globals: globalObject
  116. });
  117. } else {
  118. curArg = 0;
  119. }
  120. args.push(curArg);
  121. }
  122. return exports.setup(Object.create(new.target.prototype), globalObject, args);
  123. }
  124. toJSON() {
  125. const esValue = this !== null && this !== undefined ? this : globalObject;
  126. if (!exports.is(esValue)) {
  127. throw new globalObject.TypeError(
  128. "'toJSON' called on an object that is not a valid instance of DOMRectReadOnly."
  129. );
  130. }
  131. return esValue[implSymbol].toJSON();
  132. }
  133. get x() {
  134. const esValue = this !== null && this !== undefined ? this : globalObject;
  135. if (!exports.is(esValue)) {
  136. throw new globalObject.TypeError(
  137. "'get x' called on an object that is not a valid instance of DOMRectReadOnly."
  138. );
  139. }
  140. return esValue[implSymbol]["x"];
  141. }
  142. get y() {
  143. const esValue = this !== null && this !== undefined ? this : globalObject;
  144. if (!exports.is(esValue)) {
  145. throw new globalObject.TypeError(
  146. "'get y' called on an object that is not a valid instance of DOMRectReadOnly."
  147. );
  148. }
  149. return esValue[implSymbol]["y"];
  150. }
  151. get width() {
  152. const esValue = this !== null && this !== undefined ? this : globalObject;
  153. if (!exports.is(esValue)) {
  154. throw new globalObject.TypeError(
  155. "'get width' called on an object that is not a valid instance of DOMRectReadOnly."
  156. );
  157. }
  158. return esValue[implSymbol]["width"];
  159. }
  160. get height() {
  161. const esValue = this !== null && this !== undefined ? this : globalObject;
  162. if (!exports.is(esValue)) {
  163. throw new globalObject.TypeError(
  164. "'get height' called on an object that is not a valid instance of DOMRectReadOnly."
  165. );
  166. }
  167. return esValue[implSymbol]["height"];
  168. }
  169. get top() {
  170. const esValue = this !== null && this !== undefined ? this : globalObject;
  171. if (!exports.is(esValue)) {
  172. throw new globalObject.TypeError(
  173. "'get top' called on an object that is not a valid instance of DOMRectReadOnly."
  174. );
  175. }
  176. return esValue[implSymbol]["top"];
  177. }
  178. get right() {
  179. const esValue = this !== null && this !== undefined ? this : globalObject;
  180. if (!exports.is(esValue)) {
  181. throw new globalObject.TypeError(
  182. "'get right' called on an object that is not a valid instance of DOMRectReadOnly."
  183. );
  184. }
  185. return esValue[implSymbol]["right"];
  186. }
  187. get bottom() {
  188. const esValue = this !== null && this !== undefined ? this : globalObject;
  189. if (!exports.is(esValue)) {
  190. throw new globalObject.TypeError(
  191. "'get bottom' called on an object that is not a valid instance of DOMRectReadOnly."
  192. );
  193. }
  194. return esValue[implSymbol]["bottom"];
  195. }
  196. get left() {
  197. const esValue = this !== null && this !== undefined ? this : globalObject;
  198. if (!exports.is(esValue)) {
  199. throw new globalObject.TypeError(
  200. "'get left' called on an object that is not a valid instance of DOMRectReadOnly."
  201. );
  202. }
  203. return esValue[implSymbol]["left"];
  204. }
  205. static fromRect() {
  206. const args = [];
  207. {
  208. let curArg = arguments[0];
  209. curArg = DOMRectInit.convert(globalObject, curArg, {
  210. context: "Failed to execute 'fromRect' on 'DOMRectReadOnly': parameter 1"
  211. });
  212. args.push(curArg);
  213. }
  214. return utils.tryWrapperForImpl(Impl.implementation.fromRect(globalObject, ...args));
  215. }
  216. }
  217. Object.defineProperties(DOMRectReadOnly.prototype, {
  218. toJSON: { enumerable: true },
  219. x: { enumerable: true },
  220. y: { enumerable: true },
  221. width: { enumerable: true },
  222. height: { enumerable: true },
  223. top: { enumerable: true },
  224. right: { enumerable: true },
  225. bottom: { enumerable: true },
  226. left: { enumerable: true },
  227. [Symbol.toStringTag]: { value: "DOMRectReadOnly", configurable: true }
  228. });
  229. Object.defineProperties(DOMRectReadOnly, { fromRect: { enumerable: true } });
  230. ctorRegistry[interfaceName] = DOMRectReadOnly;
  231. Object.defineProperty(globalObject, interfaceName, {
  232. configurable: true,
  233. writable: true,
  234. value: DOMRectReadOnly
  235. });
  236. };
  237. const Impl = require("../../jsdom/living/geometry/DOMRectReadOnly-impl.js");