[pypy-svn] r39647 - in pypy/dist/pypy/lang/js: . test

santagada at codespeak.net santagada at codespeak.net
Fri Mar 2 03:23:59 CET 2007


Author: santagada
Date: Fri Mar  2 03:23:54 2007
New Revision: 39647

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:
with operator with test

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Fri Mar  2 03:23:54 2007
@@ -969,6 +969,24 @@
         self.expr.eval(ctx)
         return w_Undefined
 
+class With(Statement):
+    opcode = "WITH"
+    
+    def from_tree(self, t):
+        self.object = get_obj(t, 'object')
+        self.body = get_obj(t, 'body')
+
+    def execute(self, ctx):
+        obj = self.object.eval(ctx).GetValue().ToObject()
+        ctx.push_object(obj)
+
+        try:
+            retval = self.body.execute(ctx)
+        finally:
+            ctx.pop_object()
+        return retval
+
+
 class WhileBase(Statement):
     def from_tree(self, t):
         self.condition = get_obj(t, 'condition')

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Fri Mar  2 03:23:54 2007
@@ -437,7 +437,7 @@
         self.variable = obj
     
     def pop_object(self):
-        """docstring for pop_object"""
+        """remove the last pushed object"""
         return self.scope.pop(0)
         
     def resolve_identifier(self, identifier):

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 Mar  2 03:23:54 2007
@@ -478,3 +478,21 @@
         print(2 !== 3)
         print(2 !== 2)    
         """, ['true', 'false', 'true', 'false'])
+    
+    def test_with(self):
+        self.assert_prints("""
+        var mock = {x:2}
+        var x=4
+        print(x)
+        try {
+            with(mock) {
+                print(x)
+                throw 3
+                print("not reacheable")
+            }
+        }
+        catch(y){
+            print(y)
+        }
+        print(x)
+        """, ['4', '2', '3', '4'])


More information about the pypy-svn mailing list