HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //proc/1526/task/1530/cwd/zaklada/html/node_modules/jsdom/lib/jsdom/living/node-list.js
"use strict";
const lengthFromProperties = require("../utils").lengthFromProperties;

const privates = Symbol("NodeList internal slots");

class NodeList {
  constructor(secret, config) {
    if (secret !== privates) {
      throw new TypeError("Invalid constructor");
    }

    if (config.nodes) {
      this[privates] = {
        isLive: false,
        length: config.nodes.length
      };

      for (let i = 0; i < config.nodes.length; ++i) {
        this[i] = config.nodes[i];
      }
    } else {
      this[privates] = {
        isLive: true,
        element: config.element,
        query: config.query,
        snapshot: undefined,
        length: 0,
        version: -1
      };
      updateNodeList(this);
    }
  }

  get length() {
    updateNodeList(this);
    return this[privates].length;
  }

  item(index) {
    updateNodeList(this);
    return this[index] || null;
  }
}

NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];

function updateNodeList(nodeList) {
  if (nodeList[privates].isLive) {
    if (nodeList[privates].version < nodeList[privates].element._version) {
      nodeList[privates].snapshot = nodeList[privates].query();
      resetNodeListTo(nodeList, nodeList[privates].snapshot);
      nodeList[privates].version = nodeList[privates].element._version;
    }
  } else {
    nodeList[privates].length = lengthFromProperties(nodeList);
  }
}

function resetNodeListTo(nodeList, nodes) {
  const startingLength = lengthFromProperties(nodeList);
  for (let i = 0; i < startingLength; ++i) {
    delete nodeList[i];
  }

  for (let i = 0; i < nodes.length; ++i) {
    nodeList[i] = nodes[i];
  }
  nodeList[privates].length = nodes.length;
}

module.exports = function (core) {
  core.NodeList = NodeList;
};

module.exports.createLive = function (element, query) {
  return new NodeList(privates, { element, query });
};

module.exports.createStatic = function (nodes) {
  return new NodeList(privates, { nodes });
};

module.exports.update = updateNodeList;