Improve error message in sorted() method
This commit is contained in:
parent
05d84b23a2
commit
bd766297ef
|
@ -101,7 +101,7 @@ JSValueRef ResultsSorted(JSContextRef ctx, JSObjectRef function, JSObjectRef thi
|
|||
std::vector<bool> ascending;
|
||||
|
||||
if (RJSIsValueArray(ctx, arguments[0])) {
|
||||
RJSValidateArgumentCount(argumentCount, 1);
|
||||
RJSValidateArgumentCount(argumentCount, 1, "Second argument is not allowed if passed an array of sort descriptors");
|
||||
|
||||
JSObjectRef js_prop_names = RJSValidatedValueToObject(ctx, arguments[0]);
|
||||
prop_count = RJSValidatedListLength(ctx, js_prop_names);
|
||||
|
|
|
@ -58,21 +58,21 @@ std::string RJSValidatedStringForValue(JSContextRef ctx, JSValueRef value, const
|
|||
JSStringRef RJSStringForString(const std::string &str);
|
||||
JSValueRef RJSValueForString(JSContextRef ctx, const std::string &str);
|
||||
|
||||
inline void RJSValidateArgumentCount(size_t argumentCount, size_t expected) {
|
||||
inline void RJSValidateArgumentCount(size_t argumentCount, size_t expected, const char *message = NULL) {
|
||||
if (argumentCount != expected) {
|
||||
throw std::invalid_argument("Invalid arguments");
|
||||
throw std::invalid_argument(message ?: "Invalid arguments");
|
||||
}
|
||||
}
|
||||
|
||||
inline void RJSValidateArgumentCountIsAtLeast(size_t argumentCount, size_t expected) {
|
||||
inline void RJSValidateArgumentCountIsAtLeast(size_t argumentCount, size_t expected, const char *message = NULL) {
|
||||
if (argumentCount < expected) {
|
||||
throw std::invalid_argument("Invalid arguments");
|
||||
throw std::invalid_argument(message ?: "Invalid arguments");
|
||||
}
|
||||
}
|
||||
|
||||
inline void RJSValidateArgumentRange(size_t argumentCount, size_t min, size_t max) {
|
||||
inline void RJSValidateArgumentRange(size_t argumentCount, size_t min, size_t max, const char *message = NULL) {
|
||||
if (argumentCount < min || argumentCount > max) {
|
||||
throw std::invalid_argument("Invalid arguments");
|
||||
throw std::invalid_argument(message ?: "Invalid arguments");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue