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

Function array_flat

src/PyListProxyHandler.cc:1415–1440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1413}
1414
1415static bool array_flat(JSContext *cx, unsigned argc, JS::Value *vp) {
1416 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1417
1418 JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv()));
1419 if (!proxy) {
1420 return false;
1421 }
1422 PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
1423
1424 Py_ssize_t sourceLen = PyList_GET_SIZE(self);
1425
1426 uint32_t depthNum;
1427 if (args.length() > 0) {
1428 depthNum = args[0].get().toInt32();
1429 }
1430 else {
1431 depthNum = 1;
1432 }
1433
1434 JSObject *retArray = JS::NewArrayObject(cx, sourceLen); // min end length
1435
1436 FlattenIntoArray(cx, retArray, self, sourceLen, 0, depthNum);
1437
1438 args.rval().setObject(*retArray);
1439 return true;
1440}
1441
1442static bool array_flatMap(JSContext *cx, unsigned argc, JS::Value *vp) {
1443 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);

Callers

nothing calls this directly

Calls 2

FlattenIntoArrayFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected