[pypy-svn] r37804 - in pypy/dist/pypy/translator/js: examples modules test

fijal at codespeak.net fijal at codespeak.net
Fri Feb 2 13:16:50 CET 2007


Author: fijal
Date: Fri Feb  2 13:16:46 2007
New Revision: 37804

Added:
   pypy/dist/pypy/translator/js/test/test_extfunc.py
Modified:
   pypy/dist/pypy/translator/js/examples/start_bnb.py
   pypy/dist/pypy/translator/js/modules/dom.py
Log:
Move setTimeout to new extfunc interface


Modified: pypy/dist/pypy/translator/js/examples/start_bnb.py
==============================================================================
--- pypy/dist/pypy/translator/js/examples/start_bnb.py	(original)
+++ pypy/dist/pypy/translator/js/examples/start_bnb.py	Fri Feb  2 13:16:46 2007
@@ -92,7 +92,6 @@
     def hide_sprite(self, s):
         i = self.sprites[s]
         i.style.visibility = "hidden"
-        #pass
     
     def start_clean_sprites(self):
         self.all_sprites = {}
@@ -141,14 +140,14 @@
 km = KeyManager()
 
 def appendPlayfield(msg):
-    bgcolor = '#000000'
+    bgcolor = '#FFF'
     document.body.setAttribute('bgcolor', bgcolor)
     div = document.createElement("div")
     div.setAttribute("id", "playfield")
     div.setAttribute('width', msg['width'])
     div.setAttribute('height', msg['height'])
     div.setAttribute('style', 'position:absolute; top:0px; left:0px')
-    document.body.appendChild(div)
+    document.body.childNodes.insert(0, div)
 
 def appendPlayfieldXXX():
     bgcolor = '#000000'

Modified: pypy/dist/pypy/translator/js/modules/dom.py
==============================================================================
--- pypy/dist/pypy/translator/js/modules/dom.py	(original)
+++ pypy/dist/pypy/translator/js/modules/dom.py	Fri Feb  2 13:16:46 2007
@@ -21,7 +21,8 @@
 from pypy.rpython.ootypesystem.bltregistry import BasicExternal, MethodDesc
 from pypy.rlib.nonconst import NonConstant
 
-from pypy.translator.stackless.test.test_transform import one
+#from pypy.translator.stackless.test.test_transform import one
+from pypy.rpython.extfunc import _callable, register_external
 from xml.dom import minidom
 
 from pypy.annotation.signature import annotation
@@ -306,12 +307,10 @@
 
 def some_fun():
     pass
-    
+
 def setTimeout(func, delay):
-    if one():
-        setTimeout(some_fun, delay)
-    else:
-        func()
+    pass
+register_external(setTimeout, args=[_callable([]), int], result=None)
 
 window = Window()
 document = window.document
@@ -700,6 +699,7 @@
     'shiftKey': bool,
 })
 
+# XXX: Right now this is only way to get it rendered
 setTimeout.suggested_primitive = True
 
 # the following code wraps minidom nodes with Node classes, and makes

Added: pypy/dist/pypy/translator/js/test/test_extfunc.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js/test/test_extfunc.py	Fri Feb  2 13:16:46 2007
@@ -0,0 +1,18 @@
+
+""" Some external functions tests
+"""
+
+from pypy.translator.js.test.runtest import compile_function, check_source_contains
+from pypy.rpython.extfunc import _callable
+
+def test_set_timeout():
+    from pypy.translator.js.modules.dom import setTimeout
+    
+    def to_timeout():
+        pass
+    
+    def s_timeout_call():
+        setTimeout(to_timeout, 300)
+
+    c = compile_function(s_timeout_call, [])
+    assert check_source_contains(c, "setTimeout \( 'to_timeout\(\)',300 \)")



More information about the Pypy-commit mailing list