| 726 | } |
| 727 | |
| 728 | PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_inplace_repeat(JSArrayProxy *self, Py_ssize_t n) { |
| 729 | Py_ssize_t input_size = JSArrayProxy_length(self); |
| 730 | if (input_size == 0 || n == 1) { |
| 731 | Py_INCREF(self); |
| 732 | return (PyObject *)self; |
| 733 | } |
| 734 | |
| 735 | if (n < 1) { |
| 736 | JSArrayProxy_clear_method(self); |
| 737 | Py_INCREF(self); |
| 738 | return (PyObject *)self; |
| 739 | } |
| 740 | |
| 741 | if (input_size > PY_SSIZE_T_MAX / n) { |
| 742 | return PyErr_NoMemory(); |
| 743 | } |
| 744 | |
| 745 | JS::SetArrayLength(GLOBAL_CX, *(self->jsArray), input_size * n); |
| 746 | |
| 747 | // repeat within self |
| 748 | // one might think of using copyWithin but in SpiderMonkey it's implemented in JS! |
| 749 | JS::RootedValue elementVal(GLOBAL_CX); |
| 750 | for (Py_ssize_t inputIdx = 0; inputIdx < input_size; inputIdx++) { |
| 751 | JS_GetElement(GLOBAL_CX, *(self->jsArray), inputIdx, &elementVal); |
| 752 | for (Py_ssize_t repeatIdx = 0; repeatIdx < n; repeatIdx++) { |
| 753 | JS_SetElement(GLOBAL_CX, *(self->jsArray), repeatIdx * input_size + inputIdx, elementVal); |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | Py_INCREF(self); |
| 758 | return (PyObject *)self; |
| 759 | } |
| 760 | |
| 761 | PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_clear_method(JSArrayProxy *self) { |
| 762 | JS::SetArrayLength(GLOBAL_CX, *(self->jsArray), 0); |
nothing calls this directly
no outgoing calls
no test coverage detected