| 1491 | } |
| 1492 | |
| 1493 | static bool array_join(JSContext *cx, unsigned argc, JS::Value *vp) { |
| 1494 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
| 1495 | |
| 1496 | JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv())); |
| 1497 | if (!proxy) { |
| 1498 | return false; |
| 1499 | } |
| 1500 | PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot); |
| 1501 | |
| 1502 | Py_ssize_t selfLength = PyList_GET_SIZE(self); |
| 1503 | |
| 1504 | if (selfLength == 0) { |
| 1505 | args.rval().setString(JS_NewStringCopyZ(cx, "")); |
| 1506 | return true; |
| 1507 | } |
| 1508 | |
| 1509 | JS::RootedString rootedSeparator(cx); |
| 1510 | if (args.hasDefined(0)) { |
| 1511 | rootedSeparator.set(JS::ToString(cx, args[0])); |
| 1512 | } |
| 1513 | else { |
| 1514 | rootedSeparator.set(JS_NewStringCopyZ(cx, ",")); |
| 1515 | } |
| 1516 | |
| 1517 | JSString *writer = JS_NewStringCopyZ(cx, ""); |
| 1518 | JS::RootedString rootedWriter(cx); |
| 1519 | |
| 1520 | for (Py_ssize_t index = 0; index < selfLength; index++) { |
| 1521 | rootedWriter.set(writer); |
| 1522 | if (index > 0) { |
| 1523 | writer = JS_ConcatStrings(cx, rootedWriter, rootedSeparator); |
| 1524 | rootedWriter.set(writer); |
| 1525 | } |
| 1526 | |
| 1527 | JS::RootedValue element(cx, jsTypeFactory(cx, PyList_GetItem(self, index))); |
| 1528 | if (!element.isNullOrUndefined()) { |
| 1529 | JS::RootedValue rval(cx); |
| 1530 | |
| 1531 | JS::RootedObject retObject(cx); |
| 1532 | |
| 1533 | if (!JS_ValueToObject(cx, element, &retObject)) { |
| 1534 | return false; |
| 1535 | } |
| 1536 | |
| 1537 | if (!JS_CallFunctionName(cx, retObject, "toString", JS::HandleValueArray::empty(), &rval)) { |
| 1538 | return false; |
| 1539 | } |
| 1540 | |
| 1541 | JS::RootedString retString(cx, rval.toString()); |
| 1542 | writer = JS_ConcatStrings(cx, rootedWriter, retString); |
| 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | args.rval().setString(writer); |
| 1547 | return true; |
| 1548 | } |
| 1549 | |
| 1550 | static bool array_toString(JSContext *cx, unsigned argc, JS::Value *vp) { |
no test coverage detected