Commits

Anonymous committed c9749e1

allow to raise exception in the JSClass getter except AttributeError

Comments (0)

Files changed (2)

 
             self.assert_(ctxt.eval("typeof(s.z) === 'undefined'"))
 
+    def testRaiseExceptionInGetter(self):
+        class Document(JSClass):
+            def __getattr__(self, name):
+                if name == 'y':
+                    raise TypeError()
+
+                return JSClass.__getattr__(self, name)
+
+        class Global(JSClass):
+            def __init__(self):
+                self.document = Document()
+
+        with JSContext(Global()) as ctxt:
+            self.assertEquals(None, ctxt.eval('document.x'))
+            self.assertRaises(TypeError, ctxt.eval, 'document.y')
+
 class TestMultithread(unittest.TestCase):
     def testLocker(self):
         self.assertFalse(JSLocker.active)
 
   if (!value)
   {
-    ::PyErr_Clear();
+    if (_PyErr_OCCURRED()) 
+    {
+      if (::PyErr_ExceptionMatches(::PyExc_AttributeError))
+      {
+        ::PyErr_Clear();
+      }
+      else
+      {
+        py::throw_error_already_set();
+      }
+    }
 
     if (::PyMapping_Check(obj.ptr()) && 
         ::PyMapping_HasKeyString(obj.ptr(), *name))