- All Implemented Interfaces:
Serializable,Cloneable,org.htmlunit.corejs.javascript.ConstProperties<org.htmlunit.corejs.javascript.Scriptable>,org.htmlunit.corejs.javascript.debug.DebuggableObject,org.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>,org.htmlunit.corejs.javascript.Scriptable,org.htmlunit.corejs.javascript.SymbolScriptable
- Author:
- David K. Taylor, Christian Sell, Marc Guillemot, Daniel Gredler, Bruce Faulkner, Ahmed Ashour, Ronald Brill
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.corejs.javascript.ScriptableObject.DescriptorInfo, org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator, org.htmlunit.corejs.javascript.ScriptableObject.LambdaGetterFunction, org.htmlunit.corejs.javascript.ScriptableObject.LambdaSetterFunction -
Field Summary
Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, LEGACY_CONST, PERMANENT, READONLY, STRICTLY_READONLY, UNINITIALIZED_CONSTFields inherited from class org.htmlunit.corejs.javascript.SlotMapOwner
isSealedFields inherited from interface org.htmlunit.corejs.javascript.Scriptable
NOT_FOUND -
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance.HTMLOptionsCollection(org.htmlunit.corejs.javascript.VarScope parentScope) Creates an instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new item to the option collection.get(int index, org.htmlunit.corejs.javascript.Scriptable start) Returns the object at the specified index.Overridden to support the named properties (the ids and names of the options).protected Object[]getIds(org.htmlunit.corejs.javascript.CompoundOperationMap<org.htmlunit.corejs.javascript.Scriptable> map, boolean getNonEnumerable, boolean getSymbols) Overridden to list the named properties (the ids and names of the options) after the indexed properties.protected intReturns the number of indexed properties (0tocount - 1) this object exposes as own properties.intReturns the number of elements in this array.protected org.htmlunit.corejs.javascript.ScriptableObject.DescriptorInfogetOwnPropertyDescriptor(org.htmlunit.corejs.javascript.Context cx, Object id) Overridden to provide property descriptors for the named properties.intReturns the value of theselectedIndexproperty.booleanOverridden to support the named properties (the ids and names of the options).voidinitialize(HtmlSelect select) Initializes this object.protected booleanReturns whether the indexed own properties are writable (the object has an indexed setter).item(int index) Returns the object at the specified index.org.htmlunit.corejs.javascript.Scriptableiterator()Returns theSymbol.iteratorfunction that allows iterating over this collection.voidJavaScript constructor.voidSets the index property.voidvoidremove(int index) Removes the option at the specified index.voidsetLength(int newLength) Changes the number of options: removes options if the new length is less than the current one else add new empty options to reach the new length.voidsetSelectedIndex(int index) Sets the value of theselectedIndexproperty.Methods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, createDOMException, equivalentValues, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getWindow, getWindow, getWindowOrWorkerGlobalScope, getWithPreemption, has, hasInstance, makeScriptableFor, setClassName, setDomNode, setDomNode, setupPromise, setupRejectedPromiseMethods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkNotSealed, checkPropertyChangeForSlot, checkPropertyChangeForSlot, checkPropertyDefinition, checkPropertyDefinition, checkSlotRemoval, defineBuiltinProperty, defineBuiltinProperty, defineBuiltInProperty, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureScriptableObjectButNotSymbol, ensureSymbolScriptable, ensureType, get, getAllIds, getAncestor, getArrayPrototype, getClassPrototype, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getObjectPrototype, getParentScope, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSuperProperty, getSuperProperty, getSuperProperty, getThis, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, hasProperty, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGenericDescriptor, isGetterOrSetter, isGetterOrSetter, isTrue, preventExtensions, put, putConst, putConstProperty, putConstProperty, putOwnProperty, putOwnProperty, putOwnProperty, putProperty, putProperty, putProperty, putProperty, putSuperProperty, putSuperProperty, putSuperProperty, querySlot, redefineProperty, redefineProperty, sameValue, sealObject, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, sizeMethods inherited from class org.htmlunit.corejs.javascript.SlotMapOwner
associateValue, checkNotSealed, copyAssociatedValue, createSlotMap, createSlotMap, defineProperty, defineProperty, get, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getIds, has, isSealed, readMaps, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, writeMapsMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.htmlunit.corejs.javascript.Scriptable
get, getIds, hasMethods inherited from interface org.htmlunit.corejs.javascript.SymbolScriptable
get, has
-
Constructor Details
-
HTMLOptionsCollection
public HTMLOptionsCollection()Creates an instance. -
HTMLOptionsCollection
public HTMLOptionsCollection(org.htmlunit.corejs.javascript.VarScope parentScope) Creates an instance.- Parameters:
parentScope- parent scope
-
-
Method Details
-
jsConstructor
public void jsConstructor()JavaScript constructor. -
initialize
Initializes this object.- Parameters:
select- the HtmlSelect that this object will retrieve elements from
-
getIndexedPropertyCount
protected int getIndexedPropertyCount()Returns the number of indexed properties (0tocount - 1) this object exposes as own properties. Host objects supporting indexed properties (e.g. DOMTokenList) override this; the indexed properties are then listed by Object.keys(), Object.getOwnPropertyNames(), for...in and have a property descriptor. The default implementation returns0.- Overrides:
getIndexedPropertyCountin classHtmlUnitScriptable- Returns:
- the number of indexed own properties
-
isIndexedPropertyWritable
protected boolean isIndexedPropertyWritable()Returns whether the indexed own properties are writable (the object has an indexed setter). The default implementation returnsfalse.- Overrides:
isIndexedPropertyWritablein classHtmlUnitScriptable- Returns:
- true if the indexed properties are writable
-
get
Overridden to support the named properties (the ids and names of the options). Gets a named property from the object. Normally HtmlUnit objects don't need to overwrite this method as properties are defined on the prototypes. In some cases where "content" of object has priority compared to the properties consider using utilityHtmlUnitScriptable.getWithPreemption(String).- Specified by:
getin interfaceorg.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>- Specified by:
getin interfaceorg.htmlunit.corejs.javascript.Scriptable- Overrides:
getin classHtmlUnitScriptable
-
has
Overridden to support the named properties (the ids and names of the options).- Specified by:
hasin interfaceorg.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>- Specified by:
hasin interfaceorg.htmlunit.corejs.javascript.Scriptable- Overrides:
hasin classorg.htmlunit.corejs.javascript.ScriptableObject
-
getIds
protected Object[] getIds(org.htmlunit.corejs.javascript.CompoundOperationMap<org.htmlunit.corejs.javascript.Scriptable> map, boolean getNonEnumerable, boolean getSymbols) Overridden to list the named properties (the ids and names of the options) after the indexed properties. Overridden to list the indexed properties (seeHtmlUnitScriptable.getIndexedPropertyCount()) in front of the other own properties.- Overrides:
getIdsin classHtmlUnitScriptable
-
getOwnPropertyDescriptor
protected org.htmlunit.corejs.javascript.ScriptableObject.DescriptorInfo getOwnPropertyDescriptor(org.htmlunit.corejs.javascript.Context cx, Object id) Overridden to provide property descriptors for the named properties. Overridden to provide property descriptors for the indexed properties (seeHtmlUnitScriptable.getIndexedPropertyCount()).- Overrides:
getOwnPropertyDescriptorin classHtmlUnitScriptable
-
get
Returns the object at the specified index.- Specified by:
getin interfaceorg.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>- Specified by:
getin interfaceorg.htmlunit.corejs.javascript.Scriptable- Overrides:
getin classorg.htmlunit.corejs.javascript.ScriptableObject- Parameters:
index- the indexstart- the object that get is being called on- Returns:
- the object or NOT_FOUND
-
put
- Specified by:
putin interfaceorg.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>- Specified by:
putin interfaceorg.htmlunit.corejs.javascript.Scriptable- Overrides:
putin classHtmlUnitScriptable
-
item
Returns the object at the specified index.- Parameters:
index- the index- Returns:
- the object or NOT_FOUND
-
put
Sets the index property.- Specified by:
putin interfaceorg.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>- Specified by:
putin interfaceorg.htmlunit.corejs.javascript.Scriptable- Overrides:
putin classorg.htmlunit.corejs.javascript.ScriptableObject- Parameters:
index- the indexstart- the scriptable object that was originally invoked for this propertynewValue- the new value
-
getLength
public int getLength()Returns the number of elements in this array.- Returns:
- the number of elements in the array
-
setLength
public void setLength(int newLength) Changes the number of options: removes options if the new length is less than the current one else add new empty options to reach the new length.- Parameters:
newLength- the new length property value
-
add
Adds a new item to the option collection.Implementation Note: The specification for the JavaScript add() method actually calls for the optional newIndex parameter to be an integer. However, the newIndex parameter is specified as an Object here rather than an int because of the way Rhino and HtmlUnit process optional parameters for the JavaScript method calls. If the newIndex parameter were specified as an int, then the Undefined value for an integer is specified as NaN (Not A Number, which is a Double value), but Rhino translates this value into 0 (perhaps correctly?) when converting NaN into an int. As a result, when the newIndex parameter is not specified, it is impossible to make a distinction between a caller of the form add(someObject) and add (someObject, 0). Since the behavior of these two call forms is different, the newIndex parameter is specified as an Object. If the newIndex parameter is not specified by the actual JavaScript code being run, then newIndex is of type org.htmlunit.corejs.javascript.Undefined. If the newIndex parameter is specified, then it should be of type java.lang.Number and can be converted into an integer value.
This method will call the
put(int, Scriptable, Object)method for actually adding the element to the collection.Per the MDN documentation for the JavaScript add() method of the options collection, the index parameter is specified as follows:
Optional. Integer that specifies the index position in the collection where the element is placed. If no value is given, the method places the element at the end of the collection.
- Parameters:
newOptionObject- the DomNode to insert in the collectionbeforeOptionObject- An optional parameter which specifies the index position in the collection where the element is placed. If no value is given, the method places the element at the end of the collection.- See Also:
-
remove
public void remove(int index) Removes the option at the specified index.- Parameters:
index- the option index
-
getSelectedIndex
public int getSelectedIndex()Returns the value of theselectedIndexproperty.- Returns:
- the
selectedIndexproperty
-
setSelectedIndex
public void setSelectedIndex(int index) Sets the value of theselectedIndexproperty.- Parameters:
index- the new value
-
iterator
public org.htmlunit.corejs.javascript.Scriptable iterator()Returns theSymbol.iteratorfunction that allows iterating over this collection.- Returns:
- the Iterator symbol
-