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

Function array_unshift

src/PyListProxyHandler.cc:155–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155static bool array_unshift(JSContext *cx, unsigned argc, JS::Value *vp) { // surely the function name is in there...review JSAPI examples
156 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
157
158 JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv()));
159 if (!proxy) {
160 return false;
161 }
162 PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
163
164 JS::RootedValue elementVal(cx);
165 for (int index = args.length() - 1; index >= 0; index--) {
166 elementVal.set(args[index].get());
167 PyObject *value = pyTypeFactory(cx, elementVal);
168 if (PyList_Insert(self, 0, value) < 0) {
169 Py_DECREF(value);
170 return false;
171 }
172 Py_DECREF(value);
173 }
174
175 args.rval().setInt32(PyList_GET_SIZE(self));
176 return true;
177}
178
179// private util
180static inline uint64_t normalizeSliceTerm(int64_t value, uint64_t length) {

Callers

nothing calls this directly

Calls 3

pyTypeFactoryFunction · 0.85
getMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected