| 786 | } |
| 787 | |
| 788 | PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_insert(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs) { |
| 789 | PyObject *return_value = NULL; |
| 790 | Py_ssize_t index; |
| 791 | PyObject *value; |
| 792 | |
| 793 | if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) { |
| 794 | return NULL; |
| 795 | } |
| 796 | |
| 797 | { |
| 798 | Py_ssize_t ival = -1; |
| 799 | PyObject *iobj = PyNumber_Index(args[0]); |
| 800 | if (iobj != NULL) { |
| 801 | ival = PyLong_AsSsize_t(iobj); |
| 802 | Py_DECREF(iobj); |
| 803 | } |
| 804 | if (ival == -1 && PyErr_Occurred()) { |
| 805 | return NULL; |
| 806 | } |
| 807 | index = ival; |
| 808 | } |
| 809 | |
| 810 | value = args[1]; |
| 811 | |
| 812 | Py_ssize_t n = JSArrayProxy_length(self); |
| 813 | |
| 814 | if (index < 0) { |
| 815 | index += n; |
| 816 | if (index < 0) { |
| 817 | index = 0; |
| 818 | } |
| 819 | } |
| 820 | if (index > n) { |
| 821 | index = n; |
| 822 | } |
| 823 | |
| 824 | JS::Rooted<JS::ValueArray<3>> jArgs(GLOBAL_CX); |
| 825 | jArgs[0].setInt32(index); |
| 826 | jArgs[1].setInt32(0); |
| 827 | jArgs[2].set(jsTypeFactory(GLOBAL_CX, value)); |
| 828 | |
| 829 | JS::RootedValue jReturnedArray(GLOBAL_CX); |
| 830 | if (!JS_CallFunctionName(GLOBAL_CX, *(self->jsArray), "splice", jArgs, &jReturnedArray)) { |
| 831 | PyErr_Format(PyExc_SystemError, "%s JSAPI call failed", JSArrayProxyType.tp_name); |
| 832 | return NULL; |
| 833 | } |
| 834 | Py_RETURN_NONE; |
| 835 | } |
| 836 | |
| 837 | PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_extend(JSArrayProxy *self, PyObject *iterable) { |
| 838 | if (PyList_CheckExact(iterable) || PyTuple_CheckExact(iterable) || (PyObject *)self == iterable) { |
nothing calls this directly
no test coverage detected