Package org.mozilla.javascript
Class NativeArray
- java.lang.Object
-
- org.mozilla.javascript.ScriptableObject
-
- org.mozilla.javascript.IdScriptableObject
-
- org.mozilla.javascript.NativeArray
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable,java.util.Collection,java.util.List,ConstProperties,DebuggableObject,IdFunctionCall,Scriptable,SymbolScriptable
public class NativeArray extends IdScriptableObject implements java.util.List
This class implements the Array native object.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNativeArray.ElementComparatorstatic classNativeArray.StringLikeComparator-
Nested classes/interfaces inherited from class org.mozilla.javascript.ScriptableObject
ScriptableObject.KeyComparator
-
-
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
Constructors Constructor Description NativeArray(long lengthArg)NativeArray(java.lang.Object[] array)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(int index, java.lang.Object element)booleanadd(java.lang.Object o)booleanaddAll(int index, java.util.Collection c)booleanaddAll(java.util.Collection c)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection c)protected voiddefineOwnProperty(Context cx, java.lang.Object id, ScriptableObject desc, boolean checkValid)Defines a property on an object.voiddelete(int index)Removes the indexed property from the object.voiddelete(Symbol key)Removes an object like the others, but using a Symbol as the key.java.lang.ObjectexecIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args)'thisObj' will be null if invoked as constructor, in which case * instance of Scriptable should be returned.protected voidfillConstructorProperties(IdFunctionObject ctor)protected intfindInstanceIdInfo(java.lang.String s)Map name to id of instance property.protected intfindPrototypeId(java.lang.String s)protected intfindPrototypeId(Symbol k)java.lang.Objectget(int index)java.lang.Objectget(int index, Scriptable start)Returns the value of the indexed property or NOT_FOUND.java.lang.Objectget(long index)java.lang.Objectget(Symbol key, Scriptable start)Another version of Get that supports Symbol keyed properties.intgetAttributes(int index)Get the attributes of an indexed property.java.lang.StringgetClassName()Return the name of the class.java.lang.ObjectgetDefaultValue(java.lang.Class<?> hint)Implements the [[DefaultValue]] internal method.java.lang.Object[]getIds(boolean nonEnumerable, boolean getSymbols)java.util.List<java.lang.Integer>getIndexIds()protected java.lang.StringgetInstanceIdName(int id)Map id back to property name it defines.protected java.lang.ObjectgetInstanceIdValue(int id)Get id value.longgetLength()protected intgetMaxInstanceId()Get maximum id findInstanceIdInfo can generate.protected ScriptableObjectgetOwnPropertyDescriptor(Context cx, java.lang.Object id)booleanhas(int index, Scriptable start)Returns true if the property index is defined.booleanhas(Symbol key, Scriptable start)A version of "has" that supports symbols.intindexOf(java.lang.Object o)protected voidinitPrototypeId(int id)booleanisEmpty()java.util.Iteratoriterator()longjsGet_length()Deprecated.UsegetLength()instead.intlastIndexOf(java.lang.Object o)java.util.ListIteratorlistIterator()java.util.ListIteratorlistIterator(int start)voidput(int index, Scriptable start, java.lang.Object value)Sets the value of the indexed property, creating it if need be.voidput(java.lang.String id, Scriptable start, java.lang.Object value)Sets the value of the named property, creating it if need be.voidput(Symbol key, Scriptable start, java.lang.Object value)Implementation of put required by SymbolScriptable objects.java.lang.Objectremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection c)booleanretainAll(java.util.Collection c)java.lang.Objectset(int index, java.lang.Object element)protected voidsetInstanceIdAttributes(int id, int attr)Update the attributes of the given instance property.protected voidsetInstanceIdValue(int id, java.lang.Object value)Set or delete id value.voidsetPrototype(Scriptable p)Sets the prototype of the object.intsize()java.util.ListsubList(int fromIndex, int toIndex)java.lang.Object[]toArray()java.lang.Object[]toArray(java.lang.Object[] a)-
Methods inherited from class org.mozilla.javascript.IdScriptableObject
activatePrototypeMap, addIdFunctionProperty, defaultGet, defaultHas, defaultPut, delete, ensureType, exportAsJSClass, findInstanceIdInfo, get, getAttributes, getAttributes, has, hasPrototypeMap, initPrototypeConstructor, initPrototypeMethod, initPrototypeMethod, initPrototypeMethod, initPrototypeValue, initPrototypeValue, instanceIdInfo, setAttributes
-
Methods inherited from class org.mozilla.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, equivalentValues, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, hasInstance, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope
-
-
-
-
Method Detail
-
getClassName
public java.lang.String getClassName()
Description copied from class:ScriptableObjectReturn the name of the class.This is typically the same name as the constructor. Classes extending ScriptableObject must implement this abstract method.
- Specified by:
getClassNamein interfaceScriptable- Specified by:
getClassNamein classScriptableObject
-
getMaxInstanceId
protected int getMaxInstanceId()
Description copied from class:IdScriptableObjectGet maximum id findInstanceIdInfo can generate.- Overrides:
getMaxInstanceIdin classIdScriptableObject
-
setInstanceIdAttributes
protected void setInstanceIdAttributes(int id, int attr)Description copied from class:IdScriptableObjectUpdate the attributes of the given instance property. Classes which want to support changing property attributes via Object.defineProperty must override this method. The default implementation throws InternalError.- Overrides:
setInstanceIdAttributesin classIdScriptableObject- Parameters:
id- the instance property idattr- the new attribute bitset
-
findInstanceIdInfo
protected int findInstanceIdInfo(java.lang.String s)
Description copied from class:IdScriptableObjectMap name to id of instance property. Should return 0 if not found or the result ofIdScriptableObject.instanceIdInfo(int, int).- Overrides:
findInstanceIdInfoin classIdScriptableObject
-
getInstanceIdName
protected java.lang.String getInstanceIdName(int id)
Description copied from class:IdScriptableObjectMap id back to property name it defines.- Overrides:
getInstanceIdNamein classIdScriptableObject
-
getInstanceIdValue
protected java.lang.Object getInstanceIdValue(int id)
Description copied from class:IdScriptableObjectGet 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:
getInstanceIdValuein classIdScriptableObject
-
setInstanceIdValue
protected void setInstanceIdValue(int id, java.lang.Object value)Description copied from class:IdScriptableObjectSet or delete id value. If value == NOT_FOUND , the implementation should make sure that the following getInstanceIdValue return NOT_FOUND.- Overrides:
setInstanceIdValuein classIdScriptableObject
-
fillConstructorProperties
protected void fillConstructorProperties(IdFunctionObject ctor)
- Overrides:
fillConstructorPropertiesin classIdScriptableObject
-
initPrototypeId
protected void initPrototypeId(int id)
- Overrides:
initPrototypeIdin classIdScriptableObject
-
execIdCall
public java.lang.Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, java.lang.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:
execIdCallin interfaceIdFunctionCall- Overrides:
execIdCallin classIdScriptableObject
-
setPrototype
public void setPrototype(Scriptable p)
Description copied from class:ScriptableObjectSets the prototype of the object.- Specified by:
setPrototypein interfaceScriptable- Overrides:
setPrototypein classScriptableObject- Parameters:
p- the prototype to set
-
get
public java.lang.Object get(int index, Scriptable start)Description copied from class:ScriptableObjectReturns the value of the indexed property or NOT_FOUND.- Specified by:
getin interfaceScriptable- Overrides:
getin classScriptableObject- Parameters:
index- the numeric index for the propertystart- 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:ScriptableObjectReturns true if the property index is defined.- Specified by:
hasin interfaceScriptable- Overrides:
hasin classScriptableObject- Parameters:
index- the numeric index for the propertystart- 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)
-
has
public boolean has(Symbol key, Scriptable start)
Description copied from class:ScriptableObjectA version of "has" that supports symbols.- Specified by:
hasin interfaceSymbolScriptable- Overrides:
hasin classIdScriptableObject
-
get
public java.lang.Object get(Symbol key, Scriptable start)
Description copied from class:ScriptableObjectAnother version of Get that supports Symbol keyed properties.- Specified by:
getin interfaceSymbolScriptable- Overrides:
getin classIdScriptableObject
-
put
public void put(Symbol key, Scriptable start, java.lang.Object value)
Description copied from class:ScriptableObjectImplementation of put required by SymbolScriptable objects.- Specified by:
putin interfaceSymbolScriptable- Overrides:
putin classIdScriptableObject
-
delete
public void delete(Symbol key)
Description copied from class:ScriptableObjectRemoves an object like the others, but using a Symbol as the key.- Specified by:
deletein interfaceSymbolScriptable- Overrides:
deletein classIdScriptableObject
-
put
public void put(java.lang.String id, Scriptable start, java.lang.Object value)Description copied from class:ScriptableObjectSets 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:
putin interfaceScriptable- Overrides:
putin classIdScriptableObject- Parameters:
id- the name of the propertystart- the object whose property is being setvalue- 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, java.lang.Object value)Description copied from class:ScriptableObjectSets the value of the indexed property, creating it if need be.- Specified by:
putin interfaceScriptable- Overrides:
putin classScriptableObject- Parameters:
index- the numeric index for the propertystart- the object whose property is being setvalue- 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:ScriptableObjectRemoves the indexed property from the object.If the property is not found, or it has the PERMANENT attribute, no action is taken.
- Specified by:
deletein interfaceScriptable- Overrides:
deletein classScriptableObject- Parameters:
index- the numeric index for the property- See Also:
Scriptable.get(int, Scriptable),ScriptableObject.deleteProperty(Scriptable, int)
-
getIds
public java.lang.Object[] getIds(boolean nonEnumerable, boolean getSymbols)
-
getIndexIds
public java.util.List<java.lang.Integer> getIndexIds()
-
getDefaultValue
public java.lang.Object getDefaultValue(java.lang.Class<?> hint)
Description copied from class:ScriptableObjectImplements 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
hintof null means "no hint".- Specified by:
getDefaultValuein interfaceScriptable- Overrides:
getDefaultValuein classScriptableObject- Parameters:
hint- the type hint- Returns:
- the default value for the object
See ECMA 8.6.2.6.
-
getAttributes
public int getAttributes(int index)
Description copied from class:ScriptableObjectGet the attributes of an indexed property.- Overrides:
getAttributesin classScriptableObject- Parameters:
index- the numeric index for the property- Returns:
- the bitset of attributes
- See Also:
ScriptableObject.has(String, Scriptable),ScriptableObject.READONLY,ScriptableObject.DONTENUM,ScriptableObject.PERMANENT,ScriptableObject.EMPTY
-
getOwnPropertyDescriptor
protected ScriptableObject getOwnPropertyDescriptor(Context cx, java.lang.Object id)
- Overrides:
getOwnPropertyDescriptorin classIdScriptableObject
-
defineOwnProperty
protected void defineOwnProperty(Context cx, java.lang.Object id, ScriptableObject desc, boolean checkValid)
Description copied from class:ScriptableObjectDefines a property on an object.Based on [[DefineOwnProperty]] from 8.12.10 of the spec.
- Overrides:
defineOwnPropertyin classIdScriptableObject- Parameters:
cx- the current Contextid- the name/index of the propertydesc- the new property descriptor, as described in 8.6.1checkValid- whether to perform validity checks
-
getLength
public long getLength()
-
jsGet_length
@Deprecated public long jsGet_length()
Deprecated.UsegetLength()instead.
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection- Specified by:
containsin interfacejava.util.List
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection- Specified by:
toArrayin interfacejava.util.List
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
- Specified by:
toArrayin interfacejava.util.Collection- Specified by:
toArrayin interfacejava.util.List
-
containsAll
public boolean containsAll(java.util.Collection c)
- Specified by:
containsAllin interfacejava.util.Collection- Specified by:
containsAllin interfacejava.util.List
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection- Specified by:
sizein interfacejava.util.List- Overrides:
sizein classScriptableObject
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection- Specified by:
isEmptyin interfacejava.util.List- Overrides:
isEmptyin classScriptableObject
-
get
public java.lang.Object get(long index)
-
get
public java.lang.Object get(int index)
- Specified by:
getin interfacejava.util.List
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOfin interfacejava.util.List
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOfin interfacejava.util.List
-
iterator
public java.util.Iterator iterator()
- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable- Specified by:
iteratorin interfacejava.util.List
-
listIterator
public java.util.ListIterator listIterator()
- Specified by:
listIteratorin interfacejava.util.List
-
listIterator
public java.util.ListIterator listIterator(int start)
- Specified by:
listIteratorin interfacejava.util.List
-
add
public boolean add(java.lang.Object o)
- Specified by:
addin interfacejava.util.Collection- Specified by:
addin interfacejava.util.List
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection- Specified by:
removein interfacejava.util.List
-
addAll
public boolean addAll(java.util.Collection c)
- Specified by:
addAllin interfacejava.util.Collection- Specified by:
addAllin interfacejava.util.List
-
removeAll
public boolean removeAll(java.util.Collection c)
- Specified by:
removeAllin interfacejava.util.Collection- Specified by:
removeAllin interfacejava.util.List
-
retainAll
public boolean retainAll(java.util.Collection c)
- Specified by:
retainAllin interfacejava.util.Collection- Specified by:
retainAllin interfacejava.util.List
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection- Specified by:
clearin interfacejava.util.List
-
add
public void add(int index, java.lang.Object element)- Specified by:
addin interfacejava.util.List
-
addAll
public boolean addAll(int index, java.util.Collection c)- Specified by:
addAllin interfacejava.util.List
-
set
public java.lang.Object set(int index, java.lang.Object element)- Specified by:
setin interfacejava.util.List
-
remove
public java.lang.Object remove(int index)
- Specified by:
removein interfacejava.util.List
-
subList
public java.util.List subList(int fromIndex, int toIndex)- Specified by:
subListin interfacejava.util.List
-
findPrototypeId
protected int findPrototypeId(Symbol k)
- Overrides:
findPrototypeIdin classIdScriptableObject
-
findPrototypeId
protected int findPrototypeId(java.lang.String s)
- Overrides:
findPrototypeIdin classIdScriptableObject
-
-