org.mozilla.javascript

Class BaseFunction

Implemented Interfaces:
Callable, ConstProperties, DebuggableObject, Function, IdFunctionCall, Scriptable, Serializable
Known Direct Subclasses:
FunctionObject, IdFunctionObject, NativeFunction, NativeJavaConstructor, NativeJavaMethod

public class BaseFunction
extends IdScriptableObject
implements Function

The base class for Function objects See ECMA 15.3.
Author:
Norris Boyd

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

BaseFunction()
BaseFunction(Scriptable scope, Scriptable prototype)

Method Summary

Object
call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
Should be overridden.
Scriptable
construct(Context cx, Scriptable scope, Object[] args)
Call the function as a constructor.
Scriptable
createObject(Context cx, Scriptable scope)
Creates new script object.
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.
protected void
fillConstructorProperties(IdFunctionObject ctor)
protected int
findInstanceIdInfo(String s)
Map name to id of instance property.
protected int
findPrototypeId(String s)
int
getArity()
String
getClassName()
Get the name of the set of objects implemented by this Java class.
protected Scriptable
getClassPrototype()
String
getFunctionName()
protected String
getInstanceIdName(int id)
Map id back to property name it defines.
protected Object
getInstanceIdValue(int id)
Get id value.
int
getLength()
protected int
getMaxInstanceId()
Get maximum id findInstanceIdInfo can generate.
boolean
hasInstance(Scriptable instance)
Implements the instanceof operator for JavaScript Function objects.
protected void
initPrototypeId(int id)
void
setImmunePrototypeProperty(Object value)
Make value as DontEnum, DontDelete, ReadOnly prototype property of this Function object
protected void
setInstanceIdValue(int id, Object value)
Set or delete id value.

Methods inherited from class org.mozilla.javascript.IdScriptableObject

activatePrototypeMap, addIdFunctionProperty, defaultGet, defaultPut, delete, execIdCall, exportAsJSClass, fillConstructorProperties, findInstanceIdInfo, findPrototypeId, get, getAttributes, getInstanceIdName, getInstanceIdValue, getMaxInstanceId, has, hasPrototypeMap, incompatibleCallError, initPrototypeConstructor, initPrototypeId, initPrototypeMethod, initPrototypeValue, instanceIdInfo, put, setAttributes, setInstanceIdValue

Methods inherited from class org.mozilla.javascript.ScriptableObject

associateValue, callMethod, callMethod, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, equivalentValues, 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, isSealed, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype

Constructor Details

BaseFunction

public BaseFunction()

BaseFunction

public BaseFunction(Scriptable scope,
                    Scriptable prototype)

Method Details

call

public Object call(Context cx,
                   Scriptable scope,
                   Scriptable thisObj,
                   Object[] args)
Should be overridden.
Specified by:
call in interface Function
call in interface Callable

construct

public Scriptable construct(Context cx,
                            Scriptable scope,
                            Object[] args)
Call the function as a constructor. This method is invoked by the runtime in order to satisfy a use of the JavaScript new operator. This method is expected to create a new object and return it.
Specified by:
construct in interface Function
Parameters:
cx - the current Context for this thread
scope - an enclosing scope of the caller except when the function is called from a closure.
args - the array of arguments
Returns:
the allocated object

createObject

public Scriptable createObject(Context cx,
                               Scriptable scope)
Creates new script object. The default implementation of construct(Context,Scriptable,Object[]) uses the method to to get the value for thisObj argument when invoking call(Context,Scriptable,Scriptable,Object[]). The methos is allowed to return null to indicate that call(Context,Scriptable,Scriptable,Object[]) will create a new object itself. In this case construct(Context,Scriptable,Object[]) will set scope and prototype on the result call(Context,Scriptable,Scriptable,Object[]) unless they are already set.

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
Overrides:
execIdCall in interface IdScriptableObject

fillConstructorProperties

protected void fillConstructorProperties(IdFunctionObject ctor)
Overrides:
fillConstructorProperties in interface IdScriptableObject

findInstanceIdInfo

protected int findInstanceIdInfo(String s)
Overrides:
findInstanceIdInfo in interface IdScriptableObject

findPrototypeId

protected int findPrototypeId(String s)
Overrides:
findPrototypeId in interface IdScriptableObject

getArity

public int getArity()

getClassName

public String getClassName()
Get the name of the set of objects implemented by this Java class. This corresponds to the [[Class]] operation in ECMA and is used by Object.prototype.toString() in ECMA.

See ECMA 8.6.2 and 15.2.4.2.

Specified by:
getClassName in interface Scriptable
Overrides:
getClassName in interface ScriptableObject

getClassPrototype

protected Scriptable getClassPrototype()

getFunctionName

public String getFunctionName()

getInstanceIdName

protected String getInstanceIdName(int id)
Map id back to property name it defines.
Overrides:
getInstanceIdName in interface IdScriptableObject

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
Overrides:
getInstanceIdValue in interface IdScriptableObject

getLength

public int getLength()

getMaxInstanceId

protected int getMaxInstanceId()
Get maximum id findInstanceIdInfo can generate.
Overrides:
getMaxInstanceId in interface IdScriptableObject

hasInstance

public boolean hasInstance(Scriptable instance)
Implements the instanceof operator for JavaScript Function objects.

foo = new Foo();
foo instanceof Foo; // true

Specified by:
hasInstance in interface Scriptable
Overrides:
hasInstance in interface ScriptableObject
Parameters:
instance - The value that appeared on the LHS of the instanceof operator
Returns:
true if the "prototype" property of "this" appears in value's prototype chain

initPrototypeId

protected void initPrototypeId(int id)
Overrides:
initPrototypeId in interface IdScriptableObject

setImmunePrototypeProperty

public void setImmunePrototypeProperty(Object value)
Make value as DontEnum, DontDelete, ReadOnly prototype property of this Function object

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.
Overrides:
setInstanceIdValue in interface IdScriptableObject