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

Method JSArrayProxy_insert

src/JSArrayProxy.cc:788–835  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

786}
787
788PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_insert(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs) {
789 PyObject *return_value = NULL;
790 Py_ssize_t index;
791 PyObject *value;
792
793 if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
794 return NULL;
795 }
796
797 {
798 Py_ssize_t ival = -1;
799 PyObject *iobj = PyNumber_Index(args[0]);
800 if (iobj != NULL) {
801 ival = PyLong_AsSsize_t(iobj);
802 Py_DECREF(iobj);
803 }
804 if (ival == -1 && PyErr_Occurred()) {
805 return NULL;
806 }
807 index = ival;
808 }
809
810 value = args[1];
811
812 Py_ssize_t n = JSArrayProxy_length(self);
813
814 if (index < 0) {
815 index += n;
816 if (index < 0) {
817 index = 0;
818 }
819 }
820 if (index > n) {
821 index = n;
822 }
823
824 JS::Rooted<JS::ValueArray<3>> jArgs(GLOBAL_CX);
825 jArgs[0].setInt32(index);
826 jArgs[1].setInt32(0);
827 jArgs[2].set(jsTypeFactory(GLOBAL_CX, value));
828
829 JS::RootedValue jReturnedArray(GLOBAL_CX);
830 if (!JS_CallFunctionName(GLOBAL_CX, *(self->jsArray), "splice", jArgs, &jReturnedArray)) {
831 PyErr_Format(PyExc_SystemError, "%s JSAPI call failed", JSArrayProxyType.tp_name);
832 return NULL;
833 }
834 Py_RETURN_NONE;
835}
836
837PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_extend(JSArrayProxy *self, PyObject *iterable) {
838 if (PyList_CheckExact(iterable) || PyTuple_CheckExact(iterable) || (PyObject *)self == iterable) {

Callers

nothing calls this directly

Calls 3

_PyArg_CheckPositionalFunction · 0.85
jsTypeFactoryFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected