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

Function array_sort

src/PyListProxyHandler.cc:1734–1780  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1732}
1733
1734static bool array_sort(JSContext *cx, unsigned argc, JS::Value *vp) {
1735 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1736
1737 JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv()));
1738 if (!proxy) {
1739 return false;
1740 }
1741 PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot);
1742
1743 Py_ssize_t len = PyList_GET_SIZE(self);
1744
1745 if (len > 1) {
1746 if (args.length() < 1) {
1747 JS::RootedFunction funObj(cx, JS_NewFunction(cx, js_sort_compare_default, 2, 0, NULL));
1748
1749 try {
1750 quickSort(self, 0, len - 1, cx, funObj);
1751 } catch (const char *message) {
1752 return false;
1753 }
1754 }
1755 else {
1756 JS::Value callbackfn = args[0].get();
1757
1758 if (!callbackfn.isObject() || !JS::IsCallable(&callbackfn.toObject())) {
1759 JS_ReportErrorNumberASCII(cx, js::GetErrorMessage, nullptr, JSMSG_BAD_SORT_ARG);
1760 return false;
1761 }
1762
1763 JS::RootedValue callBack(cx, callbackfn);
1764 JS::RootedFunction rootedFun(cx, JS_ValueToFunction(cx, callBack));
1765 try {
1766 quickSort(self, 0, len - 1, cx, rootedFun);
1767 } catch (const char *message) {
1768 return false;
1769 }
1770 }
1771 }
1772
1773 if (PyErr_Occurred()) {
1774 return false;
1775 }
1776
1777 // return ref to self
1778 args.rval().set(jsTypeFactory(cx, self));
1779 return true;
1780}
1781
1782
1783

Callers

nothing calls this directly

Calls 4

quickSortFunction · 0.85
jsTypeFactoryFunction · 0.85
getMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected