org.mozilla.javascript
Class IdScriptable
java.lang.Object
|
+--org.mozilla.javascript.ScriptableObject
|
+--org.mozilla.javascript.IdScriptable
- All Implemented Interfaces:
- IdFunctionMaster, Scriptable, java.io.Serializable
- Direct Known Subclasses:
- BaseFunction, NativeArray, NativeBoolean, NativeCall, NativeDate, NativeError, NativeMath, NativeNumber, NativeObject, NativeRegExp, NativeString
- public abstract class IdScriptable
- extends ScriptableObject
- implements IdFunctionMaster
Base class for native object implementation that uses IdFunction to export its methods to script via .prototype object.
Any descendant should implement at least the following methods:
mapNameToId
getIdName
execMethod
methodArity
To define non-function properties, the descendant should customize
getIdValue
setIdValue
getIdDefaultAttributes
maxInstanceId
to get/set property value and provide its default attributes.
To customize initializition of constructor and protype objects, descendant
may override scopeInit or fillConstructorProperties methods.
- See Also:
- Serialized Form
Method Summary |
void |
addAsPrototype(int maxId,
Context cx,
Scriptable scope,
boolean sealed)
Prepare this object to serve as the prototype property of constructor
object with name getClassName() defined in
scope . |
void |
defineProperty(java.lang.String propertyName,
java.lang.Object value,
int attributes)
Redefine ScriptableObject.defineProperty to allow changing
values/attributes of id-based properties unless
getIdDefaultAttributes contains the READONLY attribute. |
void |
delete(java.lang.String name)
Removes a named property from the object.
|
java.lang.Object |
execMethod(int methodId,
IdFunction function,
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. |
java.lang.Object |
get(java.lang.String name,
Scriptable start)
Returns the value of the named property or NOT_FOUND.
|
int |
getAttributes(java.lang.String name,
Scriptable start)
Get the attributes of a named property.
|
boolean |
has(java.lang.String name,
Scriptable start)
Returns true if the named property is defined. |
int |
methodArity(int methodId)
Get arity or defined argument count for method with given id.
|
void |
put(java.lang.String name,
Scriptable start,
java.lang.Object value)
Sets the value of the named property, creating it if need be.
|
void |
setAttributes(java.lang.String name,
Scriptable start,
int attributes)
Set the attributes of a named property.
|
Methods inherited from class org.mozilla.javascript.ScriptableObject |
callMethod, defineClass, defineClass, defineFunctionProperties, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, get, getAllIds, getAttributes, getClassName, getClassPrototype, getDefaultValue, getFunctionPrototype, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, has, hasInstance, hasProperty, hasProperty, isSealed, put, putProperty, putProperty, sealObject, setAttributes, setParentScope, setPrototype |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
IdScriptable
public IdScriptable()
has
public boolean has(java.lang.String name,
Scriptable start)
- Description copied from class:
ScriptableObject
- Returns true if the named property is defined.
- Overrides:
has
in class ScriptableObject
- Following copied from class:
org.mozilla.javascript.ScriptableObject
- Parameters:
name
- the name of the propertystart
- the object in which the lookup began- Returns:
- true if and only if the property was found in the object
get
public java.lang.Object get(java.lang.String name,
Scriptable start)
- Description copied from class:
ScriptableObject
- Returns the value of the named property or NOT_FOUND.
If the property was created using defineProperty, the
appropriate getter method is called.
- Overrides:
get
in class ScriptableObject
- Following copied from class:
org.mozilla.javascript.ScriptableObject
- Parameters:
name
- the name of the propertystart
- the object in which the lookup began- Returns:
- the value of the property (may be null), or NOT_FOUND
put
public void put(java.lang.String name,
Scriptable start,
java.lang.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.
- Overrides:
put
in class ScriptableObject
- Following copied from class:
org.mozilla.javascript.ScriptableObject
- Parameters:
name
- the name of the propertystart
- the object whose property is being setvalue
- value to set the property to
delete
public void delete(java.lang.String name)
- Description copied from class:
ScriptableObject
- Removes a named property from the object.
If the property is not found, or it has the PERMANENT attribute,
no action is taken.
- Overrides:
delete
in class ScriptableObject
- Following copied from class:
org.mozilla.javascript.ScriptableObject
- Parameters:
name
- the name of the property
getAttributes
public int getAttributes(java.lang.String name,
Scriptable start)
throws PropertyException
- Description copied from class:
ScriptableObject
- Get the attributes of a named property.
The property is specified by
name
as defined for has
.
- Overrides:
getAttributes
in class ScriptableObject
- Following copied from class:
org.mozilla.javascript.ScriptableObject
- Parameters:
name
- the identifier for the propertystart
- the object in which the lookup began- Returns:
- the bitset of attributes
- Throws:
PropertyException
- if the named property
is not found- See Also:
ScriptableObject.has(java.lang.String, org.mozilla.javascript.Scriptable)
,
ScriptableObject.READONLY
,
ScriptableObject.DONTENUM
,
ScriptableObject.PERMANENT
,
ScriptableObject.EMPTY
setAttributes
public void setAttributes(java.lang.String name,
Scriptable start,
int attributes)
throws PropertyException
- Description copied from class:
ScriptableObject
- Set the attributes of a named property.
The property is specified by
name
as defined for has
.
The possible attributes are READONLY, DONTENUM,
and PERMANENT. Combinations of attributes
are expressed by the bitwise OR of attributes.
EMPTY is the state of no attributes set. Any unused
bits are reserved for future use.
- Overrides:
setAttributes
in class ScriptableObject
- Following copied from class:
org.mozilla.javascript.ScriptableObject
- Parameters:
name
- the name of the propertystart
- the object in which the lookup beganattributes
- the bitset of attributes- Throws:
PropertyException
- if the named property
is not found- See Also:
Scriptable.has(java.lang.String, org.mozilla.javascript.Scriptable)
,
ScriptableObject.READONLY
,
ScriptableObject.DONTENUM
,
ScriptableObject.PERMANENT
,
ScriptableObject.EMPTY
defineProperty
public void defineProperty(java.lang.String propertyName,
java.lang.Object value,
int attributes)
- Redefine ScriptableObject.defineProperty to allow changing
values/attributes of id-based properties unless
getIdDefaultAttributes contains the READONLY attribute.
- Overrides:
defineProperty
in class ScriptableObject
- See Also:
#getIdDefaultAttributes
,
ScriptableObject.defineProperty(java.lang.String, java.lang.Object, int)
execMethod
public java.lang.Object execMethod(int methodId,
IdFunction function,
Context cx,
Scriptable scope,
Scriptable thisObj,
java.lang.Object[] args)
throws JavaScriptException
- 'thisObj' will be null if invoked as constructor, in which case
instance of Scriptable should be returned.
- Specified by:
execMethod
in interface IdFunctionMaster
methodArity
public int methodArity(int methodId)
- Get arity or defined argument count for method with given id.
Should return -1 if methodId is not known or can not be used
with execMethod call.
- Specified by:
methodArity
in interface IdFunctionMaster
addAsPrototype
public void addAsPrototype(int maxId,
Context cx,
Scriptable scope,
boolean sealed)
- Prepare this object to serve as the prototype property of constructor
object with name
getClassName() defined in
scope
.
- Parameters:
maxId
- maximum id available in prototype objectcx
- current contextscope
- object to define constructor in.sealed
- indicates whether object and all its properties should
be sealed