1
from __future__ import division
4
from pypy.translator.js.test.runtest import compile_function
5
from pypy.rpython.lltypesystem import lltype
6
from pypy.rlib.rjs import jseval
7
from pypy.translator.js import conftest
14
getDate = jsnative("new Date().getDate()")
15
getTime = jsnative("Math.floor(new Date().getTime())")
22
jseval1_fn = compile_function(jseval1, [str])
24
assert jseval1_fn(e) == eval(e)
27
from time import localtime
33
jsnative1_fn = compile_function(jsnative1, [])
34
assert jsnative1_fn() == localtime()[2]
37
#n_times_called = lltype.malloc(lltype.GcArray(lltype.Signed), 1)
40
def callback_function():
41
n_times_called[0] += 1
42
jseval("document.title=" + str(n_times_called[0]))
43
jseval("setTimeout('callback_function()', 100)")
45
def test_register_callback():
47
if not conftest.option.browser:
48
py.test.skip("works only in a browser (use py.test --browser)")
50
def register_callback():
51
callback_function() #..start timer
52
start_time = current_time = int(getTime())
53
while current_time - start_time < 1000:
54
current_time = int(getTime())
55
return n_times_called[0]
57
register_callback_fn = compile_function(register_callback, [])
58
result = register_callback_fn()