buffer/thug — pull request #69 by Joseph-CHC (2013-09-14 16:21:47+00:00)
Title: Fix infinite recursion problem in Window.__getattr__

Window object has infinite recursion when the following two conditions:

1) Check whether the V8 JSContext has been initialized through __getattr__(). It would be a lookup loop which always calls __getattr__() since the code uses self.context before initializing V8 JSContext.

Fix by: Raise attribute error if __getattribute__() can't find "_context" variable.

2) Get the nonexistent variable or function by "self.context.eval(name)". When V8 JSContext can't find the variable, it will call __getattr__() again. It also becomes a lookup loop.

Fix by: Avoid to call __getattr__() from V8Context internal.

#> python -m cProfile thug.py -l ../samples/Events/testEvent10.html
Before fix:
ncalls tottime percall cumtime percall filename:lineno(function)
588/5 0.193 0.000 0.759 0.152 Window.py:138(__getattr__)
6825 0.003 0.000 0.003 0.000 Window.py:196(window)
616/344 0.378 0.001 0.599 0.002 Window.py:850(context)

After fix:
ncalls tottime percall cumtime percall filename:lineno(function)
55/37 0.014 0.000 0.014 0.000 Window.py:139(__getattr__)
35 0.000 0.000 0.000 0.000 Window.py:206(window)
82/4 0.004 0.000 0.020 0.005 Window.py:860(context)