File tree 2 files changed +65
-0
lines changed
2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -1379,6 +1379,41 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback,
1379
1379
}
1380
1380
}
1381
1381
1382
+ inline Object::iterator::iterator (const Object* object, const Type type) {
1383
+ _object = object;
1384
+ _keys = object->GetPropertyNames ();
1385
+ _index = type == Type::BEGIN ? 0 : _keys.Length ();
1386
+ }
1387
+
1388
+ inline Object::iterator Napi::Object::begin () {
1389
+ iterator it (this , Object::iterator::Type::BEGIN);
1390
+ return it;
1391
+ }
1392
+
1393
+ inline Object::iterator Napi::Object::end () {
1394
+ iterator it (this , Object::iterator::Type::END);
1395
+ return it;
1396
+ }
1397
+
1398
+ inline Object::iterator& Object::iterator::operator ++() {
1399
+ ++_index;
1400
+ return *this ;
1401
+ }
1402
+
1403
+ inline bool Object::iterator::operator ==(const iterator& other) const {
1404
+ return _index == other._index ;
1405
+ }
1406
+
1407
+ inline bool Object::iterator::operator !=(const iterator& other) const {
1408
+ return _index != other._index ;
1409
+ }
1410
+
1411
+ inline std::pair<Value, Value> Object::iterator::operator *() const {
1412
+ const Value key = _keys.Get (_index);
1413
+ const Value value = _object->Get (key);
1414
+ return {key, value};
1415
+ }
1416
+
1382
1417
#if NAPI_VERSION >= 8
1383
1418
inline void Object::Freeze () {
1384
1419
napi_status status = napi_object_freeze (_env, _value);
Original file line number Diff line number Diff line change @@ -776,6 +776,13 @@ namespace Napi {
776
776
inline void AddFinalizer (Finalizer finalizeCallback,
777
777
T* data,
778
778
Hint* finalizeHint);
779
+
780
+ class iterator ;
781
+
782
+ inline iterator begin ();
783
+
784
+ inline iterator end ();
785
+
779
786
#if NAPI_VERSION >= 8
780
787
void Freeze ();
781
788
void Seal ();
@@ -816,6 +823,29 @@ namespace Napi {
816
823
uint32_t Length () const ;
817
824
};
818
825
826
+ class Object ::iterator {
827
+ private:
828
+ enum class Type { BEGIN, END };
829
+
830
+ inline iterator (const Object* object, const Type type);
831
+
832
+ public:
833
+ inline iterator& operator ++();
834
+
835
+ inline bool operator ==(const iterator& other) const ;
836
+
837
+ inline bool operator !=(const iterator& other) const ;
838
+
839
+ inline std::pair<Value, Value> operator *() const ;
840
+
841
+ private:
842
+ const Napi::Object* _object;
843
+ Array _keys;
844
+ uint32_t _index;
845
+
846
+ friend class Object ;
847
+ };
848
+
819
849
// / A JavaScript array buffer value.
820
850
class ArrayBuffer : public Object {
821
851
public:
You can’t perform that action at this time.
0 commit comments