marylinh / pyv8

Automatically exported from code.google.com/p/pyv8
0 stars 0 forks source link

PyV8 calling __getattr__ twice for attributes #39

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
http://groups.google.com/group/pyv8/browse_thread/thread/508a525518ba
3747?hl=en

dieresys    
View profile  
 More options Mar 2, 6:13 am
I'm trying to analyze chunks of javascript without providing the 
object model. I've found that if the global object defines a 
"__getattr__" method, it's called twice for each undefined attributes 
found in the script. 
For example: 
------------------------------------------------------------------------ 
import PyV8 
class Global(PyV8.JSClass): 
    def __getattr__(self, name): 
        print name 
        return self 
    def alert(self, value): 
        print value 
js_context = PyV8.JSContext(Global()) 
with js_context: 
    js_context.eval("alert(window.location.href);") 
------------------------------------------------------------------------ 
should print this: 
------------------------------------------------------------------------ 
window 
location 
href 
<__main__.Global object at 0x01C7C610> 
------------------------------------------------------------------------ 
but it's printing: 
------------------------------------------------------------------------ 
window 
window 
location 
location 
href 
href 
<__main__.Global object at 0x01C7C610> 
------------------------------------------------------------------------ 

Original issue reported on code.google.com by flier...@gmail.com on 1 Mar 2010 at 11:05

GoogleCodeExporter commented 9 years ago
only call __getattr__ once when get attribute.

please verify it with SVN code after r246, thanks

Original comment by flier...@gmail.com on 20 Mar 2010 at 2:45

GoogleCodeExporter commented 9 years ago
Verified. Thanks!

Original comment by mmura...@dieresys.com.ar on 22 Mar 2010 at 2:50

GoogleCodeExporter commented 9 years ago
You are welcome :)

Original comment by flier...@gmail.com on 22 Mar 2010 at 3:45