Node.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const GetRootNodeOptions = require("./GetRootNodeOptions.js");
  5. const ceReactionsPreSteps_jsdom_living_helpers_custom_elements =
  6. require("../../jsdom/living/helpers/custom-elements.js").ceReactionsPreSteps;
  7. const ceReactionsPostSteps_jsdom_living_helpers_custom_elements =
  8. require("../../jsdom/living/helpers/custom-elements.js").ceReactionsPostSteps;
  9. const implSymbol = utils.implSymbol;
  10. const ctorRegistrySymbol = utils.ctorRegistrySymbol;
  11. const EventTarget = require("./EventTarget.js");
  12. const interfaceName = "Node";
  13. exports.is = value => {
  14. return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
  15. };
  16. exports.isImpl = value => {
  17. return utils.isObject(value) && value instanceof Impl.implementation;
  18. };
  19. exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
  20. if (exports.is(value)) {
  21. return utils.implForWrapper(value);
  22. }
  23. throw new globalObject.TypeError(`${context} is not of type 'Node'.`);
  24. };
  25. function makeWrapper(globalObject, newTarget) {
  26. let proto;
  27. if (newTarget !== undefined) {
  28. proto = newTarget.prototype;
  29. }
  30. if (!utils.isObject(proto)) {
  31. proto = globalObject[ctorRegistrySymbol]["Node"].prototype;
  32. }
  33. return Object.create(proto);
  34. }
  35. exports.create = (globalObject, constructorArgs, privateData) => {
  36. const wrapper = makeWrapper(globalObject);
  37. return exports.setup(wrapper, globalObject, constructorArgs, privateData);
  38. };
  39. exports.createImpl = (globalObject, constructorArgs, privateData) => {
  40. const wrapper = exports.create(globalObject, constructorArgs, privateData);
  41. return utils.implForWrapper(wrapper);
  42. };
  43. exports._internalSetup = (wrapper, globalObject) => {
  44. EventTarget._internalSetup(wrapper, globalObject);
  45. };
  46. exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
  47. privateData.wrapper = wrapper;
  48. exports._internalSetup(wrapper, globalObject);
  49. Object.defineProperty(wrapper, implSymbol, {
  50. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  51. configurable: true
  52. });
  53. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  54. if (Impl.init) {
  55. Impl.init(wrapper[implSymbol]);
  56. }
  57. return wrapper;
  58. };
  59. exports.new = (globalObject, newTarget) => {
  60. const wrapper = makeWrapper(globalObject, newTarget);
  61. exports._internalSetup(wrapper, globalObject);
  62. Object.defineProperty(wrapper, implSymbol, {
  63. value: Object.create(Impl.implementation.prototype),
  64. configurable: true
  65. });
  66. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  67. if (Impl.init) {
  68. Impl.init(wrapper[implSymbol]);
  69. }
  70. return wrapper[implSymbol];
  71. };
  72. const exposed = new Set(["Window"]);
  73. exports.install = (globalObject, globalNames) => {
  74. if (!globalNames.some(globalName => exposed.has(globalName))) {
  75. return;
  76. }
  77. const ctorRegistry = utils.initCtorRegistry(globalObject);
  78. class Node extends globalObject.EventTarget {
  79. constructor() {
  80. throw new globalObject.TypeError("Illegal constructor");
  81. }
  82. getRootNode() {
  83. const esValue = this !== null && this !== undefined ? this : globalObject;
  84. if (!exports.is(esValue)) {
  85. throw new globalObject.TypeError("'getRootNode' called on an object that is not a valid instance of Node.");
  86. }
  87. const args = [];
  88. {
  89. let curArg = arguments[0];
  90. curArg = GetRootNodeOptions.convert(globalObject, curArg, {
  91. context: "Failed to execute 'getRootNode' on 'Node': parameter 1"
  92. });
  93. args.push(curArg);
  94. }
  95. return utils.tryWrapperForImpl(esValue[implSymbol].getRootNode(...args));
  96. }
  97. hasChildNodes() {
  98. const esValue = this !== null && this !== undefined ? this : globalObject;
  99. if (!exports.is(esValue)) {
  100. throw new globalObject.TypeError("'hasChildNodes' called on an object that is not a valid instance of Node.");
  101. }
  102. return esValue[implSymbol].hasChildNodes();
  103. }
  104. normalize() {
  105. const esValue = this !== null && this !== undefined ? this : globalObject;
  106. if (!exports.is(esValue)) {
  107. throw new globalObject.TypeError("'normalize' called on an object that is not a valid instance of Node.");
  108. }
  109. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  110. try {
  111. return esValue[implSymbol].normalize();
  112. } finally {
  113. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  114. }
  115. }
  116. cloneNode() {
  117. const esValue = this !== null && this !== undefined ? this : globalObject;
  118. if (!exports.is(esValue)) {
  119. throw new globalObject.TypeError("'cloneNode' called on an object that is not a valid instance of Node.");
  120. }
  121. const args = [];
  122. {
  123. let curArg = arguments[0];
  124. if (curArg !== undefined) {
  125. curArg = conversions["boolean"](curArg, {
  126. context: "Failed to execute 'cloneNode' on 'Node': parameter 1",
  127. globals: globalObject
  128. });
  129. } else {
  130. curArg = false;
  131. }
  132. args.push(curArg);
  133. }
  134. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  135. try {
  136. return utils.tryWrapperForImpl(esValue[implSymbol].cloneNode(...args));
  137. } finally {
  138. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  139. }
  140. }
  141. isEqualNode(otherNode) {
  142. const esValue = this !== null && this !== undefined ? this : globalObject;
  143. if (!exports.is(esValue)) {
  144. throw new globalObject.TypeError("'isEqualNode' called on an object that is not a valid instance of Node.");
  145. }
  146. if (arguments.length < 1) {
  147. throw new globalObject.TypeError(
  148. `Failed to execute 'isEqualNode' on 'Node': 1 argument required, but only ${arguments.length} present.`
  149. );
  150. }
  151. const args = [];
  152. {
  153. let curArg = arguments[0];
  154. if (curArg === null || curArg === undefined) {
  155. curArg = null;
  156. } else {
  157. curArg = exports.convert(globalObject, curArg, {
  158. context: "Failed to execute 'isEqualNode' on 'Node': parameter 1"
  159. });
  160. }
  161. args.push(curArg);
  162. }
  163. return esValue[implSymbol].isEqualNode(...args);
  164. }
  165. isSameNode(otherNode) {
  166. const esValue = this !== null && this !== undefined ? this : globalObject;
  167. if (!exports.is(esValue)) {
  168. throw new globalObject.TypeError("'isSameNode' called on an object that is not a valid instance of Node.");
  169. }
  170. if (arguments.length < 1) {
  171. throw new globalObject.TypeError(
  172. `Failed to execute 'isSameNode' on 'Node': 1 argument required, but only ${arguments.length} present.`
  173. );
  174. }
  175. const args = [];
  176. {
  177. let curArg = arguments[0];
  178. if (curArg === null || curArg === undefined) {
  179. curArg = null;
  180. } else {
  181. curArg = exports.convert(globalObject, curArg, {
  182. context: "Failed to execute 'isSameNode' on 'Node': parameter 1"
  183. });
  184. }
  185. args.push(curArg);
  186. }
  187. return esValue[implSymbol].isSameNode(...args);
  188. }
  189. compareDocumentPosition(other) {
  190. const esValue = this !== null && this !== undefined ? this : globalObject;
  191. if (!exports.is(esValue)) {
  192. throw new globalObject.TypeError(
  193. "'compareDocumentPosition' called on an object that is not a valid instance of Node."
  194. );
  195. }
  196. if (arguments.length < 1) {
  197. throw new globalObject.TypeError(
  198. `Failed to execute 'compareDocumentPosition' on 'Node': 1 argument required, but only ${arguments.length} present.`
  199. );
  200. }
  201. const args = [];
  202. {
  203. let curArg = arguments[0];
  204. curArg = exports.convert(globalObject, curArg, {
  205. context: "Failed to execute 'compareDocumentPosition' on 'Node': parameter 1"
  206. });
  207. args.push(curArg);
  208. }
  209. return esValue[implSymbol].compareDocumentPosition(...args);
  210. }
  211. contains(other) {
  212. const esValue = this !== null && this !== undefined ? this : globalObject;
  213. if (!exports.is(esValue)) {
  214. throw new globalObject.TypeError("'contains' called on an object that is not a valid instance of Node.");
  215. }
  216. if (arguments.length < 1) {
  217. throw new globalObject.TypeError(
  218. `Failed to execute 'contains' on 'Node': 1 argument required, but only ${arguments.length} present.`
  219. );
  220. }
  221. const args = [];
  222. {
  223. let curArg = arguments[0];
  224. if (curArg === null || curArg === undefined) {
  225. curArg = null;
  226. } else {
  227. curArg = exports.convert(globalObject, curArg, {
  228. context: "Failed to execute 'contains' on 'Node': parameter 1"
  229. });
  230. }
  231. args.push(curArg);
  232. }
  233. return esValue[implSymbol].contains(...args);
  234. }
  235. lookupPrefix(namespace) {
  236. const esValue = this !== null && this !== undefined ? this : globalObject;
  237. if (!exports.is(esValue)) {
  238. throw new globalObject.TypeError("'lookupPrefix' called on an object that is not a valid instance of Node.");
  239. }
  240. if (arguments.length < 1) {
  241. throw new globalObject.TypeError(
  242. `Failed to execute 'lookupPrefix' on 'Node': 1 argument required, but only ${arguments.length} present.`
  243. );
  244. }
  245. const args = [];
  246. {
  247. let curArg = arguments[0];
  248. if (curArg === null || curArg === undefined) {
  249. curArg = null;
  250. } else {
  251. curArg = conversions["DOMString"](curArg, {
  252. context: "Failed to execute 'lookupPrefix' on 'Node': parameter 1",
  253. globals: globalObject
  254. });
  255. }
  256. args.push(curArg);
  257. }
  258. return esValue[implSymbol].lookupPrefix(...args);
  259. }
  260. lookupNamespaceURI(prefix) {
  261. const esValue = this !== null && this !== undefined ? this : globalObject;
  262. if (!exports.is(esValue)) {
  263. throw new globalObject.TypeError(
  264. "'lookupNamespaceURI' called on an object that is not a valid instance of Node."
  265. );
  266. }
  267. if (arguments.length < 1) {
  268. throw new globalObject.TypeError(
  269. `Failed to execute 'lookupNamespaceURI' on 'Node': 1 argument required, but only ${arguments.length} present.`
  270. );
  271. }
  272. const args = [];
  273. {
  274. let curArg = arguments[0];
  275. if (curArg === null || curArg === undefined) {
  276. curArg = null;
  277. } else {
  278. curArg = conversions["DOMString"](curArg, {
  279. context: "Failed to execute 'lookupNamespaceURI' on 'Node': parameter 1",
  280. globals: globalObject
  281. });
  282. }
  283. args.push(curArg);
  284. }
  285. return esValue[implSymbol].lookupNamespaceURI(...args);
  286. }
  287. isDefaultNamespace(namespace) {
  288. const esValue = this !== null && this !== undefined ? this : globalObject;
  289. if (!exports.is(esValue)) {
  290. throw new globalObject.TypeError(
  291. "'isDefaultNamespace' called on an object that is not a valid instance of Node."
  292. );
  293. }
  294. if (arguments.length < 1) {
  295. throw new globalObject.TypeError(
  296. `Failed to execute 'isDefaultNamespace' on 'Node': 1 argument required, but only ${arguments.length} present.`
  297. );
  298. }
  299. const args = [];
  300. {
  301. let curArg = arguments[0];
  302. if (curArg === null || curArg === undefined) {
  303. curArg = null;
  304. } else {
  305. curArg = conversions["DOMString"](curArg, {
  306. context: "Failed to execute 'isDefaultNamespace' on 'Node': parameter 1",
  307. globals: globalObject
  308. });
  309. }
  310. args.push(curArg);
  311. }
  312. return esValue[implSymbol].isDefaultNamespace(...args);
  313. }
  314. insertBefore(node, child) {
  315. const esValue = this !== null && this !== undefined ? this : globalObject;
  316. if (!exports.is(esValue)) {
  317. throw new globalObject.TypeError("'insertBefore' called on an object that is not a valid instance of Node.");
  318. }
  319. if (arguments.length < 2) {
  320. throw new globalObject.TypeError(
  321. `Failed to execute 'insertBefore' on 'Node': 2 arguments required, but only ${arguments.length} present.`
  322. );
  323. }
  324. const args = [];
  325. {
  326. let curArg = arguments[0];
  327. curArg = exports.convert(globalObject, curArg, {
  328. context: "Failed to execute 'insertBefore' on 'Node': parameter 1"
  329. });
  330. args.push(curArg);
  331. }
  332. {
  333. let curArg = arguments[1];
  334. if (curArg === null || curArg === undefined) {
  335. curArg = null;
  336. } else {
  337. curArg = exports.convert(globalObject, curArg, {
  338. context: "Failed to execute 'insertBefore' on 'Node': parameter 2"
  339. });
  340. }
  341. args.push(curArg);
  342. }
  343. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  344. try {
  345. return utils.tryWrapperForImpl(esValue[implSymbol].insertBefore(...args));
  346. } finally {
  347. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  348. }
  349. }
  350. appendChild(node) {
  351. const esValue = this !== null && this !== undefined ? this : globalObject;
  352. if (!exports.is(esValue)) {
  353. throw new globalObject.TypeError("'appendChild' called on an object that is not a valid instance of Node.");
  354. }
  355. if (arguments.length < 1) {
  356. throw new globalObject.TypeError(
  357. `Failed to execute 'appendChild' on 'Node': 1 argument required, but only ${arguments.length} present.`
  358. );
  359. }
  360. const args = [];
  361. {
  362. let curArg = arguments[0];
  363. curArg = exports.convert(globalObject, curArg, {
  364. context: "Failed to execute 'appendChild' on 'Node': parameter 1"
  365. });
  366. args.push(curArg);
  367. }
  368. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  369. try {
  370. return utils.tryWrapperForImpl(esValue[implSymbol].appendChild(...args));
  371. } finally {
  372. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  373. }
  374. }
  375. replaceChild(node, child) {
  376. const esValue = this !== null && this !== undefined ? this : globalObject;
  377. if (!exports.is(esValue)) {
  378. throw new globalObject.TypeError("'replaceChild' called on an object that is not a valid instance of Node.");
  379. }
  380. if (arguments.length < 2) {
  381. throw new globalObject.TypeError(
  382. `Failed to execute 'replaceChild' on 'Node': 2 arguments required, but only ${arguments.length} present.`
  383. );
  384. }
  385. const args = [];
  386. {
  387. let curArg = arguments[0];
  388. curArg = exports.convert(globalObject, curArg, {
  389. context: "Failed to execute 'replaceChild' on 'Node': parameter 1"
  390. });
  391. args.push(curArg);
  392. }
  393. {
  394. let curArg = arguments[1];
  395. curArg = exports.convert(globalObject, curArg, {
  396. context: "Failed to execute 'replaceChild' on 'Node': parameter 2"
  397. });
  398. args.push(curArg);
  399. }
  400. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  401. try {
  402. return utils.tryWrapperForImpl(esValue[implSymbol].replaceChild(...args));
  403. } finally {
  404. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  405. }
  406. }
  407. removeChild(child) {
  408. const esValue = this !== null && this !== undefined ? this : globalObject;
  409. if (!exports.is(esValue)) {
  410. throw new globalObject.TypeError("'removeChild' called on an object that is not a valid instance of Node.");
  411. }
  412. if (arguments.length < 1) {
  413. throw new globalObject.TypeError(
  414. `Failed to execute 'removeChild' on 'Node': 1 argument required, but only ${arguments.length} present.`
  415. );
  416. }
  417. const args = [];
  418. {
  419. let curArg = arguments[0];
  420. curArg = exports.convert(globalObject, curArg, {
  421. context: "Failed to execute 'removeChild' on 'Node': parameter 1"
  422. });
  423. args.push(curArg);
  424. }
  425. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  426. try {
  427. return utils.tryWrapperForImpl(esValue[implSymbol].removeChild(...args));
  428. } finally {
  429. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  430. }
  431. }
  432. get nodeType() {
  433. const esValue = this !== null && this !== undefined ? this : globalObject;
  434. if (!exports.is(esValue)) {
  435. throw new globalObject.TypeError("'get nodeType' called on an object that is not a valid instance of Node.");
  436. }
  437. return esValue[implSymbol]["nodeType"];
  438. }
  439. get nodeName() {
  440. const esValue = this !== null && this !== undefined ? this : globalObject;
  441. if (!exports.is(esValue)) {
  442. throw new globalObject.TypeError("'get nodeName' called on an object that is not a valid instance of Node.");
  443. }
  444. return esValue[implSymbol]["nodeName"];
  445. }
  446. get baseURI() {
  447. const esValue = this !== null && this !== undefined ? this : globalObject;
  448. if (!exports.is(esValue)) {
  449. throw new globalObject.TypeError("'get baseURI' called on an object that is not a valid instance of Node.");
  450. }
  451. return esValue[implSymbol]["baseURI"];
  452. }
  453. get isConnected() {
  454. const esValue = this !== null && this !== undefined ? this : globalObject;
  455. if (!exports.is(esValue)) {
  456. throw new globalObject.TypeError("'get isConnected' called on an object that is not a valid instance of Node.");
  457. }
  458. return esValue[implSymbol]["isConnected"];
  459. }
  460. get ownerDocument() {
  461. const esValue = this !== null && this !== undefined ? this : globalObject;
  462. if (!exports.is(esValue)) {
  463. throw new globalObject.TypeError(
  464. "'get ownerDocument' called on an object that is not a valid instance of Node."
  465. );
  466. }
  467. return utils.tryWrapperForImpl(esValue[implSymbol]["ownerDocument"]);
  468. }
  469. get parentNode() {
  470. const esValue = this !== null && this !== undefined ? this : globalObject;
  471. if (!exports.is(esValue)) {
  472. throw new globalObject.TypeError("'get parentNode' called on an object that is not a valid instance of Node.");
  473. }
  474. return utils.tryWrapperForImpl(esValue[implSymbol]["parentNode"]);
  475. }
  476. get parentElement() {
  477. const esValue = this !== null && this !== undefined ? this : globalObject;
  478. if (!exports.is(esValue)) {
  479. throw new globalObject.TypeError(
  480. "'get parentElement' called on an object that is not a valid instance of Node."
  481. );
  482. }
  483. return utils.tryWrapperForImpl(esValue[implSymbol]["parentElement"]);
  484. }
  485. get childNodes() {
  486. const esValue = this !== null && this !== undefined ? this : globalObject;
  487. if (!exports.is(esValue)) {
  488. throw new globalObject.TypeError("'get childNodes' called on an object that is not a valid instance of Node.");
  489. }
  490. return utils.getSameObject(this, "childNodes", () => {
  491. return utils.tryWrapperForImpl(esValue[implSymbol]["childNodes"]);
  492. });
  493. }
  494. get firstChild() {
  495. const esValue = this !== null && this !== undefined ? this : globalObject;
  496. if (!exports.is(esValue)) {
  497. throw new globalObject.TypeError("'get firstChild' called on an object that is not a valid instance of Node.");
  498. }
  499. return utils.tryWrapperForImpl(esValue[implSymbol]["firstChild"]);
  500. }
  501. get lastChild() {
  502. const esValue = this !== null && this !== undefined ? this : globalObject;
  503. if (!exports.is(esValue)) {
  504. throw new globalObject.TypeError("'get lastChild' called on an object that is not a valid instance of Node.");
  505. }
  506. return utils.tryWrapperForImpl(esValue[implSymbol]["lastChild"]);
  507. }
  508. get previousSibling() {
  509. const esValue = this !== null && this !== undefined ? this : globalObject;
  510. if (!exports.is(esValue)) {
  511. throw new globalObject.TypeError(
  512. "'get previousSibling' called on an object that is not a valid instance of Node."
  513. );
  514. }
  515. return utils.tryWrapperForImpl(esValue[implSymbol]["previousSibling"]);
  516. }
  517. get nextSibling() {
  518. const esValue = this !== null && this !== undefined ? this : globalObject;
  519. if (!exports.is(esValue)) {
  520. throw new globalObject.TypeError("'get nextSibling' called on an object that is not a valid instance of Node.");
  521. }
  522. return utils.tryWrapperForImpl(esValue[implSymbol]["nextSibling"]);
  523. }
  524. get nodeValue() {
  525. const esValue = this !== null && this !== undefined ? this : globalObject;
  526. if (!exports.is(esValue)) {
  527. throw new globalObject.TypeError("'get nodeValue' called on an object that is not a valid instance of Node.");
  528. }
  529. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  530. try {
  531. return esValue[implSymbol]["nodeValue"];
  532. } finally {
  533. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  534. }
  535. }
  536. set nodeValue(V) {
  537. const esValue = this !== null && this !== undefined ? this : globalObject;
  538. if (!exports.is(esValue)) {
  539. throw new globalObject.TypeError("'set nodeValue' called on an object that is not a valid instance of Node.");
  540. }
  541. if (V === null || V === undefined) {
  542. V = null;
  543. } else {
  544. V = conversions["DOMString"](V, {
  545. context: "Failed to set the 'nodeValue' property on 'Node': The provided value",
  546. globals: globalObject
  547. });
  548. }
  549. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  550. try {
  551. esValue[implSymbol]["nodeValue"] = V;
  552. } finally {
  553. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  554. }
  555. }
  556. get textContent() {
  557. const esValue = this !== null && this !== undefined ? this : globalObject;
  558. if (!exports.is(esValue)) {
  559. throw new globalObject.TypeError("'get textContent' called on an object that is not a valid instance of Node.");
  560. }
  561. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  562. try {
  563. return esValue[implSymbol]["textContent"];
  564. } finally {
  565. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  566. }
  567. }
  568. set textContent(V) {
  569. const esValue = this !== null && this !== undefined ? this : globalObject;
  570. if (!exports.is(esValue)) {
  571. throw new globalObject.TypeError("'set textContent' called on an object that is not a valid instance of Node.");
  572. }
  573. if (V === null || V === undefined) {
  574. V = null;
  575. } else {
  576. V = conversions["DOMString"](V, {
  577. context: "Failed to set the 'textContent' property on 'Node': The provided value",
  578. globals: globalObject
  579. });
  580. }
  581. ceReactionsPreSteps_jsdom_living_helpers_custom_elements(globalObject);
  582. try {
  583. esValue[implSymbol]["textContent"] = V;
  584. } finally {
  585. ceReactionsPostSteps_jsdom_living_helpers_custom_elements(globalObject);
  586. }
  587. }
  588. }
  589. Object.defineProperties(Node.prototype, {
  590. getRootNode: { enumerable: true },
  591. hasChildNodes: { enumerable: true },
  592. normalize: { enumerable: true },
  593. cloneNode: { enumerable: true },
  594. isEqualNode: { enumerable: true },
  595. isSameNode: { enumerable: true },
  596. compareDocumentPosition: { enumerable: true },
  597. contains: { enumerable: true },
  598. lookupPrefix: { enumerable: true },
  599. lookupNamespaceURI: { enumerable: true },
  600. isDefaultNamespace: { enumerable: true },
  601. insertBefore: { enumerable: true },
  602. appendChild: { enumerable: true },
  603. replaceChild: { enumerable: true },
  604. removeChild: { enumerable: true },
  605. nodeType: { enumerable: true },
  606. nodeName: { enumerable: true },
  607. baseURI: { enumerable: true },
  608. isConnected: { enumerable: true },
  609. ownerDocument: { enumerable: true },
  610. parentNode: { enumerable: true },
  611. parentElement: { enumerable: true },
  612. childNodes: { enumerable: true },
  613. firstChild: { enumerable: true },
  614. lastChild: { enumerable: true },
  615. previousSibling: { enumerable: true },
  616. nextSibling: { enumerable: true },
  617. nodeValue: { enumerable: true },
  618. textContent: { enumerable: true },
  619. [Symbol.toStringTag]: { value: "Node", configurable: true },
  620. ELEMENT_NODE: { value: 1, enumerable: true },
  621. ATTRIBUTE_NODE: { value: 2, enumerable: true },
  622. TEXT_NODE: { value: 3, enumerable: true },
  623. CDATA_SECTION_NODE: { value: 4, enumerable: true },
  624. ENTITY_REFERENCE_NODE: { value: 5, enumerable: true },
  625. ENTITY_NODE: { value: 6, enumerable: true },
  626. PROCESSING_INSTRUCTION_NODE: { value: 7, enumerable: true },
  627. COMMENT_NODE: { value: 8, enumerable: true },
  628. DOCUMENT_NODE: { value: 9, enumerable: true },
  629. DOCUMENT_TYPE_NODE: { value: 10, enumerable: true },
  630. DOCUMENT_FRAGMENT_NODE: { value: 11, enumerable: true },
  631. NOTATION_NODE: { value: 12, enumerable: true },
  632. DOCUMENT_POSITION_DISCONNECTED: { value: 0x01, enumerable: true },
  633. DOCUMENT_POSITION_PRECEDING: { value: 0x02, enumerable: true },
  634. DOCUMENT_POSITION_FOLLOWING: { value: 0x04, enumerable: true },
  635. DOCUMENT_POSITION_CONTAINS: { value: 0x08, enumerable: true },
  636. DOCUMENT_POSITION_CONTAINED_BY: { value: 0x10, enumerable: true },
  637. DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: { value: 0x20, enumerable: true }
  638. });
  639. Object.defineProperties(Node, {
  640. ELEMENT_NODE: { value: 1, enumerable: true },
  641. ATTRIBUTE_NODE: { value: 2, enumerable: true },
  642. TEXT_NODE: { value: 3, enumerable: true },
  643. CDATA_SECTION_NODE: { value: 4, enumerable: true },
  644. ENTITY_REFERENCE_NODE: { value: 5, enumerable: true },
  645. ENTITY_NODE: { value: 6, enumerable: true },
  646. PROCESSING_INSTRUCTION_NODE: { value: 7, enumerable: true },
  647. COMMENT_NODE: { value: 8, enumerable: true },
  648. DOCUMENT_NODE: { value: 9, enumerable: true },
  649. DOCUMENT_TYPE_NODE: { value: 10, enumerable: true },
  650. DOCUMENT_FRAGMENT_NODE: { value: 11, enumerable: true },
  651. NOTATION_NODE: { value: 12, enumerable: true },
  652. DOCUMENT_POSITION_DISCONNECTED: { value: 0x01, enumerable: true },
  653. DOCUMENT_POSITION_PRECEDING: { value: 0x02, enumerable: true },
  654. DOCUMENT_POSITION_FOLLOWING: { value: 0x04, enumerable: true },
  655. DOCUMENT_POSITION_CONTAINS: { value: 0x08, enumerable: true },
  656. DOCUMENT_POSITION_CONTAINED_BY: { value: 0x10, enumerable: true },
  657. DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: { value: 0x20, enumerable: true }
  658. });
  659. ctorRegistry[interfaceName] = Node;
  660. Object.defineProperty(globalObject, interfaceName, {
  661. configurable: true,
  662. writable: true,
  663. value: Node
  664. });
  665. };
  666. const Impl = require("../../jsdom/living/nodes/Node-impl.js");