Skip to content

Commit

Permalink
Leave platform-specific type in operator def.n
Browse files Browse the repository at this point in the history
The property get/set sugar for numerical indices has to stay platform-
agnostic. That is, we cannot use `uint32_t`, but must instead use `int`
in the operator definition, because `int` resolves exactly on both
32-bit and 64-bit platforms.

Fixes: nodejs#337
  • Loading branch information
Gabriel Schulhof committed Sep 12, 2018
1 parent 622ffae commit ba4ad76
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,8 @@ inline Object::PropertyLValue<std::string> Object::operator [](const std::string
return PropertyLValue<std::string>(*this, utf8name);
}

inline Object::PropertyLValue<uint32_t> Object::operator [](uint32_t index) {
return PropertyLValue<uint32_t>(*this, index);
inline Object::PropertyLValue<int> Object::operator [](int index) {
return PropertyLValue<int>(*this, index);
}

inline Value Object::operator [](const char* utf8name) const {
Expand All @@ -795,7 +795,7 @@ inline Value Object::operator [](const std::string& utf8name) const {
return Get(utf8name);
}

inline Value Object::operator [](uint32_t index) const {
inline Value Object::operator [](int index) const {
return Get(index);
}

Expand Down
6 changes: 3 additions & 3 deletions napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ namespace Napi {
);

/// Gets or sets an indexed property or array element.
PropertyLValue<uint32_t> operator [](
uint32_t index /// Property / element index
PropertyLValue<int> operator [](
int index /// Property / element index
);

/// Gets a named property.
Expand All @@ -411,7 +411,7 @@ namespace Napi {

/// Gets an indexed property or array element.
Value operator [](
uint32_t index ///< Property / element index
int index ///< Property / element index
) const;

/// Checks whether a property is present.
Expand Down

0 comments on commit ba4ad76

Please sign in to comment.