Improve error message in sorted() method

This commit is contained in:
Scott Kyle 2016-02-18 12:50:44 -08:00
parent 05d84b23a2
commit bd766297ef
2 changed files with 7 additions and 7 deletions

View File

@ -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);

View File

@ -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");
}
}