def do_test_compile(py, js): js2 = pyjs.compile(py) js2 = trim_js(js2) js = trim_js(js) template = "Test failed:\n%s\n\nExpected:\n\n%s\n\nGot:\n\n%s\n\n" assert js2 == js, template % (py, js, js2)
def jseval(code, **env): """Compiles the given python code and executes the generated javascript code in the given environment. """ ctx = spidermonkey.Runtime().new_context() for k, v in env.items(): ctx.add_global(k, v) jscode = pyjs.compile(code) print jscode.strip() return ctx.execute(jscode)
def __call__(self, code): js = pyjs.compile(code).strip() return js.replace("\n", " ").replace(" ", " ")