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

Add Function::Call Napi::Value override #1026

Merged
merged 2 commits into from
Feb 21, 2022

Conversation

rgerd
Copy link
Contributor

@rgerd rgerd commented Jul 23, 2021

Adds an override to Napi::Function::Call so that you can call it with a c-style array of Napi::Value's

@mhdawson
Copy link
Member

Note from discussion in Node-api team meeting today, we should validate this does not add any performance overhead to the existing cases.

napi-inl.h Outdated Show resolved Hide resolved
@rgerd
Copy link
Contributor Author

rgerd commented Aug 2, 2021

Note from discussion in Node-api team meeting today, we should validate this does not add any performance overhead to the existing cases.

@mhdawson Is there something I should do on my end to validate performance?

@mhdawson
Copy link
Member

mhdawson commented Aug 3, 2021

@rgerd not at this point it was more of a reminder to reviewers of the PR

@mhdawson
Copy link
Member

mhdawson commented Sep 3, 2021

@gabrielschulhof wondering if you have more review questions/comments?

@mhdawson
Copy link
Member

mhdawson commented Sep 10, 2021

@rgerd thanks for your patience, discussed again in the Node-API team meeting today. We agreed this can land once rebased to address the conflicts.

One additional suggestion was that it would make sense to add another overload to accept a std:vector of Value objects either in this or a follow on PR.

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

@legendecas
Copy link
Member

Commented with a question about compatibility issue #1026 (comment). We may need to come to a conclusion about the usage pattern compatibility until we can proceed.

@gabrielschulhof
Copy link
Contributor

gabrielschulhof commented Nov 19, 2021

@rgerd in today's Node-API team meeting @vmoroz brought up a good point, namely that it may not be a good idea to have an override passing a C-style array of napi_value items because having a well-formed array description is a safer choice. For example, C++20 will have std::span<T>.

He proposed that we create a simple, say, Napi::ValueSpan class which will be constructed with napi_value and size_t and create an override that accepts such an instance.

my_function.Call(Napi::ValueSpan(count, values));

We can use C++ templating to create a constructor override that can deduce the length of the array without having to pass it in explicitly as a parameter. We should structure the class definition to match that of std::span<T> exactly, so that, once we start using C++20, we can simply convert the definition to an alias of std::span<T>.

@mhdawson
Copy link
Member

We discussed again in today's Node-API team meeting. The conclusion we came to was that it would be better for signature of the new method to use std::vector. For example:

Value Call(napi_value recv, const std::vector<Value>& args) ;

It is possible to get a Value* array into a std::vector in a few ways (assign, constructor etc.)

@rgerd is this something you'd still like to move forward?

@rgerd
Copy link
Contributor Author

rgerd commented Jan 25, 2022

Hi, thank you very much for the feedback. Yes, I'd still like to move it forward, sorry for disappearing. I should be able to make the changes and validate within the next week or so.

@rgerd
Copy link
Contributor Author

rgerd commented Feb 11, 2022

Rebased with the suggested changes. The style checks are failing on function.js for parts of the file unrelated to my changes, but I also noticed eslint was added after function.js was last touched, so it seems like it hasn't been linted by the CI until now.

I could fix the linting problems myself, but just wanted to check if you have any opinions on introducing a bunch of unrelated diffs in this PR, or if we should open another PR to go in first to address those style changes.

@mhdawson
Copy link
Member

@rgerd its a good question about the linter changes. I think in this case what might makes sense is to have 2 commits in the PR, one for the linter changes and one for the change your are making. When we land we can keep both commits instead of squashing. That seems better than using 2 PR to accomplish the same thing.

@mhdawson
Copy link
Member

@NickNaso will take a look/test on ci and then will go ahead and land.

@NickNaso NickNaso merged commit c54aeef into nodejs:main Feb 21, 2022
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.

5 participants