Skip to content

Commit 3d868ab

Browse files
kunalspathakkfarnung
authored andcommitted
src,n-api: n-api bug fix
* 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: nodejs#264 Reviewed-By: Kyle Farnung <[email protected]> Reviewed-By: Jason Ginchereau <[email protected]>
1 parent cebc14a commit 3d868ab

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/node_api_jsrt.cc

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -552,34 +552,31 @@ napi_status napi_define_class(napi_env env,
552552
}
553553
}
554554

555-
std::vector<napi_property_descriptor> descriptors;
556-
descriptors.reserve(std::max(instancePropertyCount, staticPropertyCount));
555+
std::vector<napi_property_descriptor> staticDescriptors;
556+
std::vector<napi_property_descriptor> instanceDescriptors;
557+
staticDescriptors.reserve(staticPropertyCount);
558+
instanceDescriptors.reserve(instancePropertyCount);
557559

558-
if (instancePropertyCount > 0) {
559-
for (size_t i = 0; i < property_count; i++) {
560-
if ((properties[i].attributes & napi_static) == 0) {
561-
descriptors.push_back(properties[i]);
562-
}
560+
for (size_t i = 0; i < property_count; i++) {
561+
if ((properties[i].attributes & napi_static) != 0) {
562+
staticDescriptors.push_back(properties[i]);
563+
} else {
564+
instanceDescriptors.push_back(properties[i]);
563565
}
564-
565-
CHECK_NAPI(napi_define_properties(env,
566-
reinterpret_cast<napi_value>(prototype),
567-
descriptors.size(),
568-
descriptors.data()));
569566
}
570567

571568
if (staticPropertyCount > 0) {
572-
descriptors.clear();
573-
for (size_t i = 0; i < property_count; i++) {
574-
if (!(properties[i].attributes & napi_static) != 0) {
575-
descriptors.push_back(properties[i]);
576-
}
577-
}
578-
579569
CHECK_NAPI(napi_define_properties(env,
580570
reinterpret_cast<napi_value>(constructor),
581-
descriptors.size(),
582-
descriptors.data()));
571+
staticDescriptors.size(),
572+
staticDescriptors.data()));
573+
}
574+
575+
if (instancePropertyCount > 0) {
576+
CHECK_NAPI(napi_define_properties(env,
577+
reinterpret_cast<napi_value>(prototype),
578+
instanceDescriptors.size(),
579+
instanceDescriptors.data()));
583580
}
584581

585582
*result = reinterpret_cast<napi_value>(constructor);

0 commit comments

Comments
 (0)