Skip to content

Commit

Permalink
fix undefined value not converted to gobject
Browse files Browse the repository at this point in the history
  • Loading branch information
CapitaineJSparrow committed Oct 4, 2022
1 parent 8e34d29 commit 23d6474
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1368,8 +1368,15 @@ void FreeGIArgumentArray(GITypeInfo *type_info, GIArgument *arg, GITransfer tran
*/

bool CanConvertV8ToGValue(GValue *gvalue, Local<Value> value) {
auto maybeDetailString = Nan::ToDetailString(value);
Nan::Utf8String utf8String(
!maybeDetailString.IsEmpty() ?
maybeDetailString.ToLocalChecked() :
UTF8("[invalid value]")
);

// void/null
if (G_VALUE_TYPE(gvalue) == G_TYPE_INVALID)
if (G_VALUE_TYPE(gvalue) == G_TYPE_INVALID || strcmp(*utf8String,"undefined") == 0)
return value->IsNullOrUndefined();

if (G_VALUE_HOLDS_BOOLEAN (gvalue)) {
Expand Down Expand Up @@ -1426,8 +1433,7 @@ bool V8ToGValue(GValue *gvalue, Local<Value> value, bool mustCopy) {
maybeDetailString.ToLocalChecked() :
UTF8("[invalid value]")
);
Throw::TypeError("Cannot convert value \"%s\" to type %s",
*utf8String, G_VALUE_TYPE_NAME (gvalue));
Throw::TypeError("Cannot convert value \"%s\" to type %s",*utf8String, G_VALUE_TYPE_NAME (gvalue));
return false;
}

Expand Down

0 comments on commit 23d6474

Please sign in to comment.