Global variables overriding Python code.

50 views
Skip to first unread message

brandon mcginty

unread,
Dec 29, 2012, 4:16:06 PM12/29/12
to py...@googlegroups.com
Good afternoon.
First, my thanks to the developers and contributors to this project.
PyV8 is the only library making this project possible.
I am developing a text-based web browser with python and PyV8,
partially modeled off of the w3c demo included with PyV8.
There are a couple issues I've encountered with PyV8, which I'll post
one at a time, so that I can be sure that one issue isn't causing
another.

I've got a large number of properties that are read only, both to
python and javascript, as well as propertys whose setters perform some
crutial function.
(For example, the python code for the window.location setter insures
that a complete url is set, no matter what javascript sends. This
doesn't work, because of the below issue.)
On objects that are nested inside the global object, e.g. any
non-global object, getters and setters work correctly.
However, any propertys set on the global object do not have there
accessors triggered when values are set to them.
Any suggestions you all might have are appreciated.
Code and output are below.

Sincerely,
Brandon McGinty-Carroll


Code:
import PyV8
class glob(object):
prop2text="accessor text for prop 2. This text should be appended to
any new text set to the prop2 attribute."
def __init__(self,*a):
self.a=a
self.sub=subobj()
@property
def prop(self):
return "accessor test for glob.prop. there is no setter for `prop`,
so this text should never change."
@property
def prop2(self):
# print self.prop2text
return self.prop2text
@prop2.setter
def prop2(self,x):
self.prop2text=x+" "+self.prop2

class subobj(glob):
def __init__(self,*a):
print "init subobject"
self.a=a

c=PyV8.JSContext(glob(1,2,3))
c.enter()
c.eval("prop")
c.eval("prop=5059923")
c.eval("prop")
c.eval("prop2")
c.eval("prop2='This is new text.'")
c.eval("prop2")
c.eval("prop2='This is more new text.'")
c.eval("prop2")

c.eval("sub.prop")
c.eval("sub.prop=5059923")
c.eval("sub.prop")
c.eval("sub.prop2")
c.eval("sub.prop2='This is new text.'")
c.eval("sub.prop2")
c.eval("sub.prop2='This is more new text.'")
c.eval("sub.prop2")



output:
>>> c=PyV8.JSContext(glob(1,2,3))
init subobject
>>> c.enter()
>>> c.eval("prop")
'accessor test for glob.prop. there is no setter for `prop`, so this
text should never change.'
>>> c.eval("prop=5059923")
5059923
>>> c.eval("prop")
5059923
>>> c.eval("prop2")
'accessor text for prop 2. This text should be appended to any new
text set to the prop2 attribute.'
>>> c.eval("prop2='This is new text.'")
'This is new text.'
>>> c.eval("prop2")
'This is new text.'
>>> c.eval("prop2='This is more new text.'")
'This is more new text.'
>>> c.eval("prop2")
'This is more new text.'
>>>
>>> c.eval("sub.prop")
'accessor test for glob.prop. there is no setter for `prop`, so this
text should never change.'
>>> c.eval("sub.prop=5059923")
.eval("suTraceback (most recent call last):
File "<stdin>", line 1, in <module>
ReferenceError: ReferenceError: can't set attribute ( @ 1 : 8 ) ->
sub.prop=5059923
>>> c.eval("sub.prop")
'accessor test for glob.prop. there is no setter for `prop`, so this
text should never change.'
>>> c.eval("sub.prop2")
'accessor text for prop 2. This text should be appended to any new
text set to the prop2 attribute.'
>>> c.eval("sub.prop2='This is new text.'")
'This is new text.'
>>> c.eval("sub.prop2")
'This is new text. accessor text for prop 2. This text should be
appended to any new text set to the prop2 attribute.'
>>> c.eval("sub.prop2='This is more new text.'")
'This is more new text.'
>>> c.eval("sub.prop2")
'This is more new text. This is new text. accessor text for prop 2.
This text should be appended to any new text set to the prop2
attribute.'
Reply all
Reply to author
Forward
0 new messages