com.gargoylesoftware.htmlunit.javascript.host.html
Class HTMLOptionsCollection

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.html.HTMLOptionsCollection
All Implemented Interfaces:
ScriptableWithFallbackGetter, Serializable, Cloneable, Map, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable

public class HTMLOptionsCollection
extends SimpleScriptable
implements ScriptableWithFallbackGetter

This is the array returned by the "options" property of Select.

Version:
$Revision: 5864 $
Author:
David K. Taylor, Christian Sell, Marc Guillemot, Daniel Gredler, Bruce Faulkner, Ahmed Ashour
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
HTMLOptionsCollection()
          Creates an instance.
HTMLOptionsCollection(SimpleScriptable parentScope)
          Creates an instance.
 
Method Summary
 Object get(int index, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          Returns the object at the specified index.
 Object getWithFallback(String name)
          This method delegates the call to the parent select element.
 void initialize(HtmlSelect select)
          Initializes this object.
 void jsxFunction_add(Object newOptionObject, Object newIndex)
          Adds a new item to the option collection.
 Object jsxFunction_item(int index)
          Returns the object at the specified index.
 int jsxGet_length()
          Returns the number of elements in this array.
 void jsxSet_length(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.
 void put(int index, net.sourceforge.htmlunit.corejs.javascript.Scriptable start, Object newValue)
          Sets the index property.
 void put(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start, Object value)
          If IE is emulated, and this class does not have the specified property, and the owning select *does* have the specified property, this method delegates the call to the parent select element.
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, clear, containsKey, containsValue, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, entrySet, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, keySet, preventExtensions, put, putAll, putConst, putConstProperty, putProperty, putProperty, redefineProperty, remove, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype, size, values
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
delete, delete, get, getClassName, getDefaultValue, getIds, getParentScope, getPrototype, has, has, hasInstance, setParentScope, setPrototype
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

HTMLOptionsCollection

public HTMLOptionsCollection()
Creates an instance. JavaScript objects must have a default constructor.


HTMLOptionsCollection

public HTMLOptionsCollection(SimpleScriptable parentScope)
Creates an instance.

Parameters:
parentScope - parent scope
Method Detail

initialize

public void initialize(HtmlSelect select)
Initializes this object.

Parameters:
select - the HtmlSelect that this object will retrieve elements from

get

public Object get(int index,
                  net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
Returns the object at the specified index.

Specified by:
get in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
get in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
Parameters:
index - the index
start - the object that get is being called on
Returns:
the object or NOT_FOUND

put

public void put(String name,
                net.sourceforge.htmlunit.corejs.javascript.Scriptable start,
                Object value)

If IE is emulated, and this class does not have the specified property, and the owning select *does* have the specified property, this method delegates the call to the parent select element.

See getWithFallback(String) for the corresponding getter behavior.

Specified by:
put in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
put in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
Parameters:
name -
start -
value -

getWithFallback

public Object getWithFallback(String name)

This method delegates the call to the parent select element.

See put(String, Scriptable, Object) for the corresponding setter behavior.

Specified by:
getWithFallback in interface ScriptableWithFallbackGetter
Parameters:
name - the name of the requested property
Returns:
the object value, Scriptable.NOT_FOUND if nothing is found

jsxFunction_item

public Object jsxFunction_item(int index)
Returns the object at the specified index.

Parameters:
index - the index
Returns:
the object or NOT_FOUND

put

public void put(int index,
                net.sourceforge.htmlunit.corejs.javascript.Scriptable start,
                Object newValue)
Sets the index property.

Specified by:
put in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
put in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
Parameters:
index - the index
start - the scriptable object that was originally invoked for this property
newValue - the new value

jsxGet_length

public int jsxGet_length()
Returns the number of elements in this array.

Returns:
the number of elements in the array

jsxSet_length

public void jsxSet_length(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

jsxFunction_add

public void jsxFunction_add(Object newOptionObject,
                            Object newIndex)
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 net.sourceforge.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.

According to the Microsoft DHTML reference page 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 collection
newIndex - 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:
put(int, Scriptable, Object)


Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.