def eval(self, context): # for for(var exp1, cond, exp2) if self.declarations is not None: for declaration in self.declarations: declaration.eval(context) # for for(exp1, cond, exp2) if self.start_expression is not None: ref = self.start_expression.eval(context) js.get_value(ref) result_value = js.EMPTY while True: if self.condition is not None: condition_value = js.get_value(self.condition.eval(context)) if not condition_value: return js.Completion(js.NORMAL, result_value, js.EMPTY) stmt = self.statement.eval(context) if stmt.value is not js.EMPTY: result_value = stmt.value if stmt.type is js.BREAK: return js.Completion(js.NORMAL, result_value, js.EMPTY) if js.is_abrupt(stmt) and stmt.type is not js.CONTINUE: return stmt if self.count_expression is not None: count_expression_ref = self.count_expression.eval(context) js.get_value(count_expression_ref)
def eval(self, context): f = js.get_value(self.obj.eval(context)) s = None if (not (self.scope == None)): s = js.get_value(self.scope.eval(context)) return f.call(None, [ js.get_value(argument.eval(context)) for argument in self.argumentss ], scope=s)
def eval(self, context): ref = self.reference.eval(context) value = js.get_value(self.expression.eval(context)) if self.op == '=': js.put_value(ref, value) return value else: new_value = perform_binary_op(self.op[:-1], js.get_value(ref), value) js.put_value(ref, new_value) return new_value
def eval(self, context): left = js.get_value(self.left_expression.eval(context)) right = js.get_value(self.right_expression.eval(context)) if self.op == '*': return left * right elif self.op == '/': return left / right elif self.op == '%': return left % right elif self.op == '+': return left + right elif self.op == '-': return left - right elif self.op == '<<': return left << right elif self.op == '>>': return left >> right elif self.op == '<': return left < right elif self.op == '<=': return left <= right elif self.op == '>': return left > right elif self.op == '>=': return left >= right elif self.op == 'instanceof': # TODO return False elif self.op == 'in': # TODO return False elif self.op == '==': return left == right elif self.op == '!=': return left != right elif self.op == '===': return left == right elif self.op == '!==': return left != right elif self.op == '&': return left & right elif self.op == '^': return left ^ right elif self.op == '|': return left | right elif self.op == '&&': return left and right elif self.op == '||': return left or right else: raise SyntaxError('Unknown binary operand: %r' % self.op)
def eval(self, expression, context=None): if context is None: context = js.ExecutionContext({}) if not isinstance(context, js.ExecutionContext): context = js.ExecutionContext(context) expression_ast = self.parser.parse(expression) return js.get_value(expression_ast.eval(context))
def eval(self, stmt, context=None): if context is None: context = js.ExecutionContext({}) if not isinstance(context, js.ExecutionContext): context = js.ExecutionContext(context) stmt_ast = self.parser.parse(stmt) return js.get_value(stmt_ast.eval(context))
def eval(self, context): if self.expression is None: return js.Completion(js.RETURN, js.UNDEFINED, js.EMPTY) else: return js.Completion(js.RETURN, js.get_value(self.expression.eval(context)), js.EMPTY)
def eval(self, context): result_value = js.EMPTY while True: condition_value = js.get_value(self.condition.eval(context)) if not condition_value: return js.Completion(js.NORMAL, result_value, js.EMPTY) stmt = self.statement.eval(context) if stmt.value is not js.EMPTY: result_value = stmt.value if stmt.type is js.BREAK: return js.Completion(js.NORMAL, result_value, js.EMPTY) elif js.is_abrupt(stmt) and stmt.type is not js.CONTINUE: return stmt
def eval(self, context): cntx = js.ExecutionContext(dict(), parent=context) result_value = js.EMPTY firstst = self.first.eval(cntx) while True: condition_value = js.get_value(self.condition.eval(cntx)) #print("COND",condition_value) if not condition_value: return js.Completion(js.NORMAL, result_value, js.EMPTY) stmt = self.statement.eval(cntx) if stmt.value is not js.EMPTY: result_value = stmt.value if stmt.type is js.BREAK: return js.Completion(js.NORMAL, result_value, js.EMPTY) elif js.is_abrupt(stmt) and stmt.type is not js.CONTINUE: return stmt nextst = self.then.eval(cntx)
def eval(self, context): expr = self.expression.eval(context) value = js.get_value(expr) if self.op == 'delete': # TODO return True elif self.op == 'void': return js.UNDEFINED elif self.op == 'typeof': # TODO return 'object' elif self.op == '++': new_value = value + 1 js.put_value(expr, new_value) return new_value elif self.op == '--': new_value = value - 1 js.put_value(expr, new_value) return new_value elif self.op == 'postfix++': old_value = value js.put_value(expr, old_value + 1) return old_value elif self.op == 'postfix--': old_value = value js.put_value(expr, old_value - 1) return old_value elif self.op == '+': return +value elif self.op == '-': return -value elif self.op == '~': return ~value elif self.op == '!': return not value else: raise SyntaxError('Unknown unary operand: %s' % self.op)
def eval(self, context): condition_value = js.get_value(self.condition.eval(context)) if condition_value: return js.get_value(self.true_expression.eval(context)) else: return js.get_value(self.false_expression.eval(context))
def get_item_value(self, item, context): return js.get_value(item.eval(context)) if item is not None else js.UNDEFINED
def eval(self, context): f = js.get_value(self.obj.eval(context)) return f.call(None, [ js.get_value(argument.eval(context)) for argument in self.arguments ])
def eval(self, context): base_value = js.get_value(self.obj.eval(context)) property_name_value = js.get_value(self.key.eval(context)) return js.Reference(name=property_name_value, base=base_value)
def eval(self, context): items = dict((name, js.get_value(e.eval(context))) for name, e in self.items.items()) return js.Object(items=items)
def get_item_value(self, item, context): return js.get_value( item.eval(context)) if item is not None else js.UNDEFINED
def eval(self, context): condition_value = js.get_value(self.condition.eval(context)) if condition_value: return self.true_statement.eval(context) else: return self.false_statement.eval(context)
def eval(self, context): return js.Completion(js.NORMAL, js.get_value(self.expression.eval(context)), js.EMPTY)
def eval(self, context): ref = self.identifier.eval(context) value = js.get_value(self.initialiser.eval(context)) js.put_value(ref, value) return js.Completion(js.NORMAL, ref.name, js.EMPTY)
def eval(self, context): f = js.get_value(self.obj.eval(context)) return f.call(None, [js.get_value(argument.eval(context)) for argument in self.arguments])
def eval(self, context): # TODO: Ellision return js.Array(items=[js.get_value(item.eval(context)) for item in self.items])