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

Method JSArrayProxy_remove

src/JSArrayProxy.cc:955–984  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

953}
954
955PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_remove(JSArrayProxy *self, PyObject *value) {
956 Py_ssize_t selfSize = JSArrayProxy_length(self);
957
958 JS::RootedValue elementVal(GLOBAL_CX);
959 for (Py_ssize_t index = 0; index < selfSize; index++) {
960 JS_GetElement(GLOBAL_CX, *(self->jsArray), index, &elementVal);
961 PyObject *obj = pyTypeFactory(GLOBAL_CX, elementVal);
962 Py_INCREF(obj);
963 int cmp = PyObject_RichCompareBool(obj, value, Py_EQ);
964 Py_DECREF(obj);
965 Py_DECREF(obj);
966 if (cmp > 0) {
967 JS::Rooted<JS::ValueArray<2>> jArgs(GLOBAL_CX);
968 jArgs[0].setInt32(index);
969 jArgs[1].setInt32(1);
970 JS::RootedValue jReturnedArray(GLOBAL_CX);
971 if (!JS_CallFunctionName(GLOBAL_CX, *(self->jsArray), "splice", jArgs, &jReturnedArray)) {
972 PyErr_Format(PyExc_SystemError, "%s JSAPI call failed", JSArrayProxyType.tp_name);
973 return NULL;
974 }
975 Py_RETURN_NONE;
976 }
977 else if (cmp < 0) {
978 return NULL;
979 }
980 }
981
982 PyErr_SetString(PyExc_ValueError, "list.remove(x): x not in list");
983 return NULL;
984}
985
986PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_index(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs) {
987 PyObject *value;

Callers

nothing calls this directly

Calls 1

pyTypeFactoryFunction · 0.85

Tested by

no test coverage detected