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

Function array_copyWithin

src/PyListProxyHandler.cc:447–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445}
446
447static bool array_copyWithin(JSContext *cx, unsigned argc, JS::Value *vp) {
448 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
449
450 JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv()));
451 if (!proxy) {
452 return false;
453 }
454 PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
455
456 int64_t selfLength = (uint64_t)PyList_GET_SIZE(self);
457
458 unsigned int argsLength = args.length();
459
460 int64_t relativeTarget;
461 if (argsLength > 0) {
462 if (!JS::ToInt64(cx, args.get(0), &relativeTarget)) {
463 return false;
464 }
465 } else {
466 relativeTarget = 0;
467 }
468
469 int64_t actualTarget;
470 if (relativeTarget < 0) {
471 actualTarget = int64_t(std::max(double(selfLength) + relativeTarget, 0.0));
472 } else {
473 actualTarget = int64_t(std::min(double(relativeTarget), double(selfLength)));
474 }
475
476 int64_t relativeStart;
477 if (argsLength > 1) {
478 if (!JS::ToInt64(cx, args.get(1), &relativeStart)) {
479 return false;
480 }
481 } else {
482 relativeStart = 0;
483 }
484
485 int64_t actualStart;
486 if (relativeStart < 0) {
487 actualStart = int64_t(std::max(double(selfLength) + relativeStart, 0.0));
488 } else {
489 actualStart = int64_t(std::min(double(relativeStart), double(selfLength)));
490 }
491
492 int64_t relativeEnd;
493 if (argsLength > 2) {
494 if (!JS::ToInt64(cx, args.get(2), &relativeEnd)) {
495 return false;
496 }
497 } else {
498 relativeEnd = selfLength;
499 }
500
501 int64_t actualEnd;
502 if (relativeEnd < 0) {
503 actualEnd = int64_t(std::max(double(selfLength) + relativeEnd, 0.0));
504 } else {

Callers

nothing calls this directly

Calls 3

jsTypeFactoryFunction · 0.85
getMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected