Package org.mozilla.javascript
Class NativeJavaMethod
- java.lang.Object
-
- org.mozilla.javascript.ScriptableObject
-
- org.mozilla.javascript.IdScriptableObject
-
- org.mozilla.javascript.BaseFunction
-
- org.mozilla.javascript.NativeJavaMethod
-
- All Implemented Interfaces:
java.io.Serializable
,Callable
,ConstProperties
,DebuggableObject
,Function
,IdFunctionCall
,Scriptable
,SymbolScriptable
- Direct Known Subclasses:
FieldAndMethods
public class NativeJavaMethod extends BaseFunction
This class reflects Java methods into the JavaScript environment and handles overloading of methods.- See Also:
NativeJavaArray
,NativeJavaPackage
,NativeJavaClass
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.mozilla.javascript.ScriptableObject
ScriptableObject.GetterSlot, ScriptableObject.KeyComparator, ScriptableObject.Slot, ScriptableObject.SlotAccess
-
-
Field Summary
Fields Modifier and Type Field Description private static boolean
debug
private java.lang.String
functionName
(package private) MemberBox[]
methods
private java.util.concurrent.CopyOnWriteArrayList<ResolvedOverload>
overloadCache
private static int
PREFERENCE_AMBIGUOUS
No clear "easy" conversionprivate static int
PREFERENCE_EQUAL
Types are equalprivate static int
PREFERENCE_FIRST_ARG
private static int
PREFERENCE_SECOND_ARG
private static long
serialVersionUID
-
Fields inherited from class org.mozilla.javascript.BaseFunction
GENERATOR_FUNCTION_CLASS
-
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
Constructors Constructor Description NativeJavaMethod(java.lang.reflect.Method method, java.lang.String name)
NativeJavaMethod(MemberBox[] methods)
NativeJavaMethod(MemberBox[] methods, java.lang.String name)
NativeJavaMethod(MemberBox method, java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
call(Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args)
Should be overridden.(package private) java.lang.String
decompile(int indent, int flags)
Decompile the source information associated with this js function/script back into a string.(package private) int
findCachedFunction(Context cx, java.lang.Object[] args)
(package private) static int
findFunction(Context cx, MemberBox[] methodsOrCtors, java.lang.Object[] args)
Find the index of the correct function to call given the set of methods or constructors and the arguments.java.lang.String
getFunctionName()
private static int
preferSignature(java.lang.Object[] args, java.lang.Class<?>[] sig1, boolean vararg1, java.lang.Class<?>[] sig2, boolean vararg2)
Determine which of two signatures is the closer fit.private static void
printDebug(java.lang.String msg, MemberBox member, java.lang.Object[] args)
(package private) static java.lang.String
scriptSignature(java.lang.Object[] values)
java.lang.String
toString()
-
Methods inherited from class org.mozilla.javascript.BaseFunction
construct, createObject, execIdCall, fillConstructorProperties, findInstanceIdInfo, findPrototypeId, getArity, getClassName, getClassPrototype, getInstanceIdName, getInstanceIdValue, getLength, getMaxInstanceId, getPrototypeProperty, getTypeOf, hasInstance, hasPrototypeProperty, init, initAsGeneratorFunction, initPrototypeId, isApply, isApplyOrCall, isGeneratorFunction, setImmunePrototypeProperty, setInstanceIdAttributes, setInstanceIdValue
-
Methods inherited from class org.mozilla.javascript.IdScriptableObject
activatePrototypeMap, addIdFunctionProperty, defaultGet, defaultHas, defaultPut, defineOwnProperty, delete, delete, exportAsJSClass, findInstanceIdInfo, findPrototypeId, get, get, getAttributes, getAttributes, getIds, getOwnPropertyDescriptor, has, has, hasPrototypeMap, incompatibleCallError, initPrototypeConstructor, initPrototypeMethod, initPrototypeMethod, initPrototypeMethod, initPrototypeValue, initPrototypeValue, instanceIdInfo, put, put, setAttributes
-
Methods inherited from class org.mozilla.javascript.ScriptableObject
addLazilyInitializedValue, applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildClassCtor, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, checkValidAttributes, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, 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, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, 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, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
PREFERENCE_EQUAL
private static final int PREFERENCE_EQUAL
Types are equal- See Also:
- Constant Field Values
-
PREFERENCE_FIRST_ARG
private static final int PREFERENCE_FIRST_ARG
- See Also:
- Constant Field Values
-
PREFERENCE_SECOND_ARG
private static final int PREFERENCE_SECOND_ARG
- See Also:
- Constant Field Values
-
PREFERENCE_AMBIGUOUS
private static final int PREFERENCE_AMBIGUOUS
No clear "easy" conversion- See Also:
- Constant Field Values
-
debug
private static final boolean debug
- See Also:
- Constant Field Values
-
methods
MemberBox[] methods
-
functionName
private java.lang.String functionName
-
overloadCache
private final transient java.util.concurrent.CopyOnWriteArrayList<ResolvedOverload> overloadCache
-
-
Constructor Detail
-
NativeJavaMethod
NativeJavaMethod(MemberBox[] methods)
-
NativeJavaMethod
NativeJavaMethod(MemberBox[] methods, java.lang.String name)
-
NativeJavaMethod
NativeJavaMethod(MemberBox method, java.lang.String name)
-
NativeJavaMethod
public NativeJavaMethod(java.lang.reflect.Method method, java.lang.String name)
-
-
Method Detail
-
getFunctionName
public java.lang.String getFunctionName()
- Overrides:
getFunctionName
in classBaseFunction
-
scriptSignature
static java.lang.String scriptSignature(java.lang.Object[] values)
-
decompile
java.lang.String decompile(int indent, int flags)
Description copied from class:BaseFunction
Decompile the source information associated with this js function/script back into a string.- Overrides:
decompile
in classBaseFunction
- Parameters:
indent
- How much to indent the decompiled result.flags
- Flags specifying format of decompilation output.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
call
public java.lang.Object call(Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args)
Description copied from class:BaseFunction
Should be overridden.- Specified by:
call
in interfaceCallable
- Specified by:
call
in interfaceFunction
- Overrides:
call
in classBaseFunction
- Parameters:
cx
- the current Context for this threadscope
- 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 JavaScriptthis
objectargs
- the array of arguments- Returns:
- the result of the call
-
findCachedFunction
int findCachedFunction(Context cx, java.lang.Object[] args)
-
findFunction
static int findFunction(Context cx, MemberBox[] methodsOrCtors, java.lang.Object[] args)
Find the index of the correct function to call given the set of methods or constructors and the arguments. If no function can be found to call, return -1.
-
preferSignature
private static int preferSignature(java.lang.Object[] args, java.lang.Class<?>[] sig1, boolean vararg1, java.lang.Class<?>[] sig2, boolean vararg2)
Determine which of two signatures is the closer fit. Returns one of PREFERENCE_EQUAL, PREFERENCE_FIRST_ARG, PREFERENCE_SECOND_ARG, or PREFERENCE_AMBIGUOUS.
-
printDebug
private static void printDebug(java.lang.String msg, MemberBox member, java.lang.Object[] args)
-
-