org.mozilla.javascript

Class IdScriptableObject

Implemented Interfaces:
ConstProperties, DebuggableObject, IdFunctionCall, Scriptable, Serializable
Known Direct Subclasses:
BaseFunction, ImporterTopLevel, NativeArray, NativeCall, NativeContinuation, NativeGenerator, NativeIterator, NativeObject, NativeRegExp, 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 initializition of constructor and protype objects, descendant may override scopeInit or fillConstructorProperties methods.

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

@Override
Object get(String name, Scriptable start)
void
activatePrototypeMap(int maxPrototypeId)
protected void
addIdFunctionProperty(Scriptable obj, Object tag, int id, String name, int arity)
@Override
boolean has(String name, Scriptable start)
protected Object
defaultGet(String name)
protected void
defaultPut(String name, Object value)
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.
IdFunctionObject
exportAsJSClass(int maxPrototypeId, Scriptable scope, boolean sealed)
protected void
fillConstructorProperties(IdFunctionObject ctor)
protected int
findInstanceIdInfo(String name)
Map name to id of instance property.
protected int
findPrototypeId(String name)
protected String
getInstanceIdName(int id)
Map id back to property name it defines.
protected Object
getInstanceIdValue(int id)
Get id value.
protected int
getMaxInstanceId()
Get maximum id findInstanceIdInfo can generate.
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(Object tag, int id, String name, int arity)
void
initPrototypeValue(int id, String name, Object value, int attributes)
protected static int
instanceIdInfo(int attributes, int id)
@Override
int getAttributes(String name)
protected void
setInstanceIdValue(int id, Object value)
Set or delete id value.
@Override
void delete(String name)
@Override
void put(String name, Scriptable start, Object value)
@Override
void setAttributes(String name, int attributes)

Methods inherited from class org.mozilla.javascript.ScriptableObject

associateValue, avoidObjectDetection, callMethod, callMethod, defineConst, defineConstProperty, defineFunctionProperties, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, equivalentValues, extends Scriptable> String defineClass, extends Scriptable> void defineClass, extends Scriptable> void defineClass, get, get, getAllIds, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassName, getClassPrototype, getDefaultValue, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, has, has, hasInstance, hasProperty, hasProperty, isConst, isGetterOrSetter, isSealed, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype

Constructor Details

IdScriptableObject

public IdScriptableObject()

IdScriptableObject

public IdScriptableObject(Scriptable scope,
                          Scriptable prototype)

Method Details

Object get

public @Override Object get(String name,
                            Scriptable start)

activatePrototypeMap

public final void activatePrototypeMap(int maxPrototypeId)

addIdFunctionProperty

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

boolean has

public @Override boolean has(String name,
                             Scriptable start)

defaultGet

protected final Object defaultGet(String name)

defaultPut

protected final void defaultPut(String name,
                                Object value)

execIdCall

public 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.
Specified by:
execIdCall in interface IdFunctionCall

exportAsJSClass

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

fillConstructorProperties

protected void fillConstructorProperties(IdFunctionObject ctor)

findInstanceIdInfo

protected int findInstanceIdInfo(String name)

findPrototypeId

protected int findPrototypeId(String name)

getInstanceIdName

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

getInstanceIdValue

protected 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

getMaxInstanceId

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

hasPrototypeMap

public final boolean hasPrototypeMap()

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.

initPrototypeConstructor

public final void initPrototypeConstructor(IdFunctionObject f)

initPrototypeId

protected void initPrototypeId(int id)

initPrototypeMethod

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

initPrototypeValue

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

instanceIdInfo

protected static int instanceIdInfo(int attributes,
                                    int id)

int getAttributes

public @Override int getAttributes(String name)

setInstanceIdValue

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

void delete

public @Override void delete(String name)

void put

public @Override void put(String name,
                          Scriptable start,
                          Object value)

void setAttributes

public @Override void setAttributes(String name,
                                    int attributes)