Skip to content

Conversation

@jasongin
Copy link
Member

The napi_property_attributes enum used names and values from
v8::PropertyAttribute, but those negative flag names were outdated
along with the default behavior of a property being writable,
enumerable, and configurable unless otherwise specified. To match the
ES5 standard property descriptor those attributes should be positive
flags and should default to false unless otherwise specified.

Fixes: nodejs/abi-stable-node#221

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

N-API

@nodejs-github-botnodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Apr 5, 2017
@jasongin
Copy link
MemberAuthor

@mhdawson@TimothyGu please review

Copy link
Member

@mhdawsonmhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

@mscdexmscdex added the node-api Issues and PRs related to the Node-API. label Apr 5, 2017
Copy link
Member

Choose a reason for hiding this comment

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

The accessorValue is not actually referenced in the JS layer. You should also find a way to make certain the getters/setters are actually called when getting/setting the property.

Also, tests that cover the normalization logic fully should be added.

Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

src/node_api.cc Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Your call, but I think it might be better if this is factored out?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah I sort of wanted to do that, but it didn't seem right to put it in v8impl::V8PropertyAttributesFromAttributes() because the logic depends on the kind of property descriptor. I'll consider further what to do with this.

src/node_api.cc Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Slightly off-topic and basic, but are the C NULL and the C++ nullptr interoperable?

Copy link
Member

Choose a reason for hiding this comment

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

Slightly off-topic and basic, but are the C NULL and the C++ nullptr interoperable?

Yup. :) The different names are just historical oddities because C++ NULL is not defined the same way as C NULL, so C++11 introduced nullptr as a direct equivalent to C NULL.

The napi_property_attributes enum used names and values from v8::PropertyAttribute, but those negative flag names were outdated along with the default behavior of a property being writable, enumerable, and configurable unless otherwise specified. To match the ES5 standard property descriptor those attributes should be positive flags and should default to false unless otherwise specified. Fixes: nodejs/abi-stable-node#221
@jasonginjasonginforce-pushed the napi_property_attributes branch from d878c51 to 05586f4CompareApril 6, 2017 20:05
@jasongin
Copy link
MemberAuthor

@TimothyGu I pushed a commit to address your feedback, and also rebased.

Copy link
Member

@TimothyGuTimothyGu left a comment

Choose a reason for hiding this comment

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

LGTM except for the nit

src/node_api.cc Outdated
@@ -1,4 +1,4 @@
/******************************************************************************
/******************************************************************************
Copy link
Member

Choose a reason for hiding this comment

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

Do you have an idea what this is?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It's a UTF-8 BOM. VS 2017 likes to insert those for some reason. Fixed.

src/node_api.cc Outdated
attribute_flags |= (descriptor->setter == nullptr ?
v8::PropertyAttribute::ReadOnly : v8::PropertyAttribute::None);
}
elseif ((descriptor->attributes & napi_writable) == 0){
Copy link
Member

Choose a reason for hiding this comment

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

nit: coalesce the right brace with else

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Fixed.

@TimothyGu
Copy link
Member

@mhdawson
Copy link
Member

CI green, landing.

@mhdawson
Copy link
Member

Landed as 8460284

@mhdawsonmhdawson closed this Apr 7, 2017
mhdawson pushed a commit that referenced this pull request Apr 7, 2017
The napi_property_attributes enum used names and values from v8::PropertyAttribute, but those negative flag names were outdated along with the default behavior of a property being writable, enumerable, and configurable unless otherwise specified. To match the ES5 standard property descriptor those attributes should be positive flags and should default to false unless otherwise specified. PR-URL: #12240Fixes: nodejs/abi-stable-node#221 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
@refack
Copy link
Contributor

Guys I suspect you have a failing test on windows
CI: https://ci.nodejs.org/job/node-test-commit/8961/
Lets see.

@refack
Copy link
Contributor

this is the diff between the PR and 8460284

test/addons/make-callback-recurse/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/addons/make-callback-recurse/test.js b/test/addons/make-callback-recurse/test.js index 46b1327d7..895769bc3 100644 --- a/test/addons/make-callback-recurse/test.js +++ b/test/addons/make-callback-recurse/test.js @@ -15,7 +15,7 @@ assert.throws(function(){makeCallback({}, function(){throw new Error('hi from domain error')}); -}); +}, /^Error: hi from domain error$/); // Check the execution order of the nextTickQueue and MicrotaskQueue in 

And it's close to what failed on me on the CI

@refackrefack mentioned this pull request Apr 8, 2017
3 tasks
@jasnelljasnell mentioned this pull request May 11, 2017
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Apr 10, 2018
The napi_property_attributes enum used names and values from v8::PropertyAttribute, but those negative flag names were outdated along with the default behavior of a property being writable, enumerable, and configurable unless otherwise specified. To match the ES5 standard property descriptor those attributes should be positive flags and should default to false unless otherwise specified. PR-URL: nodejs#12240Fixes: nodejs/abi-stable-node#221 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 16, 2018
The napi_property_attributes enum used names and values from v8::PropertyAttribute, but those negative flag names were outdated along with the default behavior of a property being writable, enumerable, and configurable unless otherwise specified. To match the ES5 standard property descriptor those attributes should be positive flags and should default to false unless otherwise specified. Backport-PR-URL: #19447 PR-URL: #12240Fixes: nodejs/abi-stable-node#221 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
@MylesBorinsMylesBorins mentioned this pull request Apr 16, 2018
Sign up for freeto 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-apiIssues and PRs related to the Node-API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modernize napi_property_attributes enum names

8 participants

@jasongin@TimothyGu@mhdawson@refack@addaleax@mscdex@italoacasas@nodejs-github-bot