[pypy-commit] lang-js default: 7.5-8-n

stepahn noreply at buildbot.pypy.org
Fri Dec 28 11:33:41 CET 2012


Author: Stephan <stephan at stzal.com>
Branch: 
Changeset: r201:699fdb193c81
Date: 2012-05-21 15:03 +0200
http://bitbucket.org/pypy/lang-js/changeset/699fdb193c81/

Log:	7.5-8-n

diff --git a/js/builtins_global.py b/js/builtins_global.py
--- a/js/builtins_global.py
+++ b/js/builtins_global.py
@@ -241,6 +241,7 @@
     from js.functions import JsEvalCode
     from js.execution_context import EvalExecutionContext
     from pypy.rlib.parsing.parsing import ParseError
+    from pypy.rlib.parsing.deterministic import LexerError
     from js.astbuilder import FakeParseError
     from js.execution import JsSyntaxError
 
@@ -257,13 +258,14 @@
         error = e.errorinformation.failure_reasons
         error_lineno = e.source_pos.lineno
         error_pos = e.source_pos.columnno
-        error_src = src.encode('unicode_escape')
-        error_msg = 'Syntax Error in: "%s":%d,%d' %(error_src, error_lineno, error_pos)
-        raise JsSyntaxError(error_msg)
+        raise JsSyntaxError(msg = error, src = src, line = error_lineno, column = error_pos)
     except FakeParseError, e:
-        error_msg = 'Syntax Error: %s' % (e.msg)
-        raise JsSyntaxError(error_msg)
-
+        raise JsSyntaxError(msg = e.msg, src = src)
+    except LexerError, e:
+        error_lineno = e.source_pos.lineno
+        error_pos = e.source_pos.columnno
+        error_msg = 'LexerError'
+        raise JsSyntaxError(msg = error_msg, src = src, line = error_lineno, column = error_pos)
 
     symbol_map = ast.symbol_map
     code = ast_to_bytecode(ast, symbol_map)
diff --git a/js/execution.py b/js/execution.py
--- a/js/execution.py
+++ b/js/execution.py
@@ -24,23 +24,53 @@
         self.args = [exception]
 
 class JsException(Exception):
+    def _msg(self):
+        return 'Exception'
+
+    def msg(self):
+        from js.jsobj import _w
+        return _w(self._msg())
+
+class JsThrowException(JsException):
     def __init__(self, value = None):
-        from js.jsobj import _w
+        JsException.__init__(self)
         self.value = _w(value)
 
-class JsThrowException(JsException):
-    pass
+class JsTypeError(JsException):
+    def __init__(self, value = None):
+        JsException.__init__(self)
+        self.value = value
 
-class JsTypeError(JsException):
-    pass
+    def _msg(self):
+        return 'TypeError: %s' % (self.value)
 
 class JsReferenceError(JsException):
     def __init__(self, identifier):
-        s = "ReferenceError: %s is not defined" % (identifier)
-        JsException.__init__(self, s)
+        JsException.__init__(self)
+        self.identifier = identifier
+
+    def _msg(self):
+        return 'ReferenceError: %s' % (self.identifier)
 
 class JsRangeError(JsException):
-    pass
+    def __init__(self, value = None):
+        JsException.__init__(self)
+        self.value = value
+
+    def _msg(self):
+        return 'RangeError: %s' %(str(self.value))
 
 class JsSyntaxError(JsException):
-    pass
+    def __init__(self, msg = '', src = '', line = 0, column = 0):
+        JsException.__init__(self)
+        self.error_msg = msg
+        self.src = src
+        self.line = line
+        self.column = column
+
+    def _msg(self):
+        error_src = self.src.encode('unicode_escape')
+        if self.error_msg:
+            return 'SyntaxError: "%s" in "%s" at line:%d, column:%d' %(self.error_msg, error_src, self.line, self.column)
+        else:
+            return 'SyntaxError: in "%s" at line:%d, column:%d' %(error_src, self.line, self.column)
diff --git a/js/js_interactive.py b/js/js_interactive.py
--- a/js/js_interactive.py
+++ b/js/js_interactive.py
@@ -110,7 +110,7 @@
 
     def showtraceback(self, exc):
         # XXX format exceptions nicier
-        print exc.value.to_string()
+        print exc._msg()
 
     def showsyntaxerror(self, filename, exc, source):
         # XXX format syntax errors nicier


More information about the pypy-commit mailing list