Subject:
Rhino reflection patch
Date:
Wed, 28 Jul 1999 18:14:52 -0400
From:
Andrew Wason <aw@softcom.com>
To:
norris@netscape.com
CC:
mccabe@netscape.com, rogerl@netscape.com, Howard Lin <howard@softcom.com>
When JavaAdapter generates an adapter class, it does not take into account
the types of method parameters when wrapping the generated methods arguments.
This means that if a non-public class implements a public interface the
non-public class type will be wrapped instead of the declared public
interface - and methods cannot be invoked via the wrapper.
I have attached sample code (reflect-demo.zip) which shows this. The
JavaScript caller.js generates an adapter implementing the CallerInterface
interface. CallerInterface has a method (doSomething) which takes an
argument of type pkg.Interface. pkg.Target is a non-public class that
implements pkg.Interface. If an instance of pkg.Target is passed to the
CallerInterface adapter doSomething method, an Error is thrown because
pkg.Target.doSomething is called (instead of pkg.Interface.doSomething) and
pkg.Target is not public.
I have attached a patch to Context.java, ScriptRuntime.java and
JavaAdapter.java. I overloaded toObject in Context and ScriptRuntime to
take a 3rd argument which is the declared type of the object being
wrapped. This is passed to NativeJavaObject.wrap so that it generates the
correct wrapper. I changed JavaAdapter.generateOverride to generate
bytecode calling Context.toObject passing the declared Class type of the
argument.
Context.java also includes my previously submitted patch for dealing with
SecurityExceptions and the JavaAdapter property (because this patch has not
been checked into CVS yet).
Andrew
--
Andrew Wason
SoftCom, Inc.
aw@softcom.com
reflect-patch.txt
Name:
reflect-patch.txt
Type:
Plain Text (text/plain)
reflect-demo.zip
Name:
reflect-demo.zip
Type:
Zip Compressed Data (application/x-zip-compressed)
Encoding:
base64