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

Function array_shift

src/PyListProxyHandler.cc:127–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127static bool array_shift(JSContext *cx, unsigned argc, JS::Value *vp) {
128 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
129
130 JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv()));
131 if (!proxy) {
132 return false;
133 }
134 PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
135
136 Py_ssize_t selfSize = PyList_GET_SIZE(self);
137
138 if (selfSize == 0) {
139 args.rval().setUndefined();
140 return true;
141 }
142
143 PyObject *result = PyList_GetItem(self, 0);
144 if (!result) {
145 return false;
146 }
147 if (PySequence_DelItem(self, 0) < 0) {
148 return false;
149 }
150
151 args.rval().set(jsTypeFactory(cx, result));
152 return true;
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);

Callers

nothing calls this directly

Calls 2

jsTypeFactoryFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected