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

napi: break dep between v8 and napi attributes #12191

Closed
wants to merge 3 commits into from

Conversation

mhdawson
Copy link
Member

@mhdawson mhdawson commented Apr 3, 2017

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows [commit guidelines][]
Affected core subsystem(s)

napi

The v8 napi implementation had been depending on a one-to-one
relationship between v8 and napi v8 property attributes.
Remove this dependency and fix coverity scan issue
165845 related to mixing enums.

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Apr 3, 2017
@mhdawson mhdawson self-assigned this Apr 3, 2017
src/node_api.cc Outdated
@@ -741,8 +741,19 @@ napi_status napi_define_class(napi_env env,
v8::Local<v8::String> property_name;
CHECK_NEW_FROM_UTF8(isolate, property_name, p->utf8name);

// convert the properties from NAPI to v8 format
unsigned int attribute_flags = v8::None;
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to declare the variable as v8::PropertyAttribute so the cast below wouldn't be necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you do that then the compiler complains because it does not expect you to be oring together enums.

Copy link
Member Author

Choose a reason for hiding this comment

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

at least without adding more casts etc to the or lines. I had tried that first but.

Copy link
Contributor

@digitalinfinity digitalinfinity left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

@aruneshchandra asked me to change the label we use here from napi to n-api, the commit messages should probably follow that too?

src/node_api.cc Outdated
v8::PropertyAttribute attributes =
static_cast<v8::PropertyAttribute>(p->attributes);
static_cast<v8::PropertyAttribute>(attribute_flags);
Copy link
Member

Choose a reason for hiding this comment

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

There is a similar cast in napi_define_properties(), that should probably be changed too. (Generally: How about turning this into a general helper function that also takes care of the typecasting?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Strange that coverity did not report that one. I'll take a look. I had considered a helper by did not do that as it was a one off, with 2 cases will definitely create a helper.

@addaleax addaleax added the node-api Issues and PRs related to the Node-API. label Apr 4, 2017
The v8 n-api implementation had been depending on a one-to-one
relationship between v8 and n-api v8 property attributes.
Remove this dependency and fix coverity scan issue
165845.
@mhdawson
Copy link
Member Author

mhdawson commented Apr 4, 2017

@addaleax pushed commit to address comments.

src/node_api.cc Outdated
@@ -25,6 +25,22 @@ napi_env JsEnvFromV8Isolate(v8::Isolate* isolate) {
return reinterpret_cast<napi_env>(isolate);
}

// convert from n-api property attributes to v8::PropertyAttribute
v8::PropertyAttribute V8PropertyAttributesFromAttributes(
Copy link
Member

Choose a reason for hiding this comment

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

I’d suggest adding static inline since there’s no reason to expose this to the outside world

@mhdawson
Copy link
Member Author

mhdawson commented Apr 5, 2017

Addressed comment.
CI run: https://ci.nodejs.org/job/node-test-pull-request/7230/

@mhdawson
Copy link
Member Author

mhdawson commented Apr 5, 2017

landed as 4a21e39

@mhdawson mhdawson closed this Apr 5, 2017
mhdawson added a commit that referenced this pull request Apr 5, 2017
The v8 n-api implementation had been depending on a one-to-one
relationship between v8 and n-api v8 property attributes.
Remove this dependency and fix coverity scan issue
165845.

PR-URL: #12191
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
@jasnell jasnell mentioned this pull request May 11, 2017
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Apr 10, 2018
The v8 n-api implementation had been depending on a one-to-one
relationship between v8 and n-api v8 property attributes.
Remove this dependency and fix coverity scan issue
165845.

PR-URL: nodejs#12191
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
MylesBorins pushed a commit that referenced this pull request Apr 16, 2018
The v8 n-api implementation had been depending on a one-to-one
relationship between v8 and n-api v8 property attributes.
Remove this dependency and fix coverity scan issue
165845.

Backport-PR-URL: #19447
PR-URL: #12191
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Apr 16, 2018
@mhdawson mhdawson deleted the cover1 branch September 30, 2019 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants