1. Jason R. Coombs
  2. pyv8

Commits

flie...@gmail.com@3b770cb8-f9e6-11dd-ac5b-dfceb64ead24  committed c9749e1

allow to raise exception in the JSClass getter except AttributeError

  • Participants
  • Parent commits 31cf010
  • Branches default

Comments (0)

Files changed (2)

File PyV8.py

View file
  • Ignore whitespace
 
             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)

File src/Wrapper.cpp

View file
  • Ignore whitespace
 
   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))