Permalink
Browse files

Initial work on specific JS exceptions, working JSSyntaxError

  • Loading branch information...
NicolasT committed Jul 20, 2008
1 parent 172765d commit 6aeb1ca8dd5cc41e2eca3660793e6f860dacb84c
Showing with 13 additions and 13 deletions.
  1. +9 −11 jscore/jscore.pyx
  2. +4 −2 test/test_context.py
View
@@ -119,7 +119,8 @@ class JSSyntaxError(JSException):
source_id = None
source_url = None
- def __init__(self, message, exception_value, errLine, sourceId, sourceURL):
+ def __init__(self, message, exception_value, errLine, sourceId,
+ sourceURL=None):
JSException.__init__(self, message, exception_value)
self.error_line = errLine
self.source_id = sourceId
@@ -140,18 +141,15 @@ cdef _check_exception(Context ctx, JSValueRef exception, message):
value = _value_load(ctx, exception).python_value(ctx)
if isinstance(value, JSObject):
- #TODO Parse and raise appropriate exceptions
- exceptionstring = JSValueToStringCopy(ctx_, exception, &innerexception)
- _check_exception(ctx, innerexception,
- 'An exception occurred while parsing a prior exception')
+ if value.name == 'SyntaxError':
+ message = value.message
+ line = int(value.line)
+ source = int(value.sourceId)
- s = String(None)
- s.str_ = exceptionstring
- v = str(s)
+ raise JSSyntaxError(message, value, line, source, None)
- JSStringRelease(exceptionstring)
-
- raise JSException(v, v)
+ else:
+ raise RuntimeError('Unknown exception type: %s' % value.name)
else:
raise JSException(message, value)
View
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import unittest
import jscore
@@ -24,7 +25,7 @@ def test_check_script_syntax_valid(self):
def test_check_script_syntax_invalid(self):
script = '--- I am an invalid script ---'
- self.assertRaises(jscore.JSException,
+ self.assertRaises(jscore.JSSyntaxError,
self.ctx.check_script_syntax, script)
def test_check_script_syntax_params(self):
@@ -54,7 +55,8 @@ def test_evaluate_script_valid(self):
def test_evaluate_script_invalid(self):
script = 'a -;'
- self.assertRaises(jscore.JSException, self.ctx.evaluate_script, script)
+ self.assertRaises(jscore.JSSyntaxError, self.ctx.evaluate_script,
+ script)
def test_evaluate_script_empty(self):
script = ''

0 comments on commit 6aeb1ca

Please sign in to comment.