@@ -1306,6 +1306,14 @@ inline Object::PropertyLValue<uint32_t> Object::operator [](uint32_t index) {
13061306 return PropertyLValue<uint32_t >(*this , index);
13071307}
13081308
1309+ inline Object::PropertyLValue<Value> Object::operator [](Value index) {
1310+ return PropertyLValue<Value>(*this , index);
1311+ }
1312+
1313+ inline Object::PropertyLValue<Value> Object::operator [](Value index) const {
1314+ return PropertyLValue<Value>(*this , index);
1315+ }
1316+
13091317inline MaybeOrValue<Value> Object::operator [](const char * utf8name) const {
13101318 return Get (utf8name);
13111319}
@@ -1530,6 +1538,83 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback,
15301538 }
15311539}
15321540
1541+ #ifdef NAPI_CPP_EXCEPTIONS
1542+ inline Object::const_iterator::const_iterator (const Object* object,
1543+ const Type type) {
1544+ _object = object;
1545+ _keys = object->GetPropertyNames ();
1546+ _index = type == Type::BEGIN ? 0 : _keys.Length ();
1547+ }
1548+
1549+ inline Object::const_iterator Napi::Object::begin () const {
1550+ const_iterator it (this , Object::const_iterator::Type::BEGIN);
1551+ return it;
1552+ }
1553+
1554+ inline Object::const_iterator Napi::Object::end () const {
1555+ const_iterator it (this , Object::const_iterator::Type::END);
1556+ return it;
1557+ }
1558+
1559+ inline Object::const_iterator& Object::const_iterator::operator ++() {
1560+ ++_index;
1561+ return *this ;
1562+ }
1563+
1564+ inline bool Object::const_iterator::operator ==(
1565+ const const_iterator& other) const {
1566+ return _index == other._index ;
1567+ }
1568+
1569+ inline bool Object::const_iterator::operator !=(
1570+ const const_iterator& other) const {
1571+ return _index != other._index ;
1572+ }
1573+
1574+ inline const std::pair<Value, Object::PropertyLValue<Value>>
1575+ Object::const_iterator::operator *() const {
1576+ const Value key = _keys[_index];
1577+ const PropertyLValue<Value> value = (*_object)[key];
1578+ return {key, value};
1579+ }
1580+
1581+ inline Object::iterator::iterator (Object* object, const Type type) {
1582+ _object = object;
1583+ _keys = object->GetPropertyNames ();
1584+ _index = type == Type::BEGIN ? 0 : _keys.Length ();
1585+ }
1586+
1587+ inline Object::iterator Napi::Object::begin () {
1588+ iterator it (this , Object::iterator::Type::BEGIN);
1589+ return it;
1590+ }
1591+
1592+ inline Object::iterator Napi::Object::end () {
1593+ iterator it (this , Object::iterator::Type::END);
1594+ return it;
1595+ }
1596+
1597+ inline Object::iterator& Object::iterator::operator ++() {
1598+ ++_index;
1599+ return *this ;
1600+ }
1601+
1602+ inline bool Object::iterator::operator ==(const iterator& other) const {
1603+ return _index == other._index ;
1604+ }
1605+
1606+ inline bool Object::iterator::operator !=(const iterator& other) const {
1607+ return _index != other._index ;
1608+ }
1609+
1610+ inline std::pair<Value, Object::PropertyLValue<Value>>
1611+ Object::iterator::operator *() {
1612+ Value key = _keys[_index];
1613+ PropertyLValue<Value> value = (*_object)[key];
1614+ return {key, value};
1615+ }
1616+ #endif // NAPI_CPP_EXCEPTIONS
1617+
15331618#if NAPI_VERSION >= 8
15341619inline MaybeOrValue<bool > Object::Freeze () {
15351620 napi_status status = napi_object_freeze (_env, _value);
0 commit comments