Class FunctionObject
- java.lang.Object
- 
- org.mozilla.javascript.ScriptableObject
- 
- org.mozilla.javascript.IdScriptableObject
- 
- org.mozilla.javascript.BaseFunction
- 
- org.mozilla.javascript.FunctionObject
 
 
 
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- Callable,- ConstProperties,- Constructable,- DebuggableObject,- Function,- IdFunctionCall,- Scriptable,- SymbolScriptable
 
 public class FunctionObject extends BaseFunction - See Also:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class org.mozilla.javascript.ScriptableObjectScriptableObject.KeyComparator
 
- 
 - 
Field SummaryFields Modifier and Type Field Description static intJAVA_BOOLEAN_TYPEstatic intJAVA_DOUBLE_TYPEstatic intJAVA_INT_TYPEstatic intJAVA_OBJECT_TYPEstatic intJAVA_SCRIPTABLE_TYPEstatic intJAVA_STRING_TYPEstatic intJAVA_UNSUPPORTED_TYPE- 
Fields inherited from class org.mozilla.javascript.BaseFunctionId_arguments, Id_arity, Id_length, Id_name, Id_prototype, MAX_INSTANCE_ID
 - 
Fields inherited from class org.mozilla.javascript.ScriptableObjectCONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 - 
Fields inherited from interface org.mozilla.javascript.ScriptableNOT_FOUND
 
- 
 - 
Constructor SummaryConstructors Constructor Description FunctionObject(java.lang.String name, java.lang.reflect.Member methodOrConstructor, Scriptable scope)Create a JavaScript function object from a Java method.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddAsConstructor(Scriptable scope, Scriptable prototype)Define this function as a JavaScript constructor.voidaddAsConstructor(Scriptable scope, Scriptable prototype, int attributes)Define this function as a JavaScript constructor.java.lang.Objectcall(Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args)Performs conversions on argument types if needed and invokes the underlying Java method or constructor.static java.lang.ObjectconvertArg(Context cx, Scriptable scope, java.lang.Object arg, int typeTag)static java.lang.ObjectconvertArg(Context cx, Scriptable scope, java.lang.Object arg, java.lang.Class<?> desired)Deprecated.UsegetTypeTag(Class)andconvertArg(Context, Scriptable, Object, int)for type conversion.ScriptablecreateObject(Context cx, Scriptable scope)Return newScriptableinstance using the default constructor for the class of the underlying Java method.intgetArity()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).java.lang.StringgetFunctionName()intgetLength()Return the same value asgetArity().java.lang.reflect.MembergetMethodOrConstructor()Get Java method or constructor this function represent.static intgetTypeTag(java.lang.Class<?> type)- 
Methods inherited from class org.mozilla.javascript.BaseFunctionconstruct, execIdCall, fillConstructorProperties, findInstanceIdInfo, findPrototypeId, getClassName, getClassPrototype, getInstanceIdName, getInstanceIdValue, getMaxInstanceId, getPrototypeProperty, getTypeOf, hasInstance, hasPrototypeProperty, initPrototypeId, isGeneratorFunction, setImmunePrototypeProperty, setInstanceIdAttributes, setInstanceIdValue, setPrototypeProperty, setPrototypePropertyAttributes, setStandardPropertyAttributes, setupDefaultPrototype
 - 
Methods inherited from class org.mozilla.javascript.IdScriptableObjectactivatePrototypeMap, addIdFunctionProperty, defaultGet, defaultHas, defaultPut, defineOwnProperty, delete, delete, ensureType, exportAsJSClass, findInstanceIdInfo, findPrototypeId, get, get, getAttributes, getAttributes, getOwnPropertyDescriptor, has, has, hasPrototypeMap, initPrototypeConstructor, initPrototypeMethod, initPrototypeMethod, initPrototypeMethod, initPrototypeValue, initPrototypeValue, instanceIdInfo, put, put, setAttributes
 - 
Methods inherited from class org.mozilla.javascript.ScriptableObjectapplyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, equivalentValues, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.mozilla.javascript.Scriptabledelete, delete, get, get, getDefaultValue, getIds, getParentScope, getPrototype, has, has, put, put, setParentScope, setPrototype
 
- 
 
- 
- 
- 
Field Detail- 
JAVA_UNSUPPORTED_TYPEpublic static final int JAVA_UNSUPPORTED_TYPE - See Also:
- Constant Field Values
 
 - 
JAVA_STRING_TYPEpublic static final int JAVA_STRING_TYPE - See Also:
- Constant Field Values
 
 - 
JAVA_INT_TYPEpublic static final int JAVA_INT_TYPE - See Also:
- Constant Field Values
 
 - 
JAVA_BOOLEAN_TYPEpublic static final int JAVA_BOOLEAN_TYPE - See Also:
- Constant Field Values
 
 - 
JAVA_DOUBLE_TYPEpublic static final int JAVA_DOUBLE_TYPE - See Also:
- Constant Field Values
 
 - 
JAVA_SCRIPTABLE_TYPEpublic static final int JAVA_SCRIPTABLE_TYPE - See Also:
- Constant Field Values
 
 - 
JAVA_OBJECT_TYPEpublic static final int JAVA_OBJECT_TYPE - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
FunctionObjectpublic FunctionObject(java.lang.String name, java.lang.reflect.Member methodOrConstructor, Scriptable scope)Create a JavaScript function object from a Java method.The memberargument 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, the argsparameter contains the arguments, withthisObjset to the JavaScript 'this' value.funObjis the function object for the invoked function.When the constructor varargs form is called or invoked while evaluating a newexpression,argscontains the arguments,ctorObjrefers to this FunctionObject, andinNewExpris true if and only if anewexpression 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 function
- methodOrConstructor- a java.lang.reflect.Method or a java.lang.reflect.Constructor that defines the object
- scope- enclosing scope of function
- See Also:
- Scriptable
 
 
- 
 - 
Method Detail- 
getTypeTagpublic static int getTypeTag(java.lang.Class<?> type) - Returns:
- One of JAVA_*_TYPEconstants to indicate desired type orJAVA_UNSUPPORTED_TYPEif the convertion is not possible
 
 - 
convertArgpublic static java.lang.Object convertArg(Context cx, Scriptable scope, java.lang.Object arg, int typeTag) 
 - 
getAritypublic 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:
- getArityin class- BaseFunction
 
 - 
getLengthpublic int getLength() Return the same value asgetArity().- Overrides:
- getLengthin class- BaseFunction
 
 - 
getFunctionNamepublic java.lang.String getFunctionName() - Overrides:
- getFunctionNamein class- BaseFunction
 
 - 
getMethodOrConstructorpublic java.lang.reflect.Member getMethodOrConstructor() Get Java method or constructor this function represent.
 - 
addAsConstructorpublic 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, using prototype.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
- See Also:
- Scriptable.setParentScope(org.mozilla.javascript.Scriptable),- Scriptable.setPrototype(org.mozilla.javascript.Scriptable),- Scriptable.getClassName()
 
 - 
addAsConstructorpublic void addAsConstructor(Scriptable scope, Scriptable prototype, int attributes) 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, using prototype.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
- attributes- the attributes of the constructor property
- See Also:
- Scriptable.setParentScope(org.mozilla.javascript.Scriptable),- Scriptable.setPrototype(org.mozilla.javascript.Scriptable),- Scriptable.getClassName()
 
 - 
convertArg@Deprecated public static java.lang.Object convertArg(Context cx, Scriptable scope, java.lang.Object arg, java.lang.Class<?> desired) Deprecated.UsegetTypeTag(Class)andconvertArg(Context, Scriptable, Object, int)for type conversion.
 - 
callpublic java.lang.Object call(Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args) Performs conversions on argument types if needed and invokes the underlying Java method or constructor.Implements Function.call. - Specified by:
- callin interface- Callable
- Specified by:
- callin interface- Function
- Overrides:
- callin class- BaseFunction
- 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- thisobject
- args- the array of arguments
- Returns:
- the result of the call
- See Also:
- Function.call( Context, Scriptable, Scriptable, Object[])
 
 - 
createObjectpublic Scriptable createObject(Context cx, Scriptable scope) Return newScriptableinstance 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:
- createObjectin class- BaseFunction
 
 
- 
 
-