[pypy-svn] r39426 - pypy/dist/pypy/lang/js

santagada at codespeak.net santagada at codespeak.net
Mon Feb 26 14:32:06 CET 2007


Author: santagada
Date: Mon Feb 26 14:32:04 2007
New Revision: 39426

Modified:
   pypy/dist/pypy/lang/js/interpreter.py
   pypy/dist/pypy/lang/js/js_interactive.py
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/jsparser.py
Log:
stripped of regexes on jsparser.py, better handling of exceptions on the interactive parser, a rpython modification (super is not rpython), and a cleanup of the exception trace string 

Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py	(original)
+++ pypy/dist/pypy/lang/js/interpreter.py	Mon Feb 26 14:32:04 2007
@@ -774,7 +774,7 @@
             if isinstance(e, ExecutionReturned) and e.type == 'return':
                 return e.value
             else:
-                print "exeception in line: %s, %s - %s"%(node.lineno, node.value, self)
+                print "exeception in line: %s, on: %s"%(node.lineno, node.value)
                 raise
 
 class Semicolon(Statement):

Modified: pypy/dist/pypy/lang/js/js_interactive.py
==============================================================================
--- pypy/dist/pypy/lang/js/js_interactive.py	(original)
+++ pypy/dist/pypy/lang/js/js_interactive.py	Mon Feb 26 14:32:04 2007
@@ -8,7 +8,7 @@
 import sys
 import getopt
 from pypy.lang.js.interpreter import *
-from pypy.lang.js.jsobj import W_Builtin, W_String, ThrowException
+from pypy.lang.js.jsobj import W_Builtin, W_String, ThrowException, w_Undefined
 from pypy.lang.js import jsparser
 import os
 import cmd
@@ -93,7 +93,16 @@
     interp.w_Global.Put('load', W_Builtin(loadjs))
     interp.w_Global.Put('trace', W_Builtin(tracejs))
     for filename in filenames:
-        loadjs(interp.global_context, [W_String(filename)], None)
+        try:
+            loadjs(interp.global_context, [W_String(filename)], None)
+            # XXX we should catch more stuff here, like not implemented
+            # and such
+        except (jsparser.JsSyntaxError, ThrowException), e:
+            if isinstance(e, jsparser.JsSyntaxError):
+                print "\nSyntax error!"
+            elif isinstance(e, ThrowException):
+                print "\nJS Exception thrown!"
+            return
 
     #while interactive:
     #    res = interp.run(load_source(raw_input("js-pypy> ")))
@@ -152,8 +161,8 @@
                 return
         finally:
             self.reset()
-        if res is not None:
-            print res        
+        if res is not None or res is not w_Undefined:
+            print res.GetValue().ToString()
 
 if __name__ == "__main__":
     import py

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Mon Feb 26 14:32:04 2007
@@ -304,7 +304,7 @@
             self.array[x]= V
                     
         except ValueError:
-            super(W_Array, self).Put(P, V, dd, ro, de, it)
+            W_Builtin.Put(self, P, V, dd=dd, ro=ro, de=de, it=it)
 
     def Get(self, P):
         try:

Modified: pypy/dist/pypy/lang/js/jsparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsparser.py	(original)
+++ pypy/dist/pypy/lang/js/jsparser.py	Mon Feb 26 14:32:04 2007
@@ -15,11 +15,21 @@
 class JsSyntaxError(Exception):
     pass
 
-singlequote = re.compile(r"(?<!\\)'")
+SLASH = "\\"
 def read_js_output(code_string):
-    stripped_code = re.sub(r"\\(?!')",r"\\\\", code_string)
-    stripped_code = stripped_code.replace("\n", "\\n")
-    stripped_code = singlequote.sub(r"\'", stripped_code)
+    tmp = []
+    last = ""
+    for c in code_string:
+        if c == "'" and last != SLASH:
+            tmp.append("\\'")
+        else:
+            if c == SLASH:
+                tmp.append(SLASH*2)
+            elif c == "\n":
+                tmp.append("\\n")
+            else:
+                tmp.append(c)
+    stripped_code = "".join(tmp)
     if DEBUG:
         print "------ got:"
         print code_string



More information about the Pypy-commit mailing list