示例#1
0
def assertv(code, value):
    jsint = interpreter.Interpreter()
    ctx = jsint.w_Global
    try:
        bytecode = JsCode()
        interpreter.load_source(code, '').emit(bytecode)
        func = bytecode.make_js_function()
        code_val = func.run(ExecutionContext([ctx]))
    except ThrowException, excpt:
        code_val = excpt.exception
示例#2
0
def assertp(code, prints):
    l = []
    interpreter.writer = l.append
    jsint = interpreter.Interpreter()
    ctx = jsint.w_Global
    try:
        jsint.run(interpreter.load_source(code, ''))
    except ThrowException, excpt:
        l.append("uncaught exception: "+str(excpt.exception.ToString(ctx)))
示例#3
0
文件: jit.py 项目: prologic/lang-js
    def test_append(self):
        code = """
        function f() {
            for(i = 0; i < 100; i++){
            }
        }
        f();
        """
        jsint = interpreter.Interpreter()
        ctx = jsint.w_Global
        bytecode = JsCode()
        interpreter.load_source(code, '').emit(bytecode)
        func = bytecode.make_js_function()

        def interp_w(c):
            jitdriver.set_param("inlining", True)
            code_val = func.run(ExecutionContext([ctx]))
        interp_w(1)
        self.meta_interp(interp_w, [6], listcomp=True, backendopt=True, listops=True)
示例#4
0
 def runsource(self, source, filename='<input>'):
     try:
         ast = load_source(source, filename)
     except ParseError, exc:
         if exc.source_pos.i == len(source):
             # more input needed
             return True
         else:
             # syntax error
             self.showsyntaxerror(filename, exc)
             return False
示例#5
0
    def runsource(self, source, filename="<input>"):
        """Parse and run source in the interpreter.

        One of these cases can happen:
        1) The input is incorrect. Prints a nice syntax error message.
        2) The input in incomplete. More input is required. Returns None.
        3) The input is complete. Executes the source code.
        """
        try:
            ast = load_source(source, filename)
        except ParseError, exc:
            if exc.source_pos.i == len(source):
                # Case 2
                return True # True means that more input is needed
            else:
                # Case 1
                self.showsyntaxerror(filename, exc)
                return False