Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix undefined value not converted to gobject #334

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

CapitaineJSparrow
Copy link

@CapitaineJSparrow CapitaineJSparrow commented Oct 4, 2022

Fix #333 (confirmed on my end)

I'm not sure about myself, undefined is not in glib constants so I compare the type of value as string. I'm new to this project and it's the first lines of C code I write since decades so may be not the right fix.

@CapitaineJSparrow
Copy link
Author

Added unit test, failing on master but working with my PR

Comment on lines +1371 to 1380
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();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check seems a bit more complex than it needs to be. The last line here already tells you how to check if a value is undefined, but you could only check for undefined with value->IsUndefined(). Which is way better because this function is called very often and we don't want a string comparisons to be run for each call to this function.

Could you also tell me a bit more about the root cause of #333? Reason is, this function checks if we can convert a V8 value into a GValue's type. But if we add a check if (... || value->IsUndefined()) return value->IsNullOrUndefined(), then we're returning true for any call to this where value === undefined, even if the GType we want to convert to isn't void.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I don't have enough knowledge to tell you the root cause of #333 Consider my PR as a bug report I don't understand a lot about V8 and how the library works internally, neither cpp code. The only interesting part in my PR is the unit test. I'm marking this PR as draft.

But if we add a check if (... || value->IsUndefined()) return value->IsNullOrUndefined(), then we're returning true for any call to this where value === undefined, even if the GType we want to convert to isn't void.

You are completely right here, do you see a better approach to manage this case ?

@CapitaineJSparrow CapitaineJSparrow marked this pull request as draft October 17, 2022 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"focus-out-event" crashes application
2 participants