MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / ownPropertyKeys

Method ownPropertyKeys

src/PyObjectProxyHandler.cc:98–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98bool PyObjectProxyHandler::ownPropertyKeys(JSContext *cx, JS::HandleObject proxy, JS::MutableHandleIdVector props) const {
99 PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
100 PyObject *keys = PyObject_Dir(self);
101
102 if (keys != nullptr) {
103 size_t keysLength = PyList_Size(keys);
104
105 PyObject *nonDunderKeys = PyList_New(0);
106 for (size_t i = 0; i < keysLength; i++) {
107 PyObject *key = PyList_GetItem(keys, i);
108 if (PyObject_CallMethod(key, "startswith", "(s)", "__") == Py_False) { // if key starts with "__", ignore it
109 PyList_Append(nonDunderKeys, key);
110 }
111 }
112
113 return handleOwnPropertyKeys(cx, nonDunderKeys, PyList_Size(nonDunderKeys), props);
114 }
115 else {
116 if (PyErr_Occurred()) {
117 PyErr_Clear();
118 }
119
120 return handleOwnPropertyKeys(cx, PyList_New(0), 0, props);
121 }
122}
123
124bool PyObjectProxyHandler::delete_(JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
125 JS::ObjectOpResult &result) const {

Callers 2

enumerateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected