Package org.htmlunit.javascript.host.dom
Class AbstractList
- java.lang.Object
-
- org.htmlunit.corejs.javascript.ScriptableObject
-
- org.htmlunit.javascript.HtmlUnitScriptable
-
- org.htmlunit.javascript.host.dom.AbstractList
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.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 ofNodeList
andHTMLCollection
.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AbstractList.DomHtmlAttributeChangeListenerImpl
static class
AbstractList.EffectOnCache
Cache effect of some changes.
-
Field Summary
Fields Modifier and Type Field Description private boolean
attributeChangeSensitive_
private boolean
avoidObjectDetection_
private java.util.List<DomNode>
cachedElements_
Cache collection elements when possible, so as to avoid expensive XPath expression evaluations.private java.util.function.Function<HtmlAttributeChangeEvent,AbstractList.EffectOnCache>
effectOnCacheFunction_
private java.util.function.Supplier<java.util.List<DomNode>>
elementsSupplier_
private java.util.function.Predicate<DomNode>
isMatchingPredicate_
private boolean
listenerRegistered_
-
Constructor Summary
Constructors Modifier Constructor Description AbstractList()
Creates an instance.protected
AbstractList(DomNode domNode, boolean attributeChangeSensitive, java.util.List<DomNode> initialElements)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
avoidObjectDetection()
Only needed to make collections likedocument.all
available but "invisible" when simulating Firefox.protected AbstractList
create(DomNode parentScope, java.util.List<DomNode> initialElements)
Constructs a new instance with an initial cache value.void
defineProperty(java.lang.String propertyName, java.lang.Object delegateTo, java.lang.reflect.Method getter, java.lang.reflect.Method setter, int attributes)
protected java.lang.Object
equivalentValues(java.lang.Object other)
Called for the js "==".java.lang.Object
getArrayElement(int index)
int
getArrayLength()
java.util.List<DomNode>
getElements()
Gets the HTML elements from cache or retrieve them at first call.protected java.util.function.Supplier<java.util.List<DomNode>>
getElementSupplier()
protected java.util.function.Predicate<DomNode>
getIsMatchingPredicate()
protected java.lang.Object
getIt(java.lang.Object o)
Private helper that retrieves the item or items corresponding to the specified index or key.int
getLength()
Returns the length.protected org.htmlunit.corejs.javascript.Scriptable
getScriptableForElement(java.lang.Object object)
Gets the scriptable for the provided element that may already be the right scriptable.protected java.lang.Object
getWithPreemption(java.lang.String name)
Returns the element or elements that match the specified key.protected java.lang.Object
getWithPreemptionByName(java.lang.String name, java.util.List<DomNode> elements)
Helper forgetWithPreemption(String)
when finding by id doesn't get results.private void
registerListener()
void
setArrayElement(int index, java.lang.Object value)
void
setAvoidObjectDetection(boolean newValue)
void
setDomNode(DomNode domNode, boolean assignScriptObject)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Sets the DOM node that corresponds to this JavaScript object.void
setEffectOnCacheFunction(java.util.function.Function<HtmlAttributeChangeEvent,AbstractList.EffectOnCache> effectOnCacheFunction)
void
setElementsSupplier(java.util.function.Supplier<java.util.List<DomNode>> elementsSupplier)
Returns the elements whose associated host objects are available through this collection.void
setIsMatchingPredicate(java.util.function.Predicate<DomNode> isMatchingPredicate)
Indicates if the node should belong to the collection.java.lang.String
toString()
-
Methods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setParentScope, setupPromise, setupRejectedPromise
-
Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
-
-
-
Field Detail
-
avoidObjectDetection_
private boolean avoidObjectDetection_
-
attributeChangeSensitive_
private boolean attributeChangeSensitive_
-
cachedElements_
private java.util.List<DomNode> cachedElements_
Cache collection elements when possible, so as to avoid expensive XPath expression evaluations.
-
listenerRegistered_
private boolean listenerRegistered_
-
effectOnCacheFunction_
private java.util.function.Function<HtmlAttributeChangeEvent,AbstractList.EffectOnCache> effectOnCacheFunction_
-
isMatchingPredicate_
private java.util.function.Predicate<DomNode> isMatchingPredicate_
-
elementsSupplier_
private java.util.function.Supplier<java.util.List<DomNode>> elementsSupplier_
-
-
Constructor Detail
-
AbstractList
public AbstractList()
Creates an instance.
-
AbstractList
protected AbstractList(DomNode domNode, boolean attributeChangeSensitive, java.util.List<DomNode> initialElements)
Creates an instance.- Parameters:
domNode
- theDomNode
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 Detail
-
avoidObjectDetection
public boolean avoidObjectDetection()
Only needed to make collections likedocument.all
available but "invisible" when simulating Firefox.- Overrides:
avoidObjectDetection
in classorg.htmlunit.corejs.javascript.ScriptableObject
-
setAvoidObjectDetection
public void setAvoidObjectDetection(boolean newValue)
- Parameters:
newValue
- the new value
-
setEffectOnCacheFunction
public void setEffectOnCacheFunction(java.util.function.Function<HtmlAttributeChangeEvent,AbstractList.EffectOnCache> effectOnCacheFunction)
- Parameters:
effectOnCacheFunction
- the new function
-
getElementSupplier
protected java.util.function.Supplier<java.util.List<DomNode>> getElementSupplier()
- Returns:
- elementSupplier
-
setElementsSupplier
public void setElementsSupplier(java.util.function.Supplier<java.util.List<DomNode>> elementsSupplier)
Returns the elements whose associated host objects are available through this collection.- Parameters:
elementsSupplier
- the new supplier
-
getIsMatchingPredicate
protected java.util.function.Predicate<DomNode> getIsMatchingPredicate()
- Returns:
- isMatchingPredicate
-
setIsMatchingPredicate
public void setIsMatchingPredicate(java.util.function.Predicate<DomNode> isMatchingPredicate)
Indicates if the node should belong to the collection.- Parameters:
isMatchingPredicate
- the new predicate
-
getIt
protected java.lang.Object getIt(java.lang.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 classHtmlUnitScriptable
- Parameters:
domNode
- the DOM nodeassignScriptObject
- If true, callsetScriptObject
on domNode
-
getElements
public java.util.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 java.lang.Object getWithPreemption(java.lang.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 classHtmlUnitScriptable
- Parameters:
name
- the property name- Returns:
Scriptable.NOT_FOUND
if not found
-
create
protected AbstractList create(DomNode parentScope, java.util.List<DomNode> initialElements)
Constructs a new instance with an initial cache value.- Parameters:
parentScope
- the parent scope, on which we listen for changesinitialElements
- the initial content for the cache- Returns:
- the newly created instance
-
getWithPreemptionByName
protected java.lang.Object getWithPreemptionByName(java.lang.String name, java.util.List<DomNode> elements)
Helper forgetWithPreemption(String)
when finding by id doesn't get results.- Parameters:
name
- the property nameelements
- the children elements.- Returns:
Scriptable.NOT_FOUND
if not found
-
getLength
public int getLength()
Returns the length.- Returns:
- the length
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equivalentValues
protected java.lang.Object equivalentValues(java.lang.Object other)
Called for the js "==".- Overrides:
equivalentValues
in classHtmlUnitScriptable
-
getScriptableForElement
protected org.htmlunit.corejs.javascript.Scriptable getScriptableForElement(java.lang.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(java.lang.String propertyName, java.lang.Object delegateTo, java.lang.reflect.Method getter, java.lang.reflect.Method setter, int attributes)
- Overrides:
defineProperty
in classorg.htmlunit.corejs.javascript.ScriptableObject
-
getArrayElement
public java.lang.Object getArrayElement(int index)
- Specified by:
getArrayElement
in interfaceorg.htmlunit.corejs.javascript.ExternalArrayData
-
setArrayElement
public void setArrayElement(int index, java.lang.Object value)
- Specified by:
setArrayElement
in interfaceorg.htmlunit.corejs.javascript.ExternalArrayData
-
getArrayLength
public int getArrayLength()
- Specified by:
getArrayLength
in interfaceorg.htmlunit.corejs.javascript.ExternalArrayData
-
-