[pypy-svn] r28437 - in pypy/dist/pypy/translator/js2: . modules test
fijal at codespeak.net
fijal at codespeak.net
Wed Jun 7 13:37:42 CEST 2006
Author: fijal
Date: Wed Jun 7 13:37:41 2006
New Revision: 28437
Modified:
pypy/dist/pypy/translator/js2/metavm.py
pypy/dist/pypy/translator/js2/modules/dom.py
pypy/dist/pypy/translator/js2/test/test_dom.py
Log:
Improved dom tests. Really strange hacks around setTimeout
Modified: pypy/dist/pypy/translator/js2/metavm.py
==============================================================================
--- pypy/dist/pypy/translator/js2/metavm.py (original)
+++ pypy/dist/pypy/translator/js2/metavm.py Wed Jun 7 13:37:41 2006
@@ -158,12 +158,15 @@
# FIXME: Dirty hack for javascript callback stuff
def render(self, generator, op):
val = op.args[1].value
- if isinstance(val, ootype.StaticMethod):
- real_name = val._name
- generator.db.pending_function(val.graph)
- else:
- real_name = val.concretize().value._name
- generator.db.pending_function(val.concretize().value.graph)
+ assert(isinstance(val, ootype._static_meth))
+ #if isinstance(val, ootype.StaticMethod):
+ real_name = val._name
+ generator.db.pending_function(val.graph)
+ #generator.db.pending_function(val.graph)
+ #else:
+ # concrete = val.concretize()
+ # real_name = concrete.value._name
+ # generator.db.pending_function(concrete.value.graph)
generator.load_str("'%s()'" % real_name)
generator.load(op.args[2])
generator.call_external('setTimeout',[0]*2)
Modified: pypy/dist/pypy/translator/js2/modules/dom.py
==============================================================================
--- pypy/dist/pypy/translator/js2/modules/dom.py (original)
+++ pypy/dist/pypy/translator/js2/modules/dom.py Wed Jun 7 13:37:41 2006
@@ -8,6 +8,8 @@
import time
+from pypy.translator.stackless.test.test_transform import one
+
class Style(object):
_rpython_hints = {'_suggested_external' : True}
@@ -22,9 +24,14 @@
def __init__(self):
self.innerHTML = ""
self.style = None
+ self.subnodes = {}
def getElementById(self, id):
- return Node()
+ try:
+ return self.subnodes[id]
+ except KeyError:
+ self.subnodes[id] = Node()
+ return self.subnodes[id]
def setAttribute(self, name, style_str):
if name == 'style':
@@ -37,8 +44,15 @@
document = Node()
+def some_fun():
+ pass
+
def setTimeout(func, delay):
# scheduler call, but we don't want to mess with threads right now
- func()
+ if one():
+ setTimeout(some_fun, delay)
+ else:
+ func()
+ #pass
setTimeout.suggested_primitive = True
Modified: pypy/dist/pypy/translator/js2/test/test_dom.py
==============================================================================
--- pypy/dist/pypy/translator/js2/test/test_dom.py (original)
+++ pypy/dist/pypy/translator/js2/test/test_dom.py Wed Jun 7 13:37:41 2006
@@ -23,10 +23,11 @@
assert fn() == '[object HTMLHeadingElement]'
class Mover(object):
- def __init__(self):
+ def __init__(self, elem):
self.x = 0
self.y = 0
self.dir = 1
+ self.elem = elem#get_document().getElementById(elem)
def move_it_by(self, obj, dx, dy):
if self.dir < 0:
@@ -42,19 +43,24 @@
obj.style.top = str(int(obj.style.top) + dy) + "px"
def move_it(self):
- self.move_it_by(get_document().getElementById("anim_img"), 3, 3)
+ #self.move_it_by(self.elem, 3, 3)
+ self.move_it_by(get_document().getElementById(self.elem), 3, 3)
-movers = [Mover(), Mover()]
+movers = [Mover("anim_img"), Mover("anim_img2")]
+movers[1].x = 20
def move_it():
movers[0].move_it()
- setTimeout(move_it, 10)
+ movers[1].move_it()
-def test_anim_f():
+def test_anim_f():
def anim_fun():
obj = get_document().getElementById("anim_img")
obj.setAttribute('style', 'position: absolute; top: 0; left: 0;')
- setTimeout(move_it, 10)
+ obj2 = get_document().getElementById("anim_img2")
+ obj2.setAttribute('style', 'position: absolute; top: 50; left: 0;')
+ move_it()
+ return get_document().getElementById("anim_img").style.left
- fn = compile_function(anim_fun, [], html = 'html/anim.html', is_interactive = True)
- assert fn() == 'ok'
+ fn = compile_function(anim_fun, [], html = 'html/anim.html')
+ assert fn() == '3px'
More information about the Pypy-commit
mailing list