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

Function array_slice

src/PyListProxyHandler.cc:193–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193static bool array_slice(JSContext *cx, unsigned argc, JS::Value *vp) {
194 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
195
196 if (!args.requireAtLeast(cx, "slice", 1)) {
197 return false;
198 }
199
200 JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv()));
201 if (!proxy) {
202 return false;
203 }
204 PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
205
206 Py_ssize_t selfLength = PyList_GET_SIZE(self);
207
208 uint64_t start = 0;
209 uint64_t stop = selfLength;
210 if (args.length() > 0) {
211 int64_t d;
212
213 if (!JS::ToInt64(cx, args[0], &d)) {
214 return false;
215 }
216
217 start = normalizeSliceTerm(d, selfLength);
218
219 if (args.hasDefined(1)) {
220 if (!JS::ToInt64(cx, args[1], &d)) {
221 return false;
222 }
223
224 stop = normalizeSliceTerm(d, selfLength);
225 }
226 }
227
228 PyObject *result = PyList_GetSlice(self, (Py_ssize_t)start, (Py_ssize_t)stop);
229 if (!result) {
230 return false;
231 }
232
233 args.rval().set(jsTypeFactory(cx, result));
234 Py_DECREF(result);
235 return true;
236}
237
238static bool array_indexOf(JSContext *cx, unsigned argc, JS::Value *vp) {
239 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);

Callers

nothing calls this directly

Calls 3

normalizeSliceTermFunction · 0.85
jsTypeFactoryFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected