[pypy-svn] r36577 - in pypy/dist/pypy/lang/js: . test
santagada at codespeak.net
santagada at codespeak.net
Fri Jan 12 15:47:42 CET 2007
Author: santagada
Date: Fri Jan 12 15:47:29 2007
New Revision: 36577
Modified:
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/jsobj.py
pypy/dist/pypy/lang/js/test/test_interp.py
Log:
break/continue working
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Fri Jan 12 15:47:29 2007
@@ -128,8 +128,24 @@
last = node.execute(ctx)
return last
except ExecutionReturned, e:
- return e.value
+ if e.type == 'return':
+ return e.value
+ else:
+ raise e
+
+class Unconditional(Statement):
+ def __init__(self, targtype, targlineno, targstart):
+ self.targtype = targtype
+ self.targlineno = targlineno
+ self.targstart = targstart
+
+class Break(Unconditional):
+ def execute(self, ctx):
+ raise ExecutionReturned('break', None, None)
+class Continue(Unconditional):
+ def execute(self, ctx):
+ raise ExecutionReturned('continue', None, None)
class Call(Expression):
def __init__(self, identifier, arglist):
@@ -419,7 +435,10 @@
last = node.execute(ctx)
return last
except ExecutionReturned, e:
- return e.value
+ if e.type == 'return':
+ return e.value
+ else:
+ raise e
class Semicolon(Statement):
def __init__(self, expr = None):
@@ -427,7 +446,7 @@
def execute(self, ctx):
if self.expr is None:
- return
+ return w_Undefined
return self.expr.execute(ctx)
class String(Expression):
@@ -445,7 +464,7 @@
self.expr = expr
def execute(self, ctx):
- raise ExecutionReturned(self.expr.eval(ctx))
+ raise ExecutionReturned('return', self.expr.eval(ctx), None)
class Throw(Statement):
def __init__(self, exception):
@@ -506,7 +525,13 @@
def execute(self, ctx):
while self.condition.eval(ctx).ToBoolean():
- self.body.execute(ctx)
+ try:
+ self.body.execute(ctx)
+ except ExecutionReturned, e:
+ if e.type == 'break':
+ break
+ elif e.type == 'continue':
+ continue
class For(Statement):
def __init__(self, setup, condition, update, body):
@@ -518,8 +543,14 @@
def execute(self, ctx):
self.setup.eval(ctx)
while self.condition.eval(ctx).ToBoolean():
- self.body.execute(ctx)
- self.update.eval(ctx)
+ try:
+ self.body.execute(ctx)
+ self.update.eval(ctx)
+ except ExecutionReturned, e:
+ if e.type == 'break':
+ break
+ elif e.type == 'continue':
+ continue
class Boolean(Expression):
def __init__(self, bool):
@@ -560,6 +591,9 @@
node = Assign(from_tree(gettreeitem(t, '0')), from_tree(gettreeitem(t, '1')))
elif tp == 'BLOCK':
node = Block(getlist(t))
+ elif tp == 'BREAK':
+ targtype, targlineno, targstart = gettreeitem(t, 'target').additional_info.split(',')
+ node = Break(targtype, targlineno, targstart)
elif tp == 'CALL':
node = Call(from_tree(gettreeitem(t, '0')), from_tree(gettreeitem(t, '1')))
elif tp == 'COMMA':
@@ -568,6 +602,9 @@
node = Conditional(from_tree(gettreeitem(t, '0')),
from_tree(gettreeitem(t, '1')),
from_tree(gettreeitem(t, '2')))
+ elif tp == 'CONTINUE':
+ targtype, targlineno, targstart = gettreeitem(t, 'target').additional_info.split(',')
+ node = Continue(targtype, targlineno, targstart)
elif tp == 'DOT':
node = Dot(from_tree(gettreeitem(t, '0')), from_tree(gettreeitem(t, '1')))
elif tp == 'EQ':
@@ -714,9 +751,8 @@
value = gettreeitem(t, 'type')
else:
value = gettreeitem(t, 'value').additional_info
-
-
- print tp
+
+
node.init_common(gettreeitem(t, 'type').additional_info, value,
int(gettreeitem(t, 'lineno').additional_info), start, end)
return node
Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py (original)
+++ pypy/dist/pypy/lang/js/jsobj.py Fri Jan 12 15:47:29 2007
@@ -5,8 +5,10 @@
pass
class ExecutionReturned(Exception):
- def __init__(self, value):
+ def __init__(self, type='normal', value=None, identifier=None):
+ self.type = type
self.value = value
+ self.identifier = identifier
class ThrowException(Exception):
def __init__(self, exception):
@@ -30,7 +32,8 @@
self.Internal = Internal
def __repr__(self):
- return "|%s %d%d%d|"%(self.value, self.DontDelete, self.ReadOnly, self.DontEnum)
+ return "|%s %d%d%d|"%(self.value, self.DontDelete,
+ self.ReadOnly, self.DontEnum)
def internal_property(name, value):
"""return a internal property with the right attributes"""
@@ -58,7 +61,8 @@
def Get(self, P):
raise NotImplementedError
- def Put(self, P, V, DontDelete=False, ReadOnly=False, DontEnum=False, Internal=False):
+ def Put(self, P, V, DontDelete=False,
+ ReadOnly=False, DontEnum=False, Internal=False):
raise NotImplementedError
def PutValue(self, w, ctx):
Modified: pypy/dist/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_interp.py (original)
+++ pypy/dist/pypy/lang/js/test/test_interp.py Fri Jan 12 15:47:29 2007
@@ -325,11 +325,13 @@
var tc = testcases.length;"""
def test_break(self):
- py.test.skip(" TODO: needed for mozilla test suite")
self.assert_prints("""
while(1){
break;
}
+ for(x=0;1==1;x++) {
+ break;
+ }
print('out')""", ["out"])
def test_typeof(self):
More information about the Pypy-commit
mailing list