| 898 | } |
| 899 | |
| 900 | PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_pop(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs) { |
| 901 | Py_ssize_t index = -1; |
| 902 | |
| 903 | if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) { |
| 904 | return NULL; |
| 905 | } |
| 906 | |
| 907 | if (nargs >= 1) { |
| 908 | Py_ssize_t ival = -1; |
| 909 | PyObject *iobj = PyNumber_Index(args[0]); |
| 910 | if (iobj != NULL) { |
| 911 | ival = PyLong_AsSsize_t(iobj); |
| 912 | Py_DECREF(iobj); |
| 913 | } |
| 914 | if (ival == -1 && PyErr_Occurred()) { |
| 915 | return NULL; |
| 916 | } |
| 917 | index = ival; |
| 918 | } |
| 919 | |
| 920 | Py_ssize_t selfSize = JSArrayProxy_length(self); |
| 921 | |
| 922 | if (selfSize == 0) { |
| 923 | /* Special-case most common failure cause */ |
| 924 | PyErr_SetString(PyExc_IndexError, "pop from empty list"); |
| 925 | return NULL; |
| 926 | } |
| 927 | |
| 928 | if (index < 0) { |
| 929 | index += selfSize; |
| 930 | } |
| 931 | |
| 932 | if ((size_t)index >= (size_t)selfSize) { |
| 933 | PyErr_SetString(PyExc_IndexError, "pop index out of range"); |
| 934 | return NULL; |
| 935 | } |
| 936 | |
| 937 | JS::Rooted<JS::ValueArray<2>> jArgs(GLOBAL_CX); |
| 938 | jArgs[0].setInt32(index); |
| 939 | jArgs[1].setInt32(1); |
| 940 | |
| 941 | JS::RootedValue jReturnedArray(GLOBAL_CX); |
| 942 | if (!JS_CallFunctionName(GLOBAL_CX, *(self->jsArray), "splice", jArgs, &jReturnedArray)) { |
| 943 | PyErr_Format(PyExc_SystemError, "%s JSAPI call failed", JSArrayProxyType.tp_name); |
| 944 | return NULL; |
| 945 | } |
| 946 | |
| 947 | // need the value in the returned array, not the array itself |
| 948 | JS::RootedObject rootedReturnedArray(GLOBAL_CX, jReturnedArray.toObjectOrNull()); |
| 949 | JS::RootedValue elementVal(GLOBAL_CX); |
| 950 | JS_GetElement(GLOBAL_CX, rootedReturnedArray, 0, &elementVal); |
| 951 | |
| 952 | return pyTypeFactory(GLOBAL_CX, elementVal); |
| 953 | } |
| 954 | |
| 955 | PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_remove(JSArrayProxy *self, PyObject *value) { |
| 956 | Py_ssize_t selfSize = JSArrayProxy_length(self); |
nothing calls this directly
no test coverage detected