Subj : Re: Access a property faster To : Egor Senin From : Igor Bukanov Date : Thu Nov 18 2004 11:50 am Egor Senin wrote: > Igor Bukanov wrote in message news:<419BA6A6.1080709@fastmail.fm>... > >>Egor Senin wrote: >> >>>... >>>Is there any other way to retrive property without a script-class >>>compilation but with all required traverses of prototype chain and >>>parent scopes, something like ctx.getProperty(myScriptable, >>>"propertyName"); >> >>Use ScriptableObject.getProperty(myScriptable, "properyName"), >>http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/ScriptableObject.html#getProperty(org.mozilla.javascript.Scriptable,%20java.lang.String) > > > Hmm, it seems that this method doesn't traverse parent scopes, just > prototype chain ... Sorry, I had to mention that I need any native > objects or variables returned too when it's name is specified. > > Consider the call ctx.evaluateString(myScriptable, "Math", > "NowNativeObjectAccess", 1, null); > > It returns Math object after the top scope is reached. > > So, which code I should write in order to fully emulate the presented > ctx.evaluateString() call? There is no public API in Rhino for that. As a workarround you can code explicit scope lookup like in: Object result; do { result = ScriptableObject.getProperty(myScriptable, "properyName"); if (result != Scriptable.NOT_FOUND) break; myScriptable = myScriptable.getParentScope(); } while (myScriptable != null); Regards, Igor .