On Mar 25, 9:59 pm, helge <[EMAIL PROTECTED]> wrote: > On Mar 25, 3:58 pm, Norris Boyd <[EMAIL PROTECTED]> wrote: > > > So the question is then what WrapFactory.wrap() should do. > > Well, IMHO jsToJava and javaToJs should always lead to consistent > results? IMHO there should be no question on that. > > Actually I think that NativeJavaClass should do both, static methods/ > vars AND the reflection methods. Maybe exposing a child object > (__reflect__ and __static__?) if names would clash (unlikely). > > Anyways, thanks for the explanation, I somehow (how?! ;-) forgot that > static is not the same like class methods. > > > So I think WrapFactory.wrap() does the right thing now, but I can see > > a missing piece of functionality in the API. How does this come up for > > you? What are you trying to do? > > Puh ;-) Basically I use a Map to store the values of a scope on the > Java side. You can imagine it like using a regular Map<String,Object> > as the slot store (with the values being converted to/from Java). > Actually its NativeJavaObject subclasses which expose the Java API but > also allow attaching additional JS slots (functions, etc). You can > find the relevant source (WrapFactory etc) here: > > http://getobjects.googlecode.com/svn/core/trunk/org/getobjects/jsapp/ > > The setup is a bit complex due to caching of .js files in shared > scopes. Anyways, because I map back and forth, Classes get mixed up > with strange effects (eg static methods are available on the first > run, but get lost on subsequent runs. most likely because some > representation is 'cached' and enters the a/b/c loop). > > Right now everything works as expected after I manually added the > java.lang.Class=>NativeJavaClass conversion in my WrapFactory: > http://getobjects.googlecode.com/svn/core/trunk/org/getobjects/jsapp/... > > Thinking about it, I really suggest that there should be just one > object representing Java classes in JS. > > Thanks, > Helge > --http://www.helgehess.eu/
You're right that it's unfortunate that jsToJava and javaToJS don't roundtrip. The fundamental problem is that there are two namespaces, the static class and the class object, and Java only has an object representation for the latter. JavaScript has object representations for both and so it's not possible to construct a round trip given these limitations. So you're proposing unifying the class object and the static class namespaces? That definitely wouldn't work as far as its impact on backwards compatibility, and it would seem counterintuitive to have, for example, java.lang.String.valueOf(...) and java.lang.String.getConstructors() both be valid. Your change to your custom WrapFactory doesn't seem like it would work if you had a class object in the map as it would be mapped to a class. What if you just used the scope's storage rather than creating your own map, or if you stored the values from the scope in your map without calling jsToJava? --N _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
