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

src: refactor call js wrapper #1242

Merged
merged 3 commits into from
Dec 12, 2022
Merged

Conversation

JckXia
Copy link
Member

@JckXia JckXia commented Nov 28, 2022

The visual studio compiler seems to have an issue with deducting the type of call (#1237), which prevents us from using the std::enable_if statement to handle cases where CallJs isn't provided by the user. This PR aims to work around this issue.

@JckXia JckXia changed the title Src refactor call js wrapper src: refactor call js wrapper Nov 28, 2022
Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

@mhdawson
Copy link
Member

mhdawson commented Dec 1, 2022

This looks reasonable to me. @KevinEady could you take a look as well?

@KevinEady
Copy link
Contributor

Hi @mhdawson / @JckXia ,

The concern of doing this if check at run-time is this conditional will now be executed for every call of the TFSN, whereas before it was determined at compile-time. This may add an amount -- albeit negligible -- of additional computation needed per every call. This was the reasoning of using template metaprogramming.

I remember we needed to wait to land the the TypedTSFN until Node 10 was decommissioned because the std::enable_if was not supported in that Node 10's minimum GCC compiler version. I suppose we did not check for Visual Studio 2017 🤦 Check the original PR here #687

@mhdawson
Copy link
Member

mhdawson commented Dec 2, 2022

We discussed in last team meeting and @vmoroz will try out using the std in a slightly different way that he has used as a work around before.

@vmoroz
Copy link
Member

vmoroz commented Dec 4, 2022

I have addressed this issue in the new PR #1245. It seems that we had two problems:

  • The function declaration has wrong order of "modifiers": the static inline modifiers must be before the return type.
    • BTW, as the best practice we must never use static keyword for functions in header files - it produces very inefficient compiled code - each cpp file will have their own copy of such function. I am fixing all such uses in PR src, test: fix errors and warnings in VS 2017 #1245.
  • It also seems that VS 2017 does not allow comparison of function pointers with nullptr. We must cast nullptr to the function type to get it passed.

@JckXia feel free to get the fix from my PR to this one. Then, I will rescope my PR to have just warning fixes in VS 2017.

@JckXia
Copy link
Member Author

JckXia commented Dec 4, 2022

Thanks @vmoroz! I updated my PR to incorporate this workaround.

Copy link
Member

@vmoroz vmoroz left a comment

Choose a reason for hiding this comment

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

LGTM

@KevinEady
Copy link
Contributor

KevinEady commented Dec 9, 2022

Copy link
Contributor

@KevinEady KevinEady left a comment

Choose a reason for hiding this comment

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

LGTM!

@JckXia JckXia merged commit ad7ff92 into nodejs:main Dec 12, 2022
@JckXia
Copy link
Member Author

JckXia commented Dec 12, 2022

Landed as ad7ff92

@JckXia JckXia deleted the src-refactor-call-js-wrapper branch December 12, 2022 17:05
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.

4 participants