| 835 | } |
| 836 | |
| 837 | PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_extend(JSArrayProxy *self, PyObject *iterable) { |
| 838 | if (PyList_CheckExact(iterable) || PyTuple_CheckExact(iterable) || (PyObject *)self == iterable) { |
| 839 | iterable = PySequence_Fast(iterable, "argument must be iterable"); |
| 840 | if (!iterable) { |
| 841 | return NULL; |
| 842 | } |
| 843 | |
| 844 | Py_ssize_t n = PySequence_Fast_GET_SIZE(iterable); |
| 845 | if (n == 0) { |
| 846 | /* short circuit when iterable is empty */ |
| 847 | Py_DECREF(iterable); |
| 848 | Py_RETURN_NONE; |
| 849 | } |
| 850 | |
| 851 | Py_ssize_t m = JSArrayProxy_length(self); |
| 852 | |
| 853 | JS::SetArrayLength(GLOBAL_CX, *(self->jsArray), m + n); |
| 854 | |
| 855 | // populate the end of self with iterable's items. |
| 856 | PyObject **src = PySequence_Fast_ITEMS(iterable); |
| 857 | for (Py_ssize_t i = 0; i < n; i++) { |
| 858 | PyObject *o = src[i]; |
| 859 | JS::RootedValue jValue(GLOBAL_CX, jsTypeFactory(GLOBAL_CX, o)); |
| 860 | JS_SetElement(GLOBAL_CX, *(self->jsArray), m + i, jValue); |
| 861 | } |
| 862 | |
| 863 | Py_DECREF(iterable); |
| 864 | } |
| 865 | else { |
| 866 | PyObject *it = PyObject_GetIter(iterable); |
| 867 | if (it == NULL) { |
| 868 | return NULL; |
| 869 | } |
| 870 | PyObject *(*iternext)(PyObject *) = *Py_TYPE(it)->tp_iternext; |
| 871 | |
| 872 | Py_ssize_t len = JSArrayProxy_length(self); |
| 873 | |
| 874 | for (;; ) { |
| 875 | PyObject *item = iternext(it); |
| 876 | if (item == NULL) { |
| 877 | if (PyErr_Occurred()) { |
| 878 | if (PyErr_ExceptionMatches(PyExc_StopIteration)) { |
| 879 | PyErr_Clear(); |
| 880 | } |
| 881 | else { |
| 882 | Py_DECREF(it); |
| 883 | return NULL; |
| 884 | } |
| 885 | } |
| 886 | break; |
| 887 | } |
| 888 | |
| 889 | JS::SetArrayLength(GLOBAL_CX, *(self->jsArray), len + 1); |
| 890 | JS::RootedValue jValue(GLOBAL_CX, jsTypeFactory(GLOBAL_CX, item)); |
| 891 | JS_SetElement(GLOBAL_CX, *(self->jsArray), len, jValue); |
| 892 | len++; |
| 893 | } |
| 894 |
nothing calls this directly
no test coverage detected