Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.mozilla.javascript.ScriptableObject
org.mozilla.javascript.IdScriptable
org.mozilla.javascript.BaseFunction
org.mozilla.javascript.FunctionObject
public class FunctionObject
extends org.mozilla.javascript.BaseFunction
Nested Class Summary |
Field Summary | |
static int | |
static int | |
static int | |
static int | |
static int | |
static int | |
static int |
Fields inherited from class org.mozilla.javascript.ScriptableObject | |
DONTENUM , EMPTY , PERMANENT , READONLY |
Fields inherited from interface org.mozilla.javascript.Scriptable | |
NOT_FOUND |
Constructor Summary | |
|
Method Summary | |
void |
|
Object |
|
static Object |
|
static Object |
|
Scriptable |
|
int |
|
int |
|
Member |
|
static int |
|
Methods inherited from class org.mozilla.javascript.BaseFunction | |
call , construct , createObject , execMethod , getArity , getClassName , getFunctionName , getLength , hasInstance , methodArity , setImmunePrototypeProperty |
Methods inherited from class org.mozilla.javascript.IdScriptable | |
addAsPrototype , defineProperty , delete , execMethod , get , getAttributes , has , methodArity , put , setAttributes |
Methods inherited from class org.mozilla.javascript.ScriptableObject | |
associateValue , callMethod , defineClass , defineClass , defineFunctionProperties , defineProperty , defineProperty , defineProperty , defineProperty , delete , delete , deleteProperty , deleteProperty , get , get , getAllIds , getAssociatedValue , getAttributes , getAttributes , getAttributes , getAttributes , getClassName , getClassPrototype , getDefaultValue , getFunctionPrototype , getIds , getObjectPrototype , getParentScope , getProperty , getProperty , getPropertyIds , getPrototype , getTopLevelScope , has , has , hasInstance , hasProperty , hasProperty , isSealed , put , put , putProperty , putProperty , sealObject , setAttributes , setAttributes , setAttributes , setAttributes , setParentScope , setPrototype |
public static final int JAVA_BOOLEAN_TYPE
- Field Value:
- 3
public static final int JAVA_DOUBLE_TYPE
- Field Value:
- 4
public static final int JAVA_INT_TYPE
- Field Value:
- 2
public static final int JAVA_OBJECT_TYPE
- Field Value:
- 6
public static final int JAVA_SCRIPTABLE_TYPE
- Field Value:
- 5
public static final int JAVA_STRING_TYPE
- Field Value:
- 1
public static final int JAVA_UNSUPPORTED_TYPE
- Field Value:
- 0
public FunctionObject(String name, Member methodOrConstructor, Scriptable scope)
Create a JavaScript function object from a Java method. Themember
argument must be either a java.lang.reflect.Method or a java.lang.reflect.Constructor and must match one of two forms. The first form is a member with zero or more parameters of the following types: Object, String, boolean, Scriptable, int, or double. The Long type is not supported because the double representation of a long (which is the EMCA-mandated storage type for Numbers) may lose precision. If the member is a Method, the return value must be void or one of the types allowed for parameters. The runtime will perform appropriate conversions based upon the type of the parameter. A parameter type of Object specifies that no conversions are to be done. A parameter of type String will use Context.toString to convert arguments. Similarly, parameters of type double, boolean, and Scriptable will cause Context.toNumber, Context.toBoolean, and Context.toObject, respectively, to be called. If the method is not static, the Java 'this' value will correspond to the JavaScript 'this' value. Any attempt to call the function with a 'this' value that is not of the right Java type will result in an error. The second form is the variable arguments (or "varargs") form. If the FunctionObject will be used as a constructor, the member must have the following parameters(Context cx, Object[] args, Function ctorObj, boolean inNewExpr)and if it is a Method, be static and return an Object result. Otherwise, if the FunctionObject will not be used to define a constructor, the member must be a static Method with parameters (Context cx, Scriptable thisObj, Object[] args, Function funObj)and an Object result. When the function varargs form is called as part of a function call, theargs
parameter contains the arguments, withthisObj
set to the JavaScript 'this' value.funObj
is the function object for the invoked function. When the constructor varargs form is called or invoked while evaluating anew
expression,args
contains the arguments,ctorObj
refers to this FunctionObject, andinNewExpr
is true if and only if anew
expression caused the call. This supports defining a function that has different behavior when called as a constructor than when invoked as a normal function call. (For example, the Boolean constructor, when called as a function, will convert to boolean rather than creating a new object.)
- Parameters:
name
- the name of the functionmethodOrConstructor
- a java.lang.reflect.Method or a java.lang.reflect.Constructor that defines the objectscope
- enclosing scope of function
- See Also:
Scriptable
public void addAsConstructor(Scriptable scope, Scriptable prototype)
Define this function as a JavaScript constructor. Sets up the "prototype" and "constructor" properties. Also calls setParent and setPrototype with appropriate values. Then adds the function object as a property of the given scope, usingprototype.getClassName()
as the name of the property.
- Parameters:
scope
- the scope in which to define the constructor (typically the global object)prototype
- the prototype object
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) throws JavaScriptException
Performs conversions on argument types if needed and invokes the underlying Java method or constructor. Implements Function.call.
- Overrides:
- call in interface org.mozilla.javascript.BaseFunction
- Throws:
JavaScriptException
- if the underlying Java method or constructor threw an exception
public static Object convertArg(Context cx, Scriptable scope, Object arg, Class desired)
Deprecated. Use
getTypeTag(Class)
andconvertArg(Context,Scriptable,Object,int)
for type convertion.
public Scriptable createObject(Context cx, Scriptable scope)
Return newScriptable
instance using the default constructor for the class of the underlying Java method. Return null to indicate that the call method should be used to create new objects.
- Overrides:
- createObject in interface org.mozilla.javascript.BaseFunction
public int getArity()
Return the value defined by the method used to construct the object (number of parameters of the method, or 1 if the method is a "varargs" form).
- Overrides:
- getArity in interface org.mozilla.javascript.BaseFunction
public int getLength()
Return the same value asgetArity()
.
- Overrides:
- getLength in interface org.mozilla.javascript.BaseFunction
public Member getMethodOrConstructor()
Get Java method or constructor this function represent.
public static int getTypeTag(Class type)
- Returns:
- One of JAVA_*_TYPE constants to indicate desired type or
JAVA_UNSUPPORTED_TYPE
if the convertion is not possible