org.mozilla.javascript
Class NativeArray

java.lang.Object
  extended by org.mozilla.javascript.ScriptableObject
      extended by org.mozilla.javascript.IdScriptableObject
          extended by org.mozilla.javascript.NativeArray
All Implemented Interfaces:
Serializable, Iterable, Collection, List, ConstProperties, DebuggableObject, IdFunctionCall, Scriptable

public class NativeArray
extends IdScriptableObject
implements List

This class implements the Array native object.

Author:
Norris Boyd, Mike McCabe
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.mozilla.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
NativeArray(long lengthArg)
           
NativeArray(Object[] array)
           
 
Method Summary
 void add(int index, Object element)
           
 boolean add(Object o)
           
 boolean addAll(Collection c)
           
 boolean addAll(int index, Collection c)
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 void defineOwnProperty(Context cx, Object id, ScriptableObject desc)
          Defines a property on an object Based on [[DefineOwnProperty]] from 8.12.10 of the spec
 void delete(int index)
          Removes the indexed property from the object.
 Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
          'thisObj' will be null if invoked as constructor, in which case instance of Scriptable should be returned.
protected  void fillConstructorProperties(IdFunctionObject ctor)
           
protected  int findInstanceIdInfo(String s)
          Map name to id of instance property.
protected  int findPrototypeId(String s)
           
 Object get(int index)
           
 Object get(int index, Scriptable start)
          Returns the value of the indexed property or NOT_FOUND.
 Object get(long index)
           
 Object[] getAllIds()
          Returns an array of ids for the properties of the object.
 String getClassName()
          Return the name of the class.
 Object getDefaultValue(Class<?> hint)
          Implements the [[DefaultValue]] internal method.
 Object[] getIds()
          Returns an array of ids for the properties of the object.
 Integer[] getIndexIds()
           
protected  String getInstanceIdName(int id)
          Map id back to property name it defines.
protected  Object getInstanceIdValue(int id)
          Get id value.
 long getLength()
           
protected  int getMaxInstanceId()
          Get maximum id findInstanceIdInfo can generate.
protected  ScriptableObject getOwnPropertyDescriptor(Context cx, Object id)
           
 boolean has(int index, Scriptable start)
          Returns true if the property index is defined.
 int indexOf(Object o)
           
protected  void initPrototypeId(int id)
           
 Iterator iterator()
           
 long jsGet_length()
          Deprecated. Use getLength() instead.
 int lastIndexOf(Object o)
           
 ListIterator listIterator()
           
 ListIterator listIterator(int start)
           
 void put(int index, Scriptable start, Object value)
          Sets the value of the indexed property, creating it if need be.
 void put(String id, Scriptable start, Object value)
          Sets the value of the named property, creating it if need be.
 Object remove(int index)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection c)
           
 boolean retainAll(Collection c)
           
 Object set(int index, Object element)
           
protected  void setInstanceIdValue(int id, Object value)
          Set or delete id value.
 int size()
           
 List subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 
Methods inherited from class org.mozilla.javascript.IdScriptableObject
activatePrototypeMap, addIdFunctionProperty, defaultGet, defaultPut, delete, exportAsJSClass, get, getAttributes, has, hasPrototypeMap, incompatibleCallError, initPrototypeConstructor, initPrototypeMethod, initPrototypeValue, instanceIdInfo, setAttributes
 
Methods inherited from class org.mozilla.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineProperty, defineProperty, defineProperty, defineProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, equivalentValues, get, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, hasInstance, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sealObject, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode, isEmpty
 

Constructor Detail

NativeArray

public NativeArray(long lengthArg)

NativeArray

public NativeArray(Object[] array)
Method Detail

getClassName

public String getClassName()
Description copied from class: ScriptableObject
Return the name of the class. This is typically the same name as the constructor. Classes extending ScriptableObject must implement this abstract method.

Specified by:
getClassName in interface Scriptable
Specified by:
getClassName in class ScriptableObject

getMaxInstanceId

protected int getMaxInstanceId()
Description copied from class: IdScriptableObject
Get maximum id findInstanceIdInfo can generate.

Overrides:
getMaxInstanceId in class IdScriptableObject

findInstanceIdInfo

protected int findInstanceIdInfo(String s)
Description copied from class: IdScriptableObject
Map name to id of instance property. Should return 0 if not found or the result of IdScriptableObject.instanceIdInfo(int, int).

Overrides:
findInstanceIdInfo in class IdScriptableObject

getInstanceIdName

protected String getInstanceIdName(int id)
Description copied from class: IdScriptableObject
Map id back to property name it defines.

Overrides:
getInstanceIdName in class IdScriptableObject

getInstanceIdValue

protected Object getInstanceIdValue(int id)
Description copied from class: IdScriptableObject
Get id value. If id value is constant, descendant can call cacheIdValue to store value in the permanent cache. Default implementation creates IdFunctionObject instance for given id and cache its value

Overrides:
getInstanceIdValue in class IdScriptableObject

setInstanceIdValue

protected void setInstanceIdValue(int id,
                                  Object value)
Description copied from class: IdScriptableObject
Set or delete id value. If value == NOT_FOUND , the implementation should make sure that the following getInstanceIdValue return NOT_FOUND.

Overrides:
setInstanceIdValue in class IdScriptableObject

fillConstructorProperties

protected void fillConstructorProperties(IdFunctionObject ctor)
Overrides:
fillConstructorProperties in class IdScriptableObject

initPrototypeId

protected void initPrototypeId(int id)
Overrides:
initPrototypeId in class IdScriptableObject

execIdCall

public Object execIdCall(IdFunctionObject f,
                         Context cx,
                         Scriptable scope,
                         Scriptable thisObj,
                         Object[] args)
Description copied from class: IdScriptableObject
'thisObj' will be null if invoked as constructor, in which case instance of Scriptable should be returned.

Specified by:
execIdCall in interface IdFunctionCall
Overrides:
execIdCall in class IdScriptableObject

get

public Object get(int index,
                  Scriptable start)
Description copied from class: ScriptableObject
Returns the value of the indexed property or NOT_FOUND.

Specified by:
get in interface Scriptable
Overrides:
get in class ScriptableObject
Parameters:
index - the numeric index for the property
start - the object in which the lookup began
Returns:
the value of the property (may be null), or NOT_FOUND
See Also:
Scriptable.get(String,Scriptable)

has

public boolean has(int index,
                   Scriptable start)
Description copied from class: ScriptableObject
Returns true if the property index is defined.

Specified by:
has in interface Scriptable
Overrides:
has in class ScriptableObject
Parameters:
index - the numeric index for the property
start - the object in which the lookup began
Returns:
true if and only if the property was found in the object
See Also:
Scriptable.get(int, Scriptable), ScriptableObject.getProperty(Scriptable, int)

put

public void put(String id,
                Scriptable start,
                Object value)
Description copied from class: ScriptableObject
Sets the value of the named property, creating it if need be. If the property was created using defineProperty, the appropriate setter method is called.

If the property's attributes include READONLY, no action is taken. This method will actually set the property in the start object.

Specified by:
put in interface Scriptable
Overrides:
put in class IdScriptableObject
Parameters:
id - the name of the property
start - the object whose property is being set
value - value to set the property to
See Also:
Scriptable.has(String, Scriptable), Scriptable.get(String, Scriptable), ScriptableObject.putProperty(Scriptable, String, Object), Context.toObject(Object, Scriptable)

put

public void put(int index,
                Scriptable start,
                Object value)
Description copied from class: ScriptableObject
Sets the value of the indexed property, creating it if need be.

Specified by:
put in interface Scriptable
Overrides:
put in class ScriptableObject
Parameters:
index - the numeric index for the property
start - the object whose property is being set
value - value to set the property to
See Also:
Scriptable.has(int, Scriptable), Scriptable.get(int, Scriptable), ScriptableObject.putProperty(Scriptable, int, Object), Context.toObject(Object, Scriptable)

delete

public void delete(int index)
Description copied from class: ScriptableObject
Removes the indexed property from the object. If the property is not found, or it has the PERMANENT attribute, no action is taken.

Specified by:
delete in interface Scriptable
Overrides:
delete in class ScriptableObject
Parameters:
index - the numeric index for the property
See Also:
Scriptable.get(int, Scriptable), ScriptableObject.deleteProperty(Scriptable, int)

getIds

public Object[] getIds()
Description copied from class: ScriptableObject
Returns an array of ids for the properties of the object.

Any properties with the attribute DONTENUM are not listed.

Specified by:
getIds in interface Scriptable
Overrides:
getIds in class ScriptableObject
Returns:
an array of java.lang.Objects with an entry for every listed property. Properties accessed via an integer index will have a corresponding Integer entry in the returned array. Properties accessed by a String will have a String entry in the returned array.

getAllIds

public Object[] getAllIds()
Description copied from class: ScriptableObject
Returns an array of ids for the properties of the object.

All properties, even those with attribute DONTENUM, are listed.

Specified by:
getAllIds in interface DebuggableObject
Overrides:
getAllIds in class ScriptableObject
Returns:
an array of java.lang.Objects with an entry for every listed property. Properties accessed via an integer index will have a corresponding Integer entry in the returned array. Properties accessed by a String will have a String entry in the returned array.

getIndexIds

public Integer[] getIndexIds()

getDefaultValue

public Object getDefaultValue(Class<?> hint)
Description copied from class: ScriptableObject
Implements the [[DefaultValue]] internal method.

Note that the toPrimitive conversion is a no-op for every type other than Object, for which [[DefaultValue]] is called. See ECMA 9.1.

A hint of null means "no hint".

Specified by:
getDefaultValue in interface Scriptable
Overrides:
getDefaultValue in class ScriptableObject
Parameters:
hint - the type hint
Returns:
the default value for the object See ECMA 8.6.2.6.

getOwnPropertyDescriptor

protected ScriptableObject getOwnPropertyDescriptor(Context cx,
                                                    Object id)
Overrides:
getOwnPropertyDescriptor in class IdScriptableObject

defineOwnProperty

public void defineOwnProperty(Context cx,
                              Object id,
                              ScriptableObject desc)
Description copied from class: ScriptableObject
Defines a property on an object Based on [[DefineOwnProperty]] from 8.12.10 of the spec

Overrides:
defineOwnProperty in class IdScriptableObject
Parameters:
cx - the current Context
id - the name/index of the property
desc - the new property descriptor, as described in 8.6.1

getLength

public long getLength()

jsGet_length

public long jsGet_length()
Deprecated. Use getLength() instead.


contains

public boolean contains(Object o)
Specified by:
contains in interface Collection
Specified by:
contains in interface List

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection
Specified by:
containsAll in interface List

size

public int size()
Specified by:
size in interface Collection
Specified by:
size in interface List
Overrides:
size in class ScriptableObject

get

public Object get(long index)

get

public Object get(int index)
Specified by:
get in interface List

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface List

listIterator

public ListIterator listIterator()
Specified by:
listIterator in interface List

listIterator

public ListIterator listIterator(int start)
Specified by:
listIterator in interface List

add

public boolean add(Object o)
Specified by:
add in interface Collection
Specified by:
add in interface List

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection
Specified by:
remove in interface List

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface Collection
Specified by:
addAll in interface List

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface List

retainAll

public boolean retainAll(Collection c)
Specified by:
retainAll in interface Collection
Specified by:
retainAll in interface List

clear

public void clear()
Specified by:
clear in interface Collection
Specified by:
clear in interface List

add

public void add(int index,
                Object element)
Specified by:
add in interface List

addAll

public boolean addAll(int index,
                      Collection c)
Specified by:
addAll in interface List

set

public Object set(int index,
                  Object element)
Specified by:
set in interface List

remove

public Object remove(int index)
Specified by:
remove in interface List

subList

public List subList(int fromIndex,
                    int toIndex)
Specified by:
subList in interface List

findPrototypeId

protected int findPrototypeId(String s)
Overrides:
findPrototypeId in class IdScriptableObject