Class JavaAdapter
java.lang.Object
org.mozilla.javascript.JavaAdapter
- All Implemented Interfaces:
IdFunctionCall
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classProvides 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 intappendMethodSignature(Class<?>[] argTypes, Class<?> returnType, StringBuilder sb) private static voidprivate static StringBuilderappendTypeString(StringBuilder sb, Class<?> type) static ObjectcallMethod(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 ObjectconvertResult(Object result, Class<?> c) static byte[]createAdapterCode(ObjToIntMap functionNames, String adapterName, Class<?> superClass, Class<?>[] interfaces, String scriptClassName) static ScriptablecreateAdapterWrapper(Scriptable obj, Object adapter) private static ObjectdoCall(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 voidgenerateCtor(ClassFileWriter cfw, String adapterName, String superName, Constructor<?> superCtor) private static voidgenerateEmptyCtor(ClassFileWriter cfw, String adapterName, String superName, String scriptClassName) private static voidgenerateMethod(ClassFileWriter cfw, String genName, String methodName, Class<?>[] parms, Class<?> returnType, boolean convertResult) private static voidgeneratePopResult(ClassFileWriter cfw, Class<?> retType) Generates code to return a Java type, after calling a Java method that returns the same type.private static intgeneratePushParam(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 voidgeneratePushWrappedArgs(ClassFileWriter cfw, Class<?>[] argTypes, int arrayLength) Generates code to wrap Java arguments into Object[].(package private) static voidgenerateReturnResult(ClassFileWriter cfw, Class<?> retType, boolean callConvertResult) Generates code to convert a wrapped value type to a primitive type.private static voidgenerateSerialCtor(ClassFileWriter cfw, String adapterName, String superName) private static voidgenerateSuper(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 intgenerateWrapArg(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 ObjectgetAdapterSelf(Class<?> adapterClass, Object adapter) (package private) static int[]getArgsToConvert(Class<?>[] argTypes) static FunctiongetFunction(Scriptable obj, String functionName) private static StringgetMethodSignature(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 voidinit(Context cx, Scriptable scope, boolean sealed) (package private) static Objectjs_createAdapter(Context cx, Scriptable scope, Object[] args) (package private) static Class<?> loadAdapterClass(String className, byte[] classBytes) static ObjectreadAdapterObject(Scriptable self, ObjectInputStream in) static Scriptablestatic voidwriteAdapterObject(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:
execIdCallin 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:
IOExceptionClassNotFoundException
-
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
-