Subj : Re: [Q] two names for the same Object To : gonzalo From : Igor Bukanov Date : Tue May 13 2003 01:47 pm gonzalo wrote: > CORRECTION for the orinigal post: > > We are using RHINO as a interpreter for JS code found at HTML pages. The > problem we face here is that JS allows multiple names for the same > object, such as: > "button1.name" and "myForm.button1.name" or > "document.myForm.button1.name" > All expresions reefer to the same object. How can I show this to > RHINO?. > > we have processed the DOM model from the HTML document, so before > trying the interpretation we provide the context with the appropriate > object. For example: > > ScriptableObject.defineClass(scope, Document.class); > Scriptable myDocument = cx.newObject(scope, "Document", null); > scope.put("document", scope, myDocument); > > The problem is that we need the compiler (RHINO) to "understand" the hierarchy > and that a given object may have different names. > > Is there a way to do that? One way to do this is not use ScriptableObject.defineClass since to support MSIE DOM fully you do not need to define constructor/prototype hierarchy that the standard JS objects follows. So you can start from an implementation of w3c Document which gives a good starting point and then use Scriptable docWrapper = Context.toObject(instanceOfDocument, scope); ScriptableObject.defineProperty(scope, "document", docWrapper, ScriptableObject.DONTENUM); After this scripts can access documents and its Java methods mapped by Rhino to JS methods and properties. Then you look at org.mozilla.javascript.NativaJavaObject which implements JS wrapper for Java objects and override its has/get/put methods to look for additional properties according to MSIE DOM rules if NativaJavaObject can not find property. can not find Then you subclass WrapFactory to create your custom wrapper and not NativeJavaObject for instances of the Document interfaces. Then you may need to provide custom wrappers for many other DOM interfaces depending on how many MSIE shortcuts you need to implement. Regards, Igor .