Skip to content

Commit 444b519

Browse files
committed
squash: address comments
1 parent f2315a9 commit 444b519

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/node_api.cc

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ napi_env JsEnvFromV8Isolate(v8::Isolate* isolate) {
2525
return reinterpret_cast<napi_env>(isolate);
2626
}
2727

28+
// convert from n-api property attributes to v8::PropertyAttribute
29+
v8::PropertyAttribute V8PropertyAttributesFromAttributes(
30+
napi_property_attributes attributes) {
31+
unsigned int attribute_flags = v8::None;
32+
if (attributes & napi_read_only) {
33+
attribute_flags |= v8::ReadOnly;
34+
}
35+
if (attributes & napi_dont_enum) {
36+
attribute_flags |= v8::DontEnum;
37+
}
38+
if (attributes & napi_dont_delete) {
39+
attribute_flags |= v8::DontDelete;
40+
}
41+
return static_cast<v8::PropertyAttribute>(attribute_flags);
42+
}
43+
2844
v8::Isolate* V8IsolateFromJsEnv(napi_env e) {
2945
return reinterpret_cast<v8::Isolate*>(e);
3046
}
@@ -740,20 +756,8 @@ napi_status napi_define_class(napi_env env,
740756

741757
v8::Local<v8::String> property_name;
742758
CHECK_NEW_FROM_UTF8(isolate, property_name, p->utf8name);
743-
744-
// convert the properties from NAPI to v8 format
745-
unsigned int attribute_flags = v8::None;
746-
if ((p->attributes & napi_read_only)) {
747-
attribute_flags |= v8::ReadOnly;
748-
}
749-
if ((p->attributes & napi_dont_enum)) {
750-
attribute_flags |= v8::DontEnum;
751-
}
752-
if ((p->attributes & napi_dont_delete)) {
753-
attribute_flags |= v8::DontDelete;
754-
}
755759
v8::PropertyAttribute attributes =
756-
static_cast<v8::PropertyAttribute>(attribute_flags);
760+
v8impl::V8PropertyAttributesFromAttributes(p->attributes);
757761

758762
// This code is similar to that in napi_define_property(); the
759763
// difference is it applies to a template instead of an object.
@@ -1062,8 +1066,9 @@ napi_status napi_define_properties(napi_env env,
10621066
v8::Local<v8::Name> name;
10631067
CHECK_NEW_FROM_UTF8(isolate, name, p->utf8name);
10641068

1065-
v8::PropertyAttribute attributes = static_cast<v8::PropertyAttribute>(
1066-
p->attributes & ~napi_static_property);
1069+
v8::PropertyAttribute attributes =
1070+
v8impl::V8PropertyAttributesFromAttributes(
1071+
(napi_property_attributes)(p->attributes & ~napi_static_property));
10671072

10681073
if (p->method) {
10691074
v8::Local<v8::Object> cbdata =

0 commit comments

Comments
 (0)