Skip to content

Commit

Permalink
Merge pull request #392 from Distributive-Network/philippe/389-fix
Browse files Browse the repository at this point in the history
PyObject is not necessarily a dict in Iterable proxy when getting an attribute
  • Loading branch information
philippedistributive authored Jul 22, 2024
2 parents a6303de + 055d412 commit 2e3274d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PyIterableProxyHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ bool PyIterableProxyHandler::getOwnPropertyDescriptor(

PyObject *attrName = idToKey(cx, id);
PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
PyObject *item = PyDict_GetItemWithError(self, attrName);
PyObject *item = PyObject_GetAttr(self, attrName);

return handleGetOwnPropertyDescriptor(cx, id, desc, item);
}
11 changes: 11 additions & 0 deletions tests/python/test_pythonmonkey_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,14 @@ def test_console_array():
items = [1, 2, 3]
pm.eval('console.log')(items)
assert temp_out.getvalue() == "[ \x1b[33m1\x1b[39m, \x1b[33m2\x1b[39m, \x1b[33m3\x1b[39m ]\n"


def test_iterable_attribute_console_printing():
temp_out = StringIO()
sys.stdout = temp_out
obj = {}
obj['stdin'] = sys.stdin # sys.stdin is iterable
assert hasattr(sys.stdin, '__iter__') == True
obj['stdin'].isTTY = sys.stdin.isatty()
pm.eval('''(function iife(obj){console.log(obj['stdin'].isTTY);})''')(obj)
assert temp_out.getvalue() == "\x1b[33mfalse\x1b[39m\n"

0 comments on commit 2e3274d

Please sign in to comment.