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.
activatePrototypeMap
public final void activatePrototypeMap(int maxPrototypeId)
addIdFunctionProperty
protected void addIdFunctionProperty(Scriptable obj,
Object tag,
int id,
String name,
int arity)
defaultGet
protected final Object defaultGet(String name)
defaultPut
protected final void defaultPut(String name,
Object value)
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.
f
- function that is attempting to convert 'this'
object.
- 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)
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.