The first question was caused by a design problem. Because PyV8
support to use a Python map object as a Javascript object. It means,
if you pass a map object to Javascript, and get/set its property, if
the property doesn't exists, the value will be read from or add to the
map. To implement it, pyv8 must use PyObject_HasAttrString to check
whether the property exists, which will call the __getattr__. So, if
the behavior real broke your code, I think we could remove the check
code, and force to get/set value when the object is a python map
object.
The second question was caused by the Javascript standard. When you
try to get a property that doesn't exists, Javascript should return
undefined. It means, even you raise a exception from Python part, pyv8
will catch the exception and just return a undefined to Javascript
code. You could try to comment the "y.z=10" line
def __getattr__(self, name):
print "Get Attribute: %s" % name
if name == 'constructor':
return JSClassConstructor(self.__class__)
print "here"
raise AttributeError(name)
with PyV8.JSContext(Global()) as ctx:
ctx.eval("""
write(x);
//y.z = 10;
write("z="+z);
""")
Output:
Get Attribute: z
z=undefined
http://www.ecma-international.org/publications/standards/Ecma-262.htm
8.6.2.1 [[Get]] (P)
When the [[Get]] method of O is called with property name P, the
following steps are taken:
1. If O doesn’t have a property with name P, go to step 4.
2. Get the value of the property.
3. Return Result(2).
4. If the [[Prototype]] of O is null, return undefined.
5. Call the [[Get]] method of [[Prototype]] with property name P.
6. Return Result(5).