| 606 | } |
| 607 | |
| 608 | PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_concat(JSArrayProxy *self, PyObject *value) { |
| 609 | // value must be a list |
| 610 | if (!PyList_Check(value)) { |
| 611 | PyErr_Format(PyExc_TypeError, "can only concatenate list (not \"%.200s\") to list", Py_TYPE(value)->tp_name); |
| 612 | return NULL; |
| 613 | } |
| 614 | |
| 615 | Py_ssize_t sizeSelf = JSArrayProxy_length(self); |
| 616 | Py_ssize_t sizeValue; |
| 617 | if (PyObject_TypeCheck(value, &JSArrayProxyType)) { |
| 618 | sizeValue = JSArrayProxyMethodDefinitions::JSArrayProxy_length((JSArrayProxy *)value); |
| 619 | } else { |
| 620 | sizeValue = Py_SIZE(value); |
| 621 | } |
| 622 | |
| 623 | assert((size_t)sizeSelf + (size_t)sizeValue < PY_SSIZE_T_MAX); |
| 624 | |
| 625 | if (sizeValue == 0) { |
| 626 | if (sizeSelf == 0) { |
| 627 | return PyList_New(0); |
| 628 | } |
| 629 | else { |
| 630 | Py_INCREF(self); |
| 631 | return (PyObject *)self; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | JS::RootedObject jCombinedArray(GLOBAL_CX, JS::NewArrayObject(GLOBAL_CX, (size_t)sizeSelf + (size_t)sizeValue)); |
| 636 | |
| 637 | JS::RootedValue elementVal(GLOBAL_CX); |
| 638 | |
| 639 | for (Py_ssize_t inputIdx = 0; inputIdx < sizeSelf; inputIdx++) { |
| 640 | JS_GetElement(GLOBAL_CX, *(self->jsArray), inputIdx, &elementVal); |
| 641 | JS_SetElement(GLOBAL_CX, jCombinedArray, inputIdx, elementVal); |
| 642 | } |
| 643 | |
| 644 | if (PyObject_TypeCheck(value, &JSArrayProxyType)) { |
| 645 | for (Py_ssize_t inputIdx = 0; inputIdx < sizeValue; inputIdx++) { |
| 646 | JS_GetElement(GLOBAL_CX, *(((JSArrayProxy *)value)->jsArray), inputIdx, &elementVal); |
| 647 | JS_SetElement(GLOBAL_CX, jCombinedArray, sizeSelf + inputIdx, elementVal); |
| 648 | } |
| 649 | } else { |
| 650 | for (Py_ssize_t inputIdx = 0; inputIdx < sizeValue; inputIdx++) { |
| 651 | PyObject *item = PyList_GetItem(value, inputIdx); |
| 652 | elementVal.set(jsTypeFactory(GLOBAL_CX, item)); |
| 653 | JS_SetElement(GLOBAL_CX, jCombinedArray, sizeSelf + inputIdx, elementVal); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | JS::RootedValue jCombinedArrayValue(GLOBAL_CX); |
| 658 | jCombinedArrayValue.setObjectOrNull(jCombinedArray); |
| 659 | |
| 660 | return pyTypeFactory(GLOBAL_CX, jCombinedArrayValue); |
| 661 | } |
| 662 | |
| 663 | PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_repeat(JSArrayProxy *self, Py_ssize_t n) { |
| 664 | const Py_ssize_t input_size = JSArrayProxy_length(self); |
nothing calls this directly
no test coverage detected