Skip to content

Commit 4a21e39

Browse files
committed
n-api: break dep between v8 and napi attributes
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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
1 parent 1f74b9f commit 4a21e39

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/node_api.cc

+20-4
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+
static inline 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,9 +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-
744759
v8::PropertyAttribute attributes =
745-
static_cast<v8::PropertyAttribute>(p->attributes);
760+
v8impl::V8PropertyAttributesFromAttributes(p->attributes);
746761

747762
// This code is similar to that in napi_define_property(); the
748763
// difference is it applies to a template instead of an object.
@@ -1051,8 +1066,9 @@ napi_status napi_define_properties(napi_env env,
10511066
v8::Local<v8::Name> name;
10521067
CHECK_NEW_FROM_UTF8(isolate, name, p->utf8name);
10531068

1054-
v8::PropertyAttribute attributes = static_cast<v8::PropertyAttribute>(
1055-
p->attributes & ~napi_static_property);
1069+
v8::PropertyAttribute attributes =
1070+
v8impl::V8PropertyAttributesFromAttributes(
1071+
(napi_property_attributes)(p->attributes & ~napi_static_property));
10561072

10571073
if (p->method) {
10581074
v8::Local<v8::Object> cbdata =

0 commit comments

Comments
 (0)