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

santagada at codespeak.net santagada at codespeak.net
Fri Nov 3 17:06:35 CET 2006


Author: santagada
Date: Fri Nov  3 17:06:34 2006
New Revision: 34126

Modified:
   pypy/dist/pypy/lang/js/astgen.py
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/test/test_interp.py
Log:
(stephan, santagada) Trying to make try work... broken


Modified: pypy/dist/pypy/lang/js/astgen.py
==============================================================================
--- pypy/dist/pypy/lang/js/astgen.py	(original)
+++ pypy/dist/pypy/lang/js/astgen.py	Fri Nov  3 17:06:34 2006
@@ -105,6 +105,14 @@
     def __init__(self, exception):
         self.exception = exception
 
+class Try(Node):
+    """The Try class."""
+    def __init__(self, tryblock, catchblock, finallyblock, catchparam):
+        self.tryblock = tryblock
+        self.catchblock = catchblock
+        self.finallyblock = finallyblock
+        self.catchparam = catchparam
+
 
 class Vars(Node):
     def __init__(self, nodes):
@@ -172,5 +180,16 @@
         return Vars(getlist(d))
     elif tp == 'BLOCK':
         return Block(getlist(d))
+    elif tp == 'TRY':
+        finallyblock = None
+        catchblock = None
+        catchparam = ''
+        if 'finallyBlock' in d:
+            finallyblock = from_dict(d['finallyBlock'])
+        if 'catchClauses' in d:
+            #multiple catch clauses is a spidermonkey extension
+            catchblock = from_dict(d['catchClauses']['block'])
+            catchparam = d['catchClauses']['varName']
+        return Try(from_dict(d['tryBlock']), catchblock, finallyblock, catchparam)
     else:
         raise NotImplementedError("Dont know how to handler %s" % tp)

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Fri Nov  3 17:06:34 2006
@@ -43,12 +43,6 @@
         if name == 'print':
             writer(",".join([i.ToString() for i in self.arglist.call(context)]))
         else:
-            #        #import pdb;pdb.set_trace()
-        
-#        #
-#        retval = self.body.call()
-#        #scope_manager.current_scope = backup_scope
-#        return retval
             backup_scope = scope_manager.current_scope
             w_obj = scope_manager.get_variable(name)
             scope_manager.current_scope = w_obj.function.scope
@@ -138,7 +132,6 @@
             num_right = prim_right.ToNumber()
             # XXX: obey all the rules
             return W_Number(num_left + num_right)
-        #return self.left.call(context).add(self.right.call(context))
 
 class __extend__(Script):
     def call(self, context=None, args=(), this=None, params=None):
@@ -181,7 +174,32 @@
 class __extend__(Throw):
     def call(self, context=None):
         raise ThrowException(self.exception.call(context))
-    
+
+class __extend__(Try):
+    def call(self, context=None):
+        e = None
+        try:
+            tryresult = self.tryblock.call(context)
+        except ThrowException, e:
+            e = e
+            ncontext = ExecutionContext(context)
+            print "tried to catch it :)"
+            ncontext.assign(self.catchparam, e.exception)
+            if self.catchblock is not None:
+                tryresult = self.catchblock.call(ncontext)
+        
+        print self.finallyblock
+        if self.finallyblock is not None:
+            print "asdasd"
+            tryresult = self.finallyblock.call(context)
+        print "saddsa"
+        print a
+        #if there is no catchblock reraise the exception
+        if (e is not None) and (self.catchblock is not None):
+            raise e
+        
+        return tryresult
+
 class __extend__(Vars):
     def call(self, context=None):
         for var in self.nodes:

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 Nov  3 17:06:34 2006
@@ -155,7 +155,6 @@
         self.assert_prints(parse_d("print((500,3))"), ["3"])
     
     def test_try_catch(self):
-        py.test.skip("not ready yet")
         self.assert_prints(parse_d("""
         try {
             throw(3);



More information about the Pypy-commit mailing list