org.mozilla.javascript
Class IdScriptableObject

java.lang.Object
  extended by org.mozilla.javascript.ScriptableObject
      extended by org.mozilla.javascript.IdScriptableObject
All Implemented Interfaces:
java.io.Serializable, ConstProperties, DebuggableObject, IdFunctionCall, Scriptable
Direct Known Subclasses:
BaseFunction, NativeArray, NativeCall, NativeContinuation, NativeGenerator, NativeIterator, NativeJSON, NativeObject, NativeRegExp, TopLevel, XMLObject

public abstract class IdScriptableObject
extends ScriptableObject
implements IdFunctionCall

Base class for native object implementation that uses IdFunctionObject to export its methods to script via .prototype object. Any descendant should implement at least the following methods: findInstanceIdInfo getInstanceIdName execIdCall methodArity To define non-function properties, the descendant should override getInstanceIdValue setInstanceIdValue to get/set property value and provide its default attributes. To customize initialization of constructor and prototype objects, descendant may override scopeInit or fillConstructorProperties methods.

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
IdScriptableObject()
           
IdScriptableObject(Scriptable scope, Scriptable prototype)
           
 
Method Summary
 void activatePrototypeMap(int maxPrototypeId)
           
protected  void addIdFunctionProperty(Scriptable obj, java.lang.Object tag, int id, java.lang.String name, int arity)
           
protected  java.lang.Object defaultGet(java.lang.String name)
           
protected  void defaultPut(java.lang.String name, java.lang.Object value)
           
 void defineOwnProperty(Context cx, java.lang.Object key, ScriptableObject desc)
          Defines a property on an object.
 void delete(java.lang.String name)
          Removes a named property from the object.
 java.lang.Object execIdCall(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.
 IdFunctionObject exportAsJSClass(int maxPrototypeId, Scriptable scope, boolean sealed)
           
protected  void fillConstructorProperties(IdFunctionObject ctor)
           
protected  int findInstanceIdInfo(java.lang.String name)
          Map name to id of instance property.
protected  int findPrototypeId(java.lang.String name)
           
 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)
          Get the attributes of a named property.
protected  java.lang.String getInstanceIdName(int id)
          Map id back to property name it defines.
protected  java.lang.Object getInstanceIdValue(int id)
          Get id value.
protected  int getMaxInstanceId()
          Get maximum id findInstanceIdInfo can generate.
protected  ScriptableObject getOwnPropertyDescriptor(Context cx, java.lang.Object id)
           
 boolean has(java.lang.String name, Scriptable start)
          Returns true if the named property is defined.
 boolean hasPrototypeMap()
           
protected static EcmaError incompatibleCallError(IdFunctionObject f)
          Utility method to construct type error to indicate incompatible call when converting script thisObj to a particular type is not possible.
 void initPrototypeConstructor(IdFunctionObject f)
           
protected  void initPrototypeId(int id)
           
 void initPrototypeMethod(java.lang.Object tag, int id, java.lang.String name, int arity)
           
 void initPrototypeValue(int id, java.lang.String name, java.lang.Object value, int attributes)
           
protected static int instanceIdInfo(int attributes, int 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, int attributes)
          Set the attributes of a named property.
protected  void setInstanceIdAttributes(int id, int attr)
          Update the attributes of the given instance property.
protected  void setInstanceIdValue(int id, java.lang.Object value)
          Set or delete id value.
 
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, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, equivalentValues, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getClassName, getClassPrototype, getDefaultValue, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, hasInstance, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IdScriptableObject

public IdScriptableObject()

IdScriptableObject

public IdScriptableObject(Scriptable scope,
                          Scriptable prototype)
Method Detail

defaultGet

protected final java.lang.Object defaultGet(java.lang.String name)

defaultPut

protected final void defaultPut(java.lang.String name,
                                java.lang.Object value)

has

public boolean has(java.lang.String name,
                   Scriptable start)
Description copied from class: ScriptableObject
Returns true if the named property is defined.

Specified by:
has in interface Scriptable
Overrides:
has in class ScriptableObject
Parameters:
name - the name of 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(String, Scriptable), ScriptableObject.getProperty(Scriptable, String)

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.

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

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.

Specified by:
put in interface Scriptable
Overrides:
put in class ScriptableObject
Parameters:
name - 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)

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.

Specified by:
delete in interface Scriptable
Overrides:
delete in class ScriptableObject
Parameters:
name - the name of the property
See Also:
Scriptable.get(String, Scriptable), ScriptableObject.deleteProperty(Scriptable, String)

getAttributes

public int getAttributes(java.lang.String name)
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
Parameters:
name - the identifier for the property
Returns:
the bitset of attributes
See Also:
ScriptableObject.has(String, Scriptable), ScriptableObject.READONLY, ScriptableObject.DONTENUM, ScriptableObject.PERMANENT, ScriptableObject.EMPTY

setAttributes

public void setAttributes(java.lang.String name,
                          int attributes)
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
Parameters:
name - the name of the property
attributes - the bitset of attributes
See Also:
Scriptable.has(String, Scriptable), ScriptableObject.READONLY, ScriptableObject.DONTENUM, ScriptableObject.PERMANENT, ScriptableObject.EMPTY

getMaxInstanceId

protected int getMaxInstanceId()
Get maximum id findInstanceIdInfo can generate.


instanceIdInfo

protected static int instanceIdInfo(int attributes,
                                    int id)

findInstanceIdInfo

protected int findInstanceIdInfo(java.lang.String name)
Map name to id of instance property. Should return 0 if not found or the result of instanceIdInfo(int, int).


getInstanceIdName

protected java.lang.String getInstanceIdName(int id)
Map id back to property name it defines.


getInstanceIdValue

protected java.lang.Object getInstanceIdValue(int id)
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


setInstanceIdValue

protected void setInstanceIdValue(int id,
                                  java.lang.Object value)
Set or delete id value. If value == NOT_FOUND , the implementation should make sure that the following getInstanceIdValue return NOT_FOUND.


setInstanceIdAttributes

protected void setInstanceIdAttributes(int id,
                                       int attr)
Update 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.

Parameters:
id - the instance property id
attr - the new attribute bitset

execIdCall

public java.lang.Object execIdCall(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.

Specified by:
execIdCall in interface IdFunctionCall

exportAsJSClass

public final IdFunctionObject exportAsJSClass(int maxPrototypeId,
                                              Scriptable scope,
                                              boolean sealed)

hasPrototypeMap

public final boolean hasPrototypeMap()

activatePrototypeMap

public final void activatePrototypeMap(int maxPrototypeId)

initPrototypeMethod

public final void initPrototypeMethod(java.lang.Object tag,
                                      int id,
                                      java.lang.String name,
                                      int arity)

initPrototypeConstructor

public final void initPrototypeConstructor(IdFunctionObject f)

initPrototypeValue

public final void initPrototypeValue(int id,
                                     java.lang.String name,
                                     java.lang.Object value,
                                     int attributes)

initPrototypeId

protected void initPrototypeId(int id)

findPrototypeId

protected int findPrototypeId(java.lang.String name)

fillConstructorProperties

protected void fillConstructorProperties(IdFunctionObject ctor)

addIdFunctionProperty

protected void addIdFunctionProperty(Scriptable obj,
                                     java.lang.Object tag,
                                     int id,
                                     java.lang.String name,
                                     int arity)

incompatibleCallError

protected static EcmaError incompatibleCallError(IdFunctionObject f)
Utility method to construct type error to indicate incompatible call when converting script thisObj to a particular type is not possible. Possible usage would be to have a private function like realThis:
  private static NativeSomething realThis(Scriptable thisObj,
                                          IdFunctionObject f)
  {
      if (!(thisObj instanceof NativeSomething))
          throw incompatibleCallError(f);
      return (NativeSomething)thisObj;
 }
 
Note that although such function can be implemented universally via java.lang.Class.isInstance(), it would be much more slower.

Parameters:
f - function that is attempting to convert 'this' object.
Returns:
Scriptable object suitable for a check by the instanceof operator.
Throws:
java.lang.RuntimeException - if no more instanceof target can be found

defineOwnProperty

public void defineOwnProperty(Context cx,
                              java.lang.Object key,
                              ScriptableObject desc)
Description copied from class: ScriptableObject
Defines a property on an object.

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

getOwnPropertyDescriptor

protected ScriptableObject getOwnPropertyDescriptor(Context cx,
                                                    java.lang.Object id)
Overrides:
getOwnPropertyDescriptor in class ScriptableObject