Native methods should convert to numbers/bools
It will still throw if unable to make the conversion. Fixes #51
This commit is contained in:
parent
35a8f9816c
commit
a4194586ea
|
@ -261,7 +261,7 @@ JSValueRef RealmCreateObject(JSContextRef ctx, JSObjectRef function, JSObjectRef
|
||||||
|
|
||||||
bool update = false;
|
bool update = false;
|
||||||
if (argumentCount == 3) {
|
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));
|
return RJSObjectCreate(ctx, Object::create<JSValueRef>(ctx, sharedRealm, *object_schema, object, update));
|
||||||
|
|
|
@ -75,7 +75,7 @@ JSValueRef SortByProperty(JSContextRef ctx, JSObjectRef function, JSObjectRef th
|
||||||
|
|
||||||
bool ascending = true;
|
bool ascending = true;
|
||||||
if (argumentCount == 2) {
|
if (argumentCount == 2) {
|
||||||
ascending = RJSValidatedValueToBool(ctx, arguments[1]);
|
ascending = JSValueToBoolean(ctx, arguments[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
SortOrder sort = {{prop->table_column}, {ascending}};
|
SortOrder sort = {{prop->table_column}, {ascending}};
|
||||||
|
|
|
@ -108,9 +108,6 @@ static inline JSObjectRef RJSValidatedValueToObject(JSContextRef ctx, JSValueRef
|
||||||
|
|
||||||
static inline double RJSValidatedValueToNumber(JSContextRef ctx, JSValueRef value) {
|
static inline double RJSValidatedValueToNumber(JSContextRef ctx, JSValueRef value) {
|
||||||
JSValueRef exception = NULL;
|
JSValueRef exception = NULL;
|
||||||
if (!JSValueIsNumber(ctx, value)) {
|
|
||||||
throw std::runtime_error("Value is not a number");
|
|
||||||
}
|
|
||||||
double number = JSValueToNumber(ctx, value, &exception);
|
double number = JSValueToNumber(ctx, value, &exception);
|
||||||
if (exception) {
|
if (exception) {
|
||||||
throw RJSException(ctx, exception);
|
throw RJSException(ctx, exception);
|
||||||
|
@ -118,18 +115,6 @@ static inline double RJSValidatedValueToNumber(JSContextRef ctx, JSValueRef valu
|
||||||
return number;
|
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) {
|
static inline JSValueRef RJSValidatedPropertyValue(JSContextRef ctx, JSObjectRef object, JSStringRef property) {
|
||||||
JSValueRef exception = NULL;
|
JSValueRef exception = NULL;
|
||||||
JSValueRef propertyValue = JSObjectGetProperty(ctx, object, property, &exception);
|
JSValueRef propertyValue = JSObjectGetProperty(ctx, object, property, &exception);
|
||||||
|
|
Loading…
Reference in New Issue