test setting all primitive types to null/undefined throw

This commit is contained in:
Ari Lazier 2015-10-21 20:20:51 -07:00
parent ce682c3f70
commit ac544205a1
2 changed files with 49 additions and 1 deletions

View File

@ -128,6 +128,12 @@ static inline JSObjectRef RJSValidatedValueToFunction(JSContextRef ctx, JSValueR
static inline double RJSValidatedValueToNumber(JSContextRef ctx, JSValueRef value) {
JSValueRef exception = NULL;
if (JSValueIsUndefined(ctx, value)) {
throw std::invalid_argument("`undefined` is not a number.");
}
if (JSValueIsNull(ctx, value)) {
throw std::invalid_argument("`null` is not a number.");
}
double number = JSValueToNumber(ctx, value, &exception);
if (exception) {
throw RJSException(ctx, exception);

View File

@ -73,10 +73,52 @@ module.exports = BaseTest.extend({
TestCase.assertThrows(function() {
obj.boolCol = 'cat';
});
TestCase.assertThrows(function() {
obj.intCol = 'dog';
});
TestCase.assertThrows(function() {
obj.boolCol = null;
});
TestCase.assertThrows(function() {
obj.boolCol = undefined;
});
TestCase.assertThrows(function() {
obj.intCol = null;
});
TestCase.assertThrows(function() {
obj.intCol = undefined;
});
TestCase.assertThrows(function() {
obj.floatCol = null;
});
TestCase.assertThrows(function() {
obj.floatCol = undefined;
});
TestCase.assertThrows(function() {
obj.doubleCol = null;
});
TestCase.assertThrows(function() {
obj.doubleCol = undefined;
});
TestCase.assertThrows(function() {
obj.stringCol = null;
});
TestCase.assertThrows(function() {
obj.stringCol = undefined;
});
TestCase.assertThrows(function() {
obj.dateCol = null;
});
TestCase.assertThrows(function() {
obj.dateCol = undefined;
});
TestCase.assertThrows(function() {
obj.dataCol = null;
});
TestCase.assertThrows(function() {
obj.dataCol = undefined;
});
});
TestCase.assertThrows(function() {