Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
src,n-api: n-api bug fix
Browse files Browse the repository at this point in the history
* Napi test was failing because of over specifiying
a not condition. Fixed that and also restructured the code to not
iterate over list of properties twice.

* Reintroduced a condition for debugger that got removed
in previous merge.

PR-URL: #264
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
  • Loading branch information
kunalspathak authored and kfarnung committed Jun 5, 2017
1 parent cebc14a commit 3d868ab
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/node_api_jsrt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,34 +552,31 @@ napi_status napi_define_class(napi_env env,
}
}

std::vector<napi_property_descriptor> descriptors;
descriptors.reserve(std::max(instancePropertyCount, staticPropertyCount));
std::vector<napi_property_descriptor> staticDescriptors;
std::vector<napi_property_descriptor> instanceDescriptors;
staticDescriptors.reserve(staticPropertyCount);
instanceDescriptors.reserve(instancePropertyCount);

if (instancePropertyCount > 0) {
for (size_t i = 0; i < property_count; i++) {
if ((properties[i].attributes & napi_static) == 0) {
descriptors.push_back(properties[i]);
}
for (size_t i = 0; i < property_count; i++) {
if ((properties[i].attributes & napi_static) != 0) {
staticDescriptors.push_back(properties[i]);
} else {
instanceDescriptors.push_back(properties[i]);
}

CHECK_NAPI(napi_define_properties(env,
reinterpret_cast<napi_value>(prototype),
descriptors.size(),
descriptors.data()));
}

if (staticPropertyCount > 0) {
descriptors.clear();
for (size_t i = 0; i < property_count; i++) {
if (!(properties[i].attributes & napi_static) != 0) {
descriptors.push_back(properties[i]);
}
}

CHECK_NAPI(napi_define_properties(env,
reinterpret_cast<napi_value>(constructor),
descriptors.size(),
descriptors.data()));
staticDescriptors.size(),
staticDescriptors.data()));
}

if (instancePropertyCount > 0) {
CHECK_NAPI(napi_define_properties(env,
reinterpret_cast<napi_value>(prototype),
instanceDescriptors.size(),
instanceDescriptors.data()));
}

*result = reinterpret_cast<napi_value>(constructor);
Expand Down

0 comments on commit 3d868ab

Please sign in to comment.