private
| 1315 | |
| 1316 | // private |
| 1317 | static uint32_t FlattenIntoArrayWithCallBack(JSContext *cx, |
| 1318 | JSObject *retArray, PyObject *source, |
| 1319 | Py_ssize_t sourceLen, uint32_t start, uint32_t depth, |
| 1320 | JS::HandleValue callBack, JS::HandleObject thisArg) { |
| 1321 | |
| 1322 | uint32_t targetIndex = start; |
| 1323 | |
| 1324 | JS::RootedValue sourceValue(cx, jsTypeFactory(cx, source)); |
| 1325 | JS::Rooted<JS::ValueArray<3>> jArgs(cx); |
| 1326 | JS::RootedValue elementVal(cx); |
| 1327 | JS::RootedValue retVal(cx); |
| 1328 | |
| 1329 | for (uint32_t sourceIndex = 0; sourceIndex < sourceLen; sourceIndex++) { |
| 1330 | if (PyObject_TypeCheck(source, &JSArrayProxyType)) { |
| 1331 | JS_GetElement(cx, *(((JSArrayProxy *)source)->jsArray), sourceIndex, &elementVal); |
| 1332 | } |
| 1333 | else if (PyObject_TypeCheck(source, &PyList_Type)) { |
| 1334 | elementVal.set(jsTypeFactory(cx, PyList_GetItem(source, sourceIndex))); |
| 1335 | } |
| 1336 | |
| 1337 | jArgs[0].set(elementVal); |
| 1338 | jArgs[1].setInt32(sourceIndex); |
| 1339 | jArgs[2].set(sourceValue); |
| 1340 | if (!JS_CallFunctionValue(cx, thisArg, callBack, jArgs, &retVal)) { |
| 1341 | return false; |
| 1342 | } |
| 1343 | |
| 1344 | PyObject *element = pyTypeFactory(cx, retVal); |
| 1345 | |
| 1346 | bool shouldFlatten; |
| 1347 | if (depth > 0) { |
| 1348 | shouldFlatten = PyObject_TypeCheck(element, &JSArrayProxyType) || PyObject_TypeCheck(element, &PyList_Type); |
| 1349 | } else { |
| 1350 | shouldFlatten = false; |
| 1351 | } |
| 1352 | |
| 1353 | Py_ssize_t elementLen; |
| 1354 | if (PyObject_TypeCheck(element, &JSArrayProxyType)) { |
| 1355 | elementLen = JSArrayProxyMethodDefinitions::JSArrayProxy_length((JSArrayProxy *)element); |
| 1356 | } |
| 1357 | else if (PyObject_TypeCheck(element, &PyList_Type)) { |
| 1358 | elementLen = PyList_GET_SIZE(element); |
| 1359 | } |
| 1360 | |
| 1361 | if (shouldFlatten) { |
| 1362 | targetIndex = FlattenIntoArrayWithCallBack(cx, |
| 1363 | retArray, |
| 1364 | element, |
| 1365 | elementLen, |
| 1366 | targetIndex, |
| 1367 | depth - 1, |
| 1368 | callBack, |
| 1369 | thisArg |
| 1370 | ); |
| 1371 | } |
| 1372 | else { |
| 1373 | JS::RootedObject rootedRetArray(cx, retArray); |
| 1374 |
no test coverage detected