org.mozilla.javascript

Class IdScriptableObject

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.
Constructor Summary
IdScriptableObject()
IdScriptableObject(Scriptable scope, Scriptable prototype)
Method Summary
voidactivatePrototypeMap(int maxPrototypeId)
protected voidaddIdFunctionProperty(Scriptable obj, Object tag, int id, String name, int arity)
protected ObjectdefaultGet(String name)
protected voiddefaultPut(String name, Object value)
voiddelete(String name)
ObjectexecIdCall(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.
IdFunctionObjectexportAsJSClass(int maxPrototypeId, Scriptable scope, boolean sealed)
protected voidfillConstructorProperties(IdFunctionObject ctor)
protected intfindInstanceIdInfo(String name)
Map name to id of instance property.
protected intfindPrototypeId(String name)
Objectget(String name, Scriptable start)
intgetAttributes(String name)
protected StringgetInstanceIdName(int id)
Map id back to property name it defines.
protected ObjectgetInstanceIdValue(int id)
Get id value.
protected intgetMaxInstanceId()
Get maximum id findInstanceIdInfo can generate.
booleanhas(String name, Scriptable start)
booleanhasPrototypeMap()
protected static EcmaErrorincompatibleCallError(IdFunctionObject f)
Utility method to construct type error to indicate incompatible call when converting script thisObj to a particular type is not possible.
voidinitPrototypeConstructor(IdFunctionObject f)
protected voidinitPrototypeId(int id)
voidinitPrototypeMethod(Object tag, int id, String name, int arity)
voidinitPrototypeValue(int id, String name, Object value, int attributes)
protected static intinstanceIdInfo(int attributes, int id)
voidput(String name, Scriptable start, Object value)
voidsetAttributes(String name, int attributes)
protected voidsetInstanceIdValue(int id, Object value)
Set or delete id value.

Constructor Detail

IdScriptableObject

public IdScriptableObject()

IdScriptableObject

public IdScriptableObject(Scriptable scope, Scriptable prototype)

Method Detail

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)

delete

public void delete(String name)

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.

exportAsJSClass

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

fillConstructorProperties

protected void fillConstructorProperties(IdFunctionObject ctor)

findInstanceIdInfo

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

findPrototypeId

protected int findPrototypeId(String name)

get

public Object get(String name, Scriptable start)

getAttributes

public int getAttributes(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.

has

public boolean has(String name, Scriptable start)

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: readOnly specify if the function f does not change state of object.

Returns: Scriptable object suitable for a check by the instanceof operator.

Throws: RuntimeException if no more instanceof target can be found

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)

put

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

setAttributes

public void setAttributes(String name, int attributes)

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.