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: add Env::GetModuleFileName #1327

Closed
wants to merge 3 commits into from

Conversation

KevinEady
Copy link
Contributor

Adds wrapper for Napi::Env::GetModuleFileName() from release of Node-API v9.

@KevinEady
Copy link
Contributor Author

KevinEady commented Jun 10, 2023

Node Version Link Status
20 https://ci.nodejs.org/job/node-test-node-addon-api-new/7560/
21 https://ci.nodejs.org/job/node-test-node-addon-api-new/7561/ ✅*

*: osx1015 failing due to #1328

#if NAPI_VERSION > 8
inline std::string_view Env::GetModuleFileName() const {
const char* result;
napi_status status = node_api_get_module_file_name(_env, &result);
Copy link
Member

@legendecas legendecas Jun 13, 2023

Choose a reason for hiding this comment

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

Node.js v16.x (and add-ons compiled with the common.gypi shipped with Node.js) is still compiled with C++14, however std::string_view is available since c++17. I think we should avoid using c++17 features here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mhmm mhmm that makes sense ... So then would we prefer the alternative of node-addon-api returning a new std::string by copying the const char* result?

Copy link
Member

Choose a reason for hiding this comment

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

Would it be good to return the const char* result? If needed, copying the result with std::string is fairly easy.

@KevinEady KevinEady marked this pull request as draft June 16, 2023 21:35
- Do not use `std::string_view` since not available in C++14 (Node v16)
@KevinEady KevinEady dismissed gabrielschulhof’s stale review June 16, 2023 21:42

Implementation changed

@KevinEady KevinEady marked this pull request as ready for review June 16, 2023 21:42
Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Thanks

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 pushed a commit that referenced this pull request Jun 28, 2023
PR-URL: #1327
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com
@mhdawson
Copy link
Member

Landed in b83e453

@mhdawson mhdawson closed this Jun 28, 2023
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this pull request Aug 11, 2023
PR-URL: nodejs/node-addon-api#1327
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com
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