| 1634 | } |
| 1635 | |
| 1636 | static int invokeCallBack(PyObject *list, int index, JS::HandleValue leftValue, JSContext *cx, JS::HandleFunction callBack) { |
| 1637 | JS::Rooted<JS::ValueArray<2>> jArgs(cx); |
| 1638 | |
| 1639 | jArgs[0].set(jsTypeFactory(cx, PyList_GetItem(list, index))); |
| 1640 | jArgs[1].set(leftValue); |
| 1641 | |
| 1642 | JS::RootedValue retVal(cx); |
| 1643 | if (!JS_CallFunction(cx, nullptr, callBack, jArgs, &retVal)) { |
| 1644 | throw "JS_CallFunction failed"; |
| 1645 | } |
| 1646 | |
| 1647 | if (!retVal.isNumber()) { |
| 1648 | PyErr_Format(PyExc_TypeError, "incorrect compare function return type"); |
| 1649 | return 0; |
| 1650 | } |
| 1651 | |
| 1652 | return retVal.toInt32(); |
| 1653 | } |
| 1654 | |
| 1655 | // Adapted from Kernigan&Ritchie's C book |
| 1656 | static void quickSort(PyObject *list, int left, int right, JSContext *cx, JS::HandleFunction callBack) { |
no test coverage detected