| 295 | } |
| 296 | |
| 297 | static bool array_splice(JSContext *cx, unsigned argc, JS::Value *vp) { |
| 298 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
| 299 | |
| 300 | JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv())); |
| 301 | if (!proxy) { |
| 302 | return false; |
| 303 | } |
| 304 | PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot); |
| 305 | |
| 306 | uint64_t selfLength = (uint64_t)PyList_GET_SIZE(self); |
| 307 | |
| 308 | int64_t relativeStart; |
| 309 | if (!JS::ToInt64(cx, args.get(0), &relativeStart)) { |
| 310 | return false; |
| 311 | } |
| 312 | |
| 313 | /* actualStart is the index after which elements will be |
| 314 | deleted and/or new elements will be added */ |
| 315 | uint64_t actualStart; |
| 316 | if (relativeStart < 0) { |
| 317 | actualStart = uint64_t(std::max(double(selfLength) + relativeStart, 0.0)); |
| 318 | } else { |
| 319 | actualStart = uint64_t(std::min(double(relativeStart), double(selfLength))); |
| 320 | } |
| 321 | |
| 322 | unsigned int argsLength = args.length(); |
| 323 | |
| 324 | /* insertCount is the number of elements being added */ |
| 325 | uint32_t insertCount; |
| 326 | if (argsLength < 2) { |
| 327 | insertCount = 0; |
| 328 | } |
| 329 | else { |
| 330 | insertCount = argsLength - 2; |
| 331 | } |
| 332 | |
| 333 | /* actualDeleteCount is the number of elements being deleted */ |
| 334 | uint64_t actualDeleteCount; |
| 335 | if (argsLength < 1) { |
| 336 | actualDeleteCount = 0; |
| 337 | } |
| 338 | else if (argsLength < 2) { |
| 339 | actualDeleteCount = selfLength - actualStart; |
| 340 | } |
| 341 | else { |
| 342 | int64_t deleteCount; |
| 343 | if (!JS::ToInt64(cx, args.get(1), &deleteCount)) { |
| 344 | return false; |
| 345 | } |
| 346 | |
| 347 | actualDeleteCount = uint64_t(std::min(std::max(0.0, double(deleteCount)), double(selfLength - actualStart))); |
| 348 | } |
| 349 | |
| 350 | // get deleted items for return value |
| 351 | PyObject *deleted = PyList_GetSlice(self, actualStart, actualStart + actualDeleteCount); |
| 352 | if (!deleted) { |
| 353 | return false; |
| 354 | } |
nothing calls this directly
no test coverage detected