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

Method JSArrayProxy_count

src/JSArrayProxy.cc:1044–1064  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1042}
1043
1044PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_count(JSArrayProxy *self, PyObject *value) {
1045 Py_ssize_t count = 0;
1046
1047 Py_ssize_t length = JSArrayProxy_length(self);
1048 JS::RootedValue elementVal(GLOBAL_CX);
1049 for (Py_ssize_t index = 0; index < length; index++) {
1050 JS_GetElement(GLOBAL_CX, *(self->jsArray), index, &elementVal);
1051 PyObject *obj = pyTypeFactory(GLOBAL_CX, elementVal);
1052 Py_INCREF(obj);
1053 int cmp = PyObject_RichCompareBool(obj, value, Py_EQ);
1054 Py_DECREF(obj);
1055 Py_DECREF(obj);
1056 if (cmp > 0) {
1057 count++;
1058 }
1059 else if (cmp < 0) {
1060 return NULL;
1061 }
1062 }
1063 return PyLong_FromSsize_t(count);
1064}
1065
1066PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_reverse(JSArrayProxy *self) {
1067 if (JSArrayProxy_length(self) > 1) {

Callers

nothing calls this directly

Calls 1

pyTypeFactoryFunction · 0.85

Tested by

no test coverage detected