From 33b74641f5db8a22e402a3fa787ed6c825ec01da Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Sat, 25 Sep 2004 09:24:43 +0000 Subject: [PATCH] For compatibility allow jsFunction_* to return non-scriptable type. Not to perform type conversion checks for methods that do return proper JS type the type check is done only once in the constructor and if necessary a flag is set to call WrapFaactory.wrap on method return. --- .../mozilla/javascript/FunctionObject.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/js/rhino/src/org/mozilla/javascript/FunctionObject.java b/js/rhino/src/org/mozilla/javascript/FunctionObject.java index f917148d7674..bff47b619c1e 100644 --- a/js/rhino/src/org/mozilla/javascript/FunctionObject.java +++ b/js/rhino/src/org/mozilla/javascript/FunctionObject.java @@ -173,12 +173,7 @@ public class FunctionObject extends BaseFunction if (returnType == Void.TYPE) { hasVoidReturn = true; } else { - int returnTypeTag = getTypeTag(returnType); - if (returnTypeTag == JAVA_UNSUPPORTED_TYPE) { - throw Context.reportRuntimeError2( - "msg.bad.method.return", - returnType.getName(), methodName); - } + returnTypeTag = getTypeTag(returnType); } member.prepareInvokerOptimization(); } else { @@ -446,6 +441,9 @@ public class FunctionObject extends BaseFunction Object result; if (member.isMethod()) { result = member.invoke(thisObj, invokeArgs); + if (returnTypeTag == JAVA_UNSUPPORTED_TYPE) { + result = cx.getWrapFactory().wrap(cx, scope, result, null); + } } else { result = member.newInstance(invokeArgs); } @@ -510,6 +508,15 @@ public class FunctionObject extends BaseFunction typeTags[i] = (byte)getTypeTag(types[i]); } } + if (member.isMethod()) { + Method method = member.method(); + Class returnType = method.getReturnType(); + if (returnType == Void.TYPE) { + hasVoidReturn = true; + } else { + returnTypeTag = getTypeTag(returnType); + } + } } private static final short VARARGS_METHOD = -1; @@ -526,8 +533,9 @@ public class FunctionObject extends BaseFunction public static final int JAVA_OBJECT_TYPE = 6; MemberBox member; - transient private byte[] typeTags; + private transient byte[] typeTags; private int parmsLength; - private boolean hasVoidReturn; + private transient boolean hasVoidReturn; + private transient int returnTypeTag; private boolean isStatic; }