| 540 | } |
| 541 | |
| 542 | static bool array_concat(JSContext *cx, unsigned argc, JS::Value *vp) { |
| 543 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
| 544 | |
| 545 | JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv())); |
| 546 | if (!proxy) { |
| 547 | return false; |
| 548 | } |
| 549 | PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot); |
| 550 | |
| 551 | Py_ssize_t selfSize = PyList_GET_SIZE(self); |
| 552 | PyObject *result = PyList_GetSlice(self, 0, selfSize); |
| 553 | |
| 554 | unsigned numArgs = args.length(); |
| 555 | JS::RootedValue elementVal(cx); |
| 556 | for (unsigned index = 0; index < numArgs; index++) { |
| 557 | elementVal.set(args[index].get()); |
| 558 | |
| 559 | PyObject *item = pyTypeFactory(cx, elementVal); |
| 560 | if (PyObject_TypeCheck(item, &JSArrayProxyType)) { |
| 561 | // flatten the array only a depth 1 |
| 562 | Py_ssize_t itemLength = JSArrayProxyMethodDefinitions::JSArrayProxy_length((JSArrayProxy *)item); |
| 563 | for (Py_ssize_t flatIndex = 0; flatIndex < itemLength; flatIndex++) { |
| 564 | if (!JS_GetElement(cx, *(((JSArrayProxy *)item)->jsArray), flatIndex, &elementVal)) { |
| 565 | Py_DECREF(item); |
| 566 | return false; |
| 567 | } |
| 568 | PyObject *value = pyTypeFactory(cx, elementVal); |
| 569 | if (PyList_Append(result, value) < 0) { |
| 570 | Py_DECREF(item); |
| 571 | Py_DECREF(value); |
| 572 | return false; |
| 573 | } |
| 574 | Py_DECREF(value); |
| 575 | } |
| 576 | } |
| 577 | else if (PyObject_TypeCheck(item, &PyList_Type)) { |
| 578 | // flatten the array only at depth 1 |
| 579 | Py_ssize_t itemLength = PyList_GET_SIZE(item); |
| 580 | for (Py_ssize_t flatIndex = 0; flatIndex < itemLength; flatIndex++) { |
| 581 | if (PyList_Append(result, PyList_GetItem(item, flatIndex)) < 0) { |
| 582 | Py_DECREF(item); |
| 583 | return false; |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | else { |
| 588 | PyObject *value = pyTypeFactory(cx, elementVal); |
| 589 | if (PyList_Append(result, value) < 0) { |
| 590 | Py_DECREF(item); |
| 591 | Py_DECREF(value); |
| 592 | return false; |
| 593 | } |
| 594 | Py_DECREF(value); |
| 595 | } |
| 596 | |
| 597 | Py_DECREF(item); |
| 598 | } |
| 599 |
nothing calls this directly
no test coverage detected