Native methods should convert to numbers/bools

It will still throw if unable to make the conversion. Fixes #51
This commit is contained in:
Scott Kyle 2015-10-12 15:42:56 -07:00
parent 35a8f9816c
commit a4194586ea
3 changed files with 2 additions and 17 deletions

View File

@ -261,7 +261,7 @@ JSValueRef RealmCreateObject(JSContextRef ctx, JSObjectRef function, JSObjectRef
bool update = false;
if (argumentCount == 3) {
update = RJSValidatedValueToBool(ctx, arguments[2]);
update = JSValueToBoolean(ctx, arguments[2]);
}
return RJSObjectCreate(ctx, Object::create<JSValueRef>(ctx, sharedRealm, *object_schema, object, update));

View File

@ -75,7 +75,7 @@ JSValueRef SortByProperty(JSContextRef ctx, JSObjectRef function, JSObjectRef th
bool ascending = true;
if (argumentCount == 2) {
ascending = RJSValidatedValueToBool(ctx, arguments[1]);
ascending = JSValueToBoolean(ctx, arguments[1]);
}
SortOrder sort = {{prop->table_column}, {ascending}};

View File

@ -108,9 +108,6 @@ static inline JSObjectRef RJSValidatedValueToObject(JSContextRef ctx, JSValueRef
static inline double RJSValidatedValueToNumber(JSContextRef ctx, JSValueRef value) {
JSValueRef exception = NULL;
if (!JSValueIsNumber(ctx, value)) {
throw std::runtime_error("Value is not a number");
}
double number = JSValueToNumber(ctx, value, &exception);
if (exception) {
throw RJSException(ctx, exception);
@ -118,18 +115,6 @@ static inline double RJSValidatedValueToNumber(JSContextRef ctx, JSValueRef valu
return number;
}
static inline bool RJSValidatedValueToBool(JSContextRef ctx, JSValueRef value) {
JSValueRef exception = NULL;
if (!JSValueIsBoolean(ctx, value)) {
throw std::runtime_error("Value is not a boolean");
}
bool b = JSValueToNumber(ctx, value, &exception);
if (exception) {
throw RJSException(ctx, exception);
}
return b;
}
static inline JSValueRef RJSValidatedPropertyValue(JSContextRef ctx, JSObjectRef object, JSStringRef property) {
JSValueRef exception = NULL;
JSValueRef propertyValue = JSObjectGetProperty(ctx, object, property, &exception);