Class JavaAdapter
java.lang.Object
org.mozilla.javascript.JavaAdapter
- All Implemented Interfaces:
IdFunctionCall
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
Provides a key with which to distinguish previously generated adapter classes stored in a hash table. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static int
appendMethodSignature
(Class<?>[] argTypes, Class<?> returnType, StringBuilder sb) private static void
private static StringBuilder
appendTypeString
(StringBuilder sb, Class<?> type) static Object
callMethod
(ContextFactory factory, Scriptable thisObj, Function f, Object[] args, long argsToWrap) Utility method which dynamically binds a Context to the current thread, if none already exists.static Object
convertResult
(Object result, Class<?> c) static byte[]
createAdapterCode
(ObjToIntMap functionNames, String adapterName, Class<?> superClass, Class<?>[] interfaces, String scriptClassName) static Scriptable
createAdapterWrapper
(Scriptable obj, Object adapter) private static Object
doCall
(Context cx, Scriptable scope, Scriptable thisObj, Function f, Object[] args, long argsToWrap) 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 returnedprivate static void
generateCtor
(ClassFileWriter cfw, String adapterName, String superName, Constructor<?> superCtor) private static void
generateEmptyCtor
(ClassFileWriter cfw, String adapterName, String superName, String scriptClassName) private static void
generateMethod
(ClassFileWriter cfw, String genName, String methodName, Class<?>[] parms, Class<?> returnType, boolean convertResult) private static void
generatePopResult
(ClassFileWriter cfw, Class<?> retType) Generates code to return a Java type, after calling a Java method that returns the same type.private static int
generatePushParam
(ClassFileWriter cfw, int paramOffset, Class<?> paramType) Generates code to push typed parameters onto the operand stack prior to a direct Java method call.(package private) static void
generatePushWrappedArgs
(ClassFileWriter cfw, Class<?>[] argTypes, int arrayLength) Generates code to wrap Java arguments into Object[].(package private) static void
generateReturnResult
(ClassFileWriter cfw, Class<?> retType, boolean callConvertResult) Generates code to convert a wrapped value type to a primitive type.private static void
generateSerialCtor
(ClassFileWriter cfw, String adapterName, String superName) private static void
generateSuper
(ClassFileWriter cfw, String genName, String superName, String methodName, String methodSignature, Class<?>[] parms, Class<?> returnType) Generates a method called "super$methodName()" which can be called from JavaScript that is equivalent to calling "super.methodName()" from Java.private static int
generateWrapArg
(ClassFileWriter cfw, int paramOffset, Class<?> argType) Generates code to wrap Java argument into Object.private static Class
<?> getAdapterClass
(Scriptable scope, Class<?> superClass, Class<?>[] interfaces, Scriptable obj) static Object
getAdapterSelf
(Class<?> adapterClass, Object adapter) (package private) static int[]
getArgsToConvert
(Class<?>[] argTypes) static Function
getFunction
(Scriptable obj, String functionName) private static String
getMethodSignature
(Method method, Class<?>[] argTypes) Returns a fully qualified method name concatenated with its signature.private static ObjToIntMap
(package private) static Method[]
getOverridableMethods
(Class<?> clazz) static void
init
(Context cx, Scriptable scope, boolean sealed) (package private) static Object
js_createAdapter
(Context cx, Scriptable scope, Object[] args) (package private) static Class
<?> loadAdapterClass
(String className, byte[] classBytes) static Object
readAdapterObject
(Scriptable self, ObjectInputStream in) static Scriptable
static void
writeAdapterObject
(Object javaObject, ObjectOutputStream out)
-
Field Details
-
FTAG
-
Id_JavaAdapter
private static final int Id_JavaAdapter- See Also:
-
-
Constructor Details
-
JavaAdapter
public JavaAdapter()
-
-
Method Details
-
init
-
execIdCall
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) Description copied from interface:IdFunctionCall
'thisObj' will be null if invoked as constructor, in which case instance of Scriptable should be returned- Specified by:
execIdCall
in interfaceIdFunctionCall
-
convertResult
-
createAdapterWrapper
-
getAdapterSelf
public static Object getAdapterSelf(Class<?> adapterClass, Object adapter) throws NoSuchFieldException, IllegalAccessException -
js_createAdapter
-
writeAdapterObject
- Throws:
IOException
-
readAdapterObject
public static Object readAdapterObject(Scriptable self, ObjectInputStream in) throws IOException, ClassNotFoundException - Throws:
IOException
ClassNotFoundException
-
getObjectFunctionNames
-
getAdapterClass
private static Class<?> getAdapterClass(Scriptable scope, Class<?> superClass, Class<?>[] interfaces, Scriptable obj) -
createAdapterCode
public static byte[] createAdapterCode(ObjToIntMap functionNames, String adapterName, Class<?> superClass, Class<?>[] interfaces, String scriptClassName) -
getOverridableMethods
-
appendOverridableMethods
-
loadAdapterClass
-
getFunction
-
callMethod
public static Object callMethod(ContextFactory factory, Scriptable thisObj, Function f, Object[] args, long argsToWrap) Utility method which dynamically binds a Context to the current thread, if none already exists. -
doCall
private static Object doCall(Context cx, Scriptable scope, Scriptable thisObj, Function f, Object[] args, long argsToWrap) -
runScript
-
generateCtor
private static void generateCtor(ClassFileWriter cfw, String adapterName, String superName, Constructor<?> superCtor) -
generateSerialCtor
-
generateEmptyCtor
private static void generateEmptyCtor(ClassFileWriter cfw, String adapterName, String superName, String scriptClassName) -
generatePushWrappedArgs
Generates code to wrap Java arguments into Object[]. Non-primitive Java types are left as-is pending conversion in the helper method. Leaves the array object on the top of the stack. -
generateWrapArg
Generates code to wrap Java argument into Object. Non-primitive Java types are left unconverted pending conversion in the helper method. Leaves the wrapper object on the top of the stack. -
generateReturnResult
Generates code to convert a wrapped value type to a primitive type. Handles unwrapping java.lang.Boolean, and java.lang.Number types. Generates the appropriate RETURN bytecode. -
generateMethod
private static void generateMethod(ClassFileWriter cfw, String genName, String methodName, Class<?>[] parms, Class<?> returnType, boolean convertResult) -
generatePushParam
Generates code to push typed parameters onto the operand stack prior to a direct Java method call. -
generatePopResult
Generates code to return a Java type, after calling a Java method that returns the same type. Generates the appropriate RETURN bytecode. -
generateSuper
private static void generateSuper(ClassFileWriter cfw, String genName, String superName, String methodName, String methodSignature, Class<?>[] parms, Class<?> returnType) Generates a method called "super$methodName()" which can be called from JavaScript that is equivalent to calling "super.methodName()" from Java. Eventually, this may be supported directly in JavaScript. -
getMethodSignature
-
appendMethodSignature
-
appendTypeString
-
getArgsToConvert
-