Class AbstractList

java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.dom.AbstractList
All Implemented Interfaces:
Serializable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.ExternalArrayData, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable
Direct Known Subclasses:
HTMLCollection, NodeList

public class AbstractList extends HtmlUnitScriptable implements org.htmlunit.corejs.javascript.ExternalArrayData
The parent class of NodeList and HTMLCollection.
See Also:
  • Field Details

    • avoidObjectDetection_

      private boolean avoidObjectDetection_
    • attributeChangeSensitive_

      private boolean attributeChangeSensitive_
    • cachedElements_

      private List<DomNode> cachedElements_
      Cache collection elements when possible, so as to avoid expensive XPath expression evaluations.
    • listenerRegistered_

      private boolean listenerRegistered_
    • effectOnCacheFunction_

    • isMatchingPredicate_

      private Predicate<DomNode> isMatchingPredicate_
    • elementsSupplier_

      private Supplier<List<DomNode>> elementsSupplier_
  • Constructor Details

    • AbstractList

      public AbstractList()
      Creates an instance.
    • AbstractList

      protected AbstractList(DomNode domNode, boolean attributeChangeSensitive, List<DomNode> initialElements)
      Creates an instance.
      Parameters:
      domNode - the DomNode
      attributeChangeSensitive - indicates if the content of the collection may change when an attribute of a descendant node of parentScope changes (attribute added, modified or removed)
      initialElements - the initial content for the cache
  • Method Details

    • avoidObjectDetection

      public boolean avoidObjectDetection()
      Only needed to make collections like document.all available but "invisible" when simulating Firefox.
      Overrides:
      avoidObjectDetection in class org.htmlunit.corejs.javascript.ScriptableObject
    • setAvoidObjectDetection

      public void setAvoidObjectDetection(boolean newValue)
      Parameters:
      newValue - the new value
    • setEffectOnCacheFunction

      public void setEffectOnCacheFunction(Function<HtmlAttributeChangeEvent,AbstractList.EffectOnCache> effectOnCacheFunction)
      Parameters:
      effectOnCacheFunction - the new function
    • getElementSupplier

      protected Supplier<List<DomNode>> getElementSupplier()
      Returns:
      elementSupplier
    • setElementsSupplier

      public void setElementsSupplier(Supplier<List<DomNode>> elementsSupplier)
      Returns the elements whose associated host objects are available through this collection.
      Parameters:
      elementsSupplier - the new supplier
    • getIsMatchingPredicate

      protected Predicate<DomNode> getIsMatchingPredicate()
      Returns:
      isMatchingPredicate
    • setIsMatchingPredicate

      public void setIsMatchingPredicate(Predicate<DomNode> isMatchingPredicate)
      Indicates if the node should belong to the collection.
      Parameters:
      isMatchingPredicate - the new predicate
    • getIt

      protected Object getIt(Object o)
      Private helper that retrieves the item or items corresponding to the specified index or key.
      Parameters:
      o - the index or key corresponding to the element or elements to return
      Returns:
      the element or elements corresponding to the specified index or key
    • setDomNode

      public void setDomNode(DomNode domNode, boolean assignScriptObject)
      Description copied from class: HtmlUnitScriptable
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Sets the DOM node that corresponds to this JavaScript object.
      Overrides:
      setDomNode in class HtmlUnitScriptable
      Parameters:
      domNode - the DOM node
      assignScriptObject - If true, call setScriptObject on domNode
    • getElements

      public List<DomNode> getElements()
      Gets the HTML elements from cache or retrieve them at first call.
      Returns:
      the list of HtmlElement contained in this collection
    • registerListener

      private void registerListener()
    • getWithPreemption

      protected Object getWithPreemption(String name)
      Returns the element or elements that match the specified key. If it is the name of a property, the property value is returned. If it is the id of an element in the array, that element is returned. Finally, if it is the name of an element or elements in the array, then all those elements are returned. Otherwise, Scriptable.NOT_FOUND is returned.

      Called by HtmlUnitScriptable.get(String, Scriptable) to allow retrieval of the property before the prototype chain is searched.

      IMPORTANT: This method is invoked *very* often by Rhino. If you override this method, the implementation needs to be as fast as possible!

      Overrides:
      getWithPreemption in class HtmlUnitScriptable
      Parameters:
      name - the property name
      Returns:
      Scriptable.NOT_FOUND if not found
    • create

      protected AbstractList create(DomNode parentScope, List<DomNode> initialElements)
      Constructs a new instance with an initial cache value.
      Parameters:
      parentScope - the parent scope, on which we listen for changes
      initialElements - the initial content for the cache
      Returns:
      the newly created instance
    • getWithPreemptionByName

      protected Object getWithPreemptionByName(String name, List<DomNode> elements)
      Helper for getWithPreemption(String) when finding by id doesn't get results.
      Parameters:
      name - the property name
      elements - the children elements.
      Returns:
      Scriptable.NOT_FOUND if not found
    • getLength

      public int getLength()
      Returns the length.
      Returns:
      the length
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equivalentValues

      protected Object equivalentValues(Object other)
      Called for the js "==".
      Overrides:
      equivalentValues in class HtmlUnitScriptable
    • getScriptableForElement

      protected org.htmlunit.corejs.javascript.Scriptable getScriptableForElement(Object object)
      Gets the scriptable for the provided element that may already be the right scriptable.
      Parameters:
      object - the object for which to get the scriptable
      Returns:
      the scriptable
    • defineProperty

      public void defineProperty(String propertyName, Object delegateTo, Method getter, Method setter, int attributes)
      Overrides:
      defineProperty in class org.htmlunit.corejs.javascript.ScriptableObject
    • getArrayElement

      public Object getArrayElement(int index)
      Specified by:
      getArrayElement in interface org.htmlunit.corejs.javascript.ExternalArrayData
    • setArrayElement

      public void setArrayElement(int index, Object value)
      Specified by:
      setArrayElement in interface org.htmlunit.corejs.javascript.ExternalArrayData
    • getArrayLength

      public int getArrayLength()
      Specified by:
      getArrayLength in interface org.htmlunit.corejs.javascript.ExternalArrayData