org.mozilla.javascript
Class BaseFunction

java.lang.Object
  |
  +--org.mozilla.javascript.ScriptableObject
        |
        +--org.mozilla.javascript.IdScriptable
              |
              +--org.mozilla.javascript.BaseFunction
All Implemented Interfaces:
Function, IdFunctionMaster, Scriptable, java.io.Serializable
Direct Known Subclasses:
IdFunction, NativeFunction

public class BaseFunction
extends IdScriptable
implements Function

The base class for Function objects See ECMA 15.3.

Author:
Norris Boyd
See Also:
Serialized Form

Fields inherited from class org.mozilla.javascript.ScriptableObject
DONTENUM, EMPTY, PERMANENT, READONLY
 
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
BaseFunction()
           
 
Method Summary
 java.lang.Object call(Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args)
          Should be overridden.
 Scriptable construct(Context cx, Scriptable scope, java.lang.Object[] args)
          Call the function as a constructor.
 java.lang.String decompile(Context cx, int indent, boolean justbody)
          Decompile the source information associated with this js function/script back into a string.
 java.lang.Object execMethod(int methodId, IdFunction 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.
 int getArity()
           
 java.lang.String getClassName()
          Get the name of the set of objects implemented by this Java class.
 java.lang.String getFunctionName()
           
 int getLength()
           
 boolean hasInstance(Scriptable instance)
          Implements the instanceof operator for JavaScript Function objects.
 int methodArity(int methodId)
          Get arity or defined argument count for method with given id.
 void setImmunePrototypeProperty(java.lang.Object value)
          Make value as DontEnum, DontDelete, ReadOnly prototype property of this Function object
 
Methods inherited from class org.mozilla.javascript.IdScriptable
addAsPrototype, defineProperty, delete, get, getAttributes, has, put, setAttributes
 
Methods inherited from class org.mozilla.javascript.ScriptableObject
callMethod, defineClass, defineClass, defineFunctionProperties, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, get, getAllIds, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, has, hasProperty, hasProperty, isSealed, put, putProperty, putProperty, sealObject, setAttributes, setParentScope, setPrototype
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mozilla.javascript.Scriptable
delete, delete, get, get, getDefaultValue, getIds, getParentScope, getPrototype, has, has, put, put, setParentScope, setPrototype
 

Constructor Detail

BaseFunction

public BaseFunction()
Method Detail

getClassName

public java.lang.String getClassName()
Description copied from interface: Scriptable
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 class ScriptableObject

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 class 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

methodArity

public int methodArity(int methodId)
Description copied from class: IdScriptable
Get arity or defined argument count for method with given id. Should return -1 if methodId is not known or can not be used with execMethod call.
Overrides:
methodArity in class IdScriptable

execMethod

public java.lang.Object execMethod(int methodId,
                                   IdFunction f,
                                   Context cx,
                                   Scriptable scope,
                                   Scriptable thisObj,
                                   java.lang.Object[] args)
                            throws JavaScriptException
Description copied from class: IdScriptable
'thisObj' will be null if invoked as constructor, in which case instance of Scriptable should be returned.
Overrides:
execMethod in class IdScriptable

setImmunePrototypeProperty

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

call

public java.lang.Object call(Context cx,
                             Scriptable scope,
                             Scriptable thisObj,
                             java.lang.Object[] args)
                      throws JavaScriptException
Should be overridden.
Specified by:
call in interface Function
Following copied from interface: org.mozilla.javascript.Function
Parameters:
cx - the current Context for this thread
scope - the scope to execute the function relative to. This is set to the value returned by getParentScope() except when the function is called from a closure.
thisObj - the JavaScript this object
args - the array of arguments
Returns:
the result of the call
Throws:
JavaScriptException - if an uncaught exception occurred while executing the function

construct

public Scriptable construct(Context cx,
                            Scriptable scope,
                            java.lang.Object[] args)
                     throws JavaScriptException
Description copied from interface: Function
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
Following copied from interface: org.mozilla.javascript.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
Throws:
JavaScriptException - if an uncaught exception occurred while executing the constructor

decompile

public java.lang.String decompile(Context cx,
                                  int indent,
                                  boolean justbody)
Decompile the source information associated with this js function/script back into a string.
Parameters:
cx - Current context
indent - How much to indent the decompiled result
justbody - Whether the decompilation should omit the function header and trailing brace.

getArity

public int getArity()

getLength

public int getLength()

getFunctionName

public java.lang.String getFunctionName()