-
Notifications
You must be signed in to change notification settings - Fork 30k
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
n-api: Update property attrs enum to match JS spec #12240
Conversation
@mhdawson @TimothyGu please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
{ "readonlyValue", 0, 0, 0, number, napi_read_only, 0}, | ||
{ "hiddenValue", 0, 0, 0, number, napi_read_only | napi_dont_enum, 0}, | ||
{ "echo", Echo, 0, 0, 0, napi_enumerable, 0 }, | ||
{ "accessorValue", 0, GetValue, SetValue, 0, napi_enumerable, 0}, |
There was a problem hiding this comment.
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.
{ "readonlyValue", 0, 0, 0, number, napi_read_only, 0 }, | ||
{ "hiddenValue", 0, 0, 0, number, napi_read_only | napi_dont_enum, 0 }, | ||
{ "echo", Echo, 0, 0, 0, napi_enumerable, 0 }, | ||
{ "accessorValue", 0, GetValue, SetValue, 0, napi_enumerable, 0}, |
There was a problem hiding this comment.
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
// but V8 requires the ReadOnly attribute to match existence of a setter. | ||
attributes = static_cast<v8::PropertyAttribute>(p->setter != nullptr | ||
? attributes & ~v8::PropertyAttribute::ReadOnly | ||
: attributes | v8::PropertyAttribute::ReadOnly); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
|
||
if (p->method) { | ||
if (p->method != nullptr) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
d878c51
to
05586f4
Compare
@TimothyGu I pushed a commit to address your feedback, and also rebased. |
There was a problem hiding this 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 @@ | |||
/****************************************************************************** | |||
/****************************************************************************** |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); | ||
} | ||
else if ((descriptor->attributes & napi_writable) == 0) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
CI green, landing. |
Landed as 8460284 |
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: #12240 Fixes: nodejs/abi-stable-node#221 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Guys I suspect you have a failing test on windows |
this is the diff between the PR and 8460284
|
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#12240 Fixes: nodejs/abi-stable-node#221 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
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: #12240 Fixes: nodejs/abi-stable-node#221 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
The
napi_property_attributes
enum used names and values fromv8::PropertyAttribute
, but those negative flag names were outdatedalong 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), orvcbuild test
(Windows) passesAffected core subsystem(s)
N-API