private
| 1135 | |
| 1136 | // private |
| 1137 | static bool sort_compare_default(JSContext *cx, unsigned argc, JS::Value *vp) { |
| 1138 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
| 1139 | |
| 1140 | JS::RootedObject callee(cx, &args.callee()); |
| 1141 | JS::RootedValue reverseValue(cx); |
| 1142 | if (!JS_GetProperty(cx, callee, "_reverse_param", &reverseValue)) { |
| 1143 | PyErr_Format(PyExc_SystemError, "%s JSAPI call failed", JSArrayProxyType.tp_name); |
| 1144 | return false; |
| 1145 | } |
| 1146 | bool reverse = reverseValue.toBoolean(); |
| 1147 | |
| 1148 | JS::RootedValue elementVal0(cx, args[0]); |
| 1149 | PyObject *args_0 = pyTypeFactory(cx, elementVal0); |
| 1150 | |
| 1151 | JS::RootedValue elementVal1(cx, args[1]); |
| 1152 | PyObject *args_1 = pyTypeFactory(cx, elementVal1); |
| 1153 | |
| 1154 | int cmp = PyObject_RichCompareBool(args_0, args_1, Py_LT); |
| 1155 | if (cmp > 0) { |
| 1156 | args.rval().setInt32(reverse ? 1 : -1); |
| 1157 | } |
| 1158 | else if (cmp == 0) { |
| 1159 | cmp = PyObject_RichCompareBool(args_0, args_1, Py_EQ); |
| 1160 | if (cmp > 0) { |
| 1161 | args.rval().setInt32(0); |
| 1162 | } |
| 1163 | else if (cmp == 0) { |
| 1164 | args.rval().setInt32(reverse ? -1 : 1); |
| 1165 | } |
| 1166 | else { |
| 1167 | Py_DECREF(args_0); |
| 1168 | Py_DECREF(args_1); |
| 1169 | return false; |
| 1170 | } |
| 1171 | } |
| 1172 | else { |
| 1173 | Py_DECREF(args_0); |
| 1174 | Py_DECREF(args_1); |
| 1175 | return false; |
| 1176 | } |
| 1177 | |
| 1178 | Py_DECREF(args_0); |
| 1179 | Py_DECREF(args_1); |
| 1180 | return true; |
| 1181 | } |
| 1182 | |
| 1183 | PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_sort(JSArrayProxy *self, PyObject *args, PyObject *kwargs) { |
| 1184 | static const char *const _keywords[] = {"key", "reverse", NULL}; |
nothing calls this directly
no test coverage detected