MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / array_toLocaleString

Function array_toLocaleString

src/PyListProxyHandler.cc:1554–1605  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1552}
1553
1554static bool array_toLocaleString(JSContext *cx, unsigned argc, JS::Value *vp) {
1555 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1556
1557 JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv()));
1558 if (!proxy) {
1559 return false;
1560 }
1561 PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
1562
1563 Py_ssize_t selfLength = PyList_GET_SIZE(self);
1564
1565 if (selfLength == 0) {
1566 args.rval().setString(JS_NewStringCopyZ(cx, ""));
1567 return true;
1568 }
1569
1570 JS::RootedString rootedSeparator(cx, JS_NewStringCopyZ(cx, ","));
1571
1572 JSString *writer = JS_NewStringCopyZ(cx, "");
1573 JS::RootedString rootedWriter(cx);
1574
1575 JS::HandleValueArray jArgs(args);
1576
1577 for (Py_ssize_t index = 0; index < selfLength; index++) {
1578 rootedWriter.set(writer);
1579 if (index > 0) {
1580 writer = JS_ConcatStrings(cx, rootedWriter, rootedSeparator);
1581 rootedWriter.set(writer);
1582 }
1583
1584 JS::RootedValue element(cx, jsTypeFactory(cx, PyList_GetItem(self, index)));
1585 if (!element.isNullOrUndefined()) {
1586 JS::RootedValue rval(cx);
1587
1588 JS::RootedObject retObject(cx);
1589
1590 if (!JS_ValueToObject(cx, element, &retObject)) {
1591 return false;
1592 }
1593
1594 if (!JS_CallFunctionName(cx, retObject, "toLocaleString", jArgs, &rval)) {
1595 return false;
1596 }
1597
1598 JS::RootedString retString(cx, rval.toString());
1599 writer = JS_ConcatStrings(cx, rootedWriter, retString);
1600 }
1601 }
1602
1603 args.rval().setString(writer);
1604 return true;
1605}
1606
1607static bool array_valueOf(JSContext *cx, unsigned argc, JS::Value *vp) {
1608 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);

Callers

nothing calls this directly

Calls 3

jsTypeFactoryFunction · 0.85
setMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected