File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -1378,6 +1378,37 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback,
1378
1378
}
1379
1379
}
1380
1380
1381
+ Object::iterator::iterator (Object *object, uint32_t index) {
1382
+ _object = object;
1383
+ _index = index ;
1384
+ _keys = object->GetPropertyNames ();
1385
+ }
1386
+
1387
+ Object::iterator Napi::Object::begin () {
1388
+ iterator it (this , 0 );
1389
+ return it;
1390
+ }
1391
+
1392
+ Object::iterator Napi::Object::end () {
1393
+ iterator it (this , GetPropertyNames ().Length ());
1394
+ return it;
1395
+ }
1396
+
1397
+ Object::iterator Object::iterator::operator ++() {
1398
+ ++_index;
1399
+ return *this ;
1400
+ }
1401
+
1402
+ bool Object::iterator::operator !=(iterator other) {
1403
+ return _index != other._index ;
1404
+ }
1405
+
1406
+ Value Object::iterator::operator *() {
1407
+ Value key = _keys[_index].Value (); // Don't know how to convert this yet
1408
+ Object object = *_object;
1409
+ return object[key];
1410
+ }
1411
+
1381
1412
// //////////////////////////////////////////////////////////////////////////////
1382
1413
// External class
1383
1414
// //////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change @@ -742,6 +742,12 @@ namespace Napi {
742
742
inline void AddFinalizer (Finalizer finalizeCallback,
743
743
T* data,
744
744
Hint* finalizeHint);
745
+
746
+ class iterator ;
747
+
748
+ iterator begin ();
749
+
750
+ iterator end ();
745
751
};
746
752
747
753
template <typename T>
@@ -778,6 +784,24 @@ namespace Napi {
778
784
uint32_t Length () const ;
779
785
};
780
786
787
+ class Object ::iterator {
788
+ public:
789
+ iterator (Object *object, uint32_t index);
790
+
791
+ iterator operator ++();
792
+
793
+ bool operator !=(iterator other);
794
+
795
+ Value operator *();
796
+
797
+ private:
798
+ Napi::Object *_object;
799
+ uint32_t _index;
800
+ Array _keys;
801
+
802
+ friend class Object ;
803
+ };
804
+
781
805
// / A JavaScript array buffer value.
782
806
class ArrayBuffer : public Object {
783
807
public:
You can’t perform that action at this time.
0 commit comments