You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Define iterator for Napi::Array for using with ranged for-loop or STL algorithms #830
Currently, the only way to loop over the Napi::Array is to maintain the index manually and loop over using traditional for loops:
auto napiArray = Napi::Array::New(info.Env());
for (uint32_t i = 0, len = cppVector.size(); i < len; i++) {
napiArray[i] = Napi::Number::New(info.Env(), cppVector[i]);
}
However, I'd like to be able to use ranged for loop or STL algorithms:
auto napiArray = Napi::Array::New(info.Env());
std::transform(cppVector.begin(), cppVector.end(), napiArray.begin(),
[&info](auto a) { returnNapi::Number::New(info.Env(), a); });
We shouldn't necessarily use the same iterator for these two types. I expect the Array to work the same as std::vector. But Napi::Object is more similar to std::map.
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.
We discussed in the Node-API team meeting today and it seems reasonable but it might be a more complicated due to sparse arrays etc. @aminya would you be able to submit a PR?
Activity
RaisinTen commentedon Nov 18, 2020
@aminya perhaps you mean an iterator for
Napi::ObjectbecauseNapi::Arrayinherits fromNapi::Object. What should the iterator invalidation rules be?aminya commentedon Nov 18, 2020
We shouldn't necessarily use the same iterator for these two types. I expect the
Arrayto work the same asstd::vector. ButNapi::Objectis more similar tostd::map.github-actions commentedon Feb 17, 2021
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.
aminya commentedon Feb 17, 2021
Unstale
mhdawson commentedon Feb 19, 2021
We discussed in the Node-API team meeting today and it seems reasonable but it might be a more complicated due to sparse arrays etc. @aminya would you be able to submit a PR?
src: add iterator for Object
RaisinTen commentedon Mar 13, 2021
PR to add an iterator for
Napi::Object: #930src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
aminya commentedon Apr 13, 2021
This isn't fixed yet, though.
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object
src: add iterator for Object