| 220 | } |
| 221 | |
| 222 | bool JSObjectProxyMethodDefinitions::JSObjectProxy_richcompare_helper(JSObjectProxy *self, PyObject *other, std::unordered_map<PyObject *, PyObject *> &visited) |
| 223 | { |
| 224 | if (!(Py_TYPE(other)->tp_iter) && !PySequence_Check(other) & !PyMapping_Check(other)) { // if other is not a container |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | if ((visited.find((PyObject *)self) != visited.end() && visited[(PyObject *)self] == other) || |
| 229 | (visited.find((PyObject *)other) != visited.end() && visited[other] == (PyObject *)self) |
| 230 | ) // if we've already compared these before, skip |
| 231 | { |
| 232 | return true; |
| 233 | } |
| 234 | |
| 235 | visited.insert({{(PyObject *)self, other}}); |
| 236 | |
| 237 | if (Py_TYPE((PyObject *)self) == Py_TYPE(other)) { |
| 238 | JS::RootedValue selfVal(GLOBAL_CX, JS::ObjectValue(**(self->jsObject))); |
| 239 | JS::RootedValue otherVal(GLOBAL_CX, JS::ObjectValue(**(*(JSObjectProxy *)other).jsObject)); |
| 240 | if (selfVal.asRawBits() == otherVal.asRawBits()) { |
| 241 | return true; |
| 242 | } |
| 243 | bool *isEqual; |
| 244 | } |
| 245 | |
| 246 | JS::RootedIdVector props(GLOBAL_CX); |
| 247 | if (!js::GetPropertyKeys(GLOBAL_CX, *(self->jsObject), JSITER_OWNONLY, &props)) |
| 248 | { |
| 249 | PyErr_Format(PyExc_SystemError, "%s JSAPI call failed", JSObjectProxyType.tp_name); |
| 250 | return false; |
| 251 | } |
| 252 | |
| 253 | // iterate recursively through members of self and check for equality |
| 254 | size_t length = props.length(); |
| 255 | for (size_t i = 0; i < length; i++) |
| 256 | { |
| 257 | JS::HandleId id = props[i]; |
| 258 | JS::RootedValue key(GLOBAL_CX); |
| 259 | key.setString(id.toString()); |
| 260 | |
| 261 | PyObject *pyKey = pyTypeFactory(GLOBAL_CX, key); |
| 262 | PyObject *pyVal1 = PyObject_GetItem((PyObject *)self, pyKey); |
| 263 | PyObject *pyVal2 = PyObject_GetItem((PyObject *)other, pyKey); |
| 264 | Py_DECREF(pyKey); |
| 265 | if (!pyVal2) { // if other.key is NULL then not equal |
| 266 | return false; |
| 267 | } |
| 268 | if (pyVal1 && Py_TYPE(pyVal1) == &JSObjectProxyType) { // if either subvalue is a JSObjectProxy, we need to pass around our visited map |
| 269 | if (!JSObjectProxy_richcompare_helper((JSObjectProxy *)pyVal1, pyVal2, visited)) |
| 270 | { |
| 271 | return false; |
| 272 | } |
| 273 | } |
| 274 | else if (pyVal2 && Py_TYPE(pyVal2) == &JSObjectProxyType) { |
| 275 | if (!JSObjectProxy_richcompare_helper((JSObjectProxy *)pyVal2, pyVal1, visited)) |
| 276 | { |
| 277 | return false; |
| 278 | } |
| 279 | } |
nothing calls this directly
no test coverage detected