Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark methods of wrapper classes const #874

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions doc/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ Returns a `bool` indicating if an exception is pending in the environment.
### GetAndClearPendingException

```cpp
Napi::Error Napi::Env::GetAndClearPendingException();
Napi::Error Napi::Env::GetAndClearPendingException() const;
```

Returns an `Napi::Error` object representing the environment's pending exception, if any.

### RunScript

```cpp
Napi::Value Napi::Env::RunScript(____ script);
Napi::Value Napi::Env::RunScript(____ script) const;
```
- `[in] script`: A string containing JavaScript code to execute.

Expand All @@ -78,7 +78,7 @@ The `script` can be any of the following types:

### GetInstanceData
```cpp
template <typename T> T* GetInstanceData();
template <typename T> T* GetInstanceData() const;
```

Returns the instance data that was previously associated with the environment,
Expand All @@ -89,7 +89,7 @@ or `nullptr` if none was associated.
```cpp
template <typename T> using Finalizer = void (*)(Env, T*);
template <typename T, Finalizer<T> fini = Env::DefaultFini<T>>
void SetInstanceData(T* data);
void SetInstanceData(T* data) const;
```

- `[template] fini`: A function to call when the instance data is to be deleted.
Expand All @@ -112,7 +112,7 @@ template <typename DataType,
typename HintType,
FinalizerWithHint<DataType, HintType> fini =
Env::DefaultFiniWithHint<DataType, HintType>>
void SetInstanceData(DataType* data, HintType* hint);
void SetInstanceData(DataType* data, HintType* hint) const;
```

- `[template] fini`: A function to call when the instance data is to be deleted.
Expand Down
129 changes: 20 additions & 109 deletions doc/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Creates a new `Napi::Object` value.
### Set()

```cpp
bool Napi::Object::Set (____ key, ____ value);
bool Napi::Object::Set (____ key, ____ value) const;
```
- `[in] key`: The name for the property being assigned.
- `[in] value`: The value being assigned to the property.
Expand All @@ -91,7 +91,7 @@ The `value` can be of any type that is accepted by [`Napi::Value::From`][].
### Delete()

```cpp
bool Napi::Object::Delete(____ key);
bool Napi::Object::Delete(____ key) const;
```
- `[in] key`: The name of the property to delete.

Expand Down Expand Up @@ -143,7 +143,7 @@ Note: This is equivalent to the JavaScript instanceof operator.
### AddFinalizer()
```cpp
template <typename Finalizer, typename T>
inline void AddFinalizer(Finalizer finalizeCallback, T* data);
inline void AddFinalizer(Finalizer finalizeCallback, T* data) const;
```

- `[in] finalizeCallback`: The function to call when the object is garbage-collected.
Expand All @@ -161,7 +161,7 @@ where `data` is the pointer that was passed into the call to `AddFinalizer()`.
template <typename Finalizer, typename T, typename Hint>
inline void AddFinalizer(Finalizer finalizeCallback,
T* data,
Hint* finalizeHint);
Hint* finalizeHint) const;
```

- `[in] data`: The data to associate with the object.
Expand All @@ -184,7 +184,7 @@ The properties whose key is a `Symbol` will not be included.

### HasOwnProperty()
```cpp
bool Napi::Object::HasOwnProperty(____ key); const
bool Napi::Object::HasOwnProperty(____ key) const;
```
- `[in] key` The name of the property to check.

Expand All @@ -200,7 +200,7 @@ The key can be any of the following types:
### DefineProperty()

```cpp
bool Napi::Object::DefineProperty (const Napi::PropertyDescriptor& property);
bool Napi::Object::DefineProperty (const Napi::PropertyDescriptor& property) const;
```
- `[in] property`: A [`Napi::PropertyDescriptor`](property_descriptor.md).

Expand All @@ -209,7 +209,7 @@ Define a property on the object.
### DefineProperties()

```cpp
bool Napi::Object::DefineProperties (____ properties)
bool Napi::Object::DefineProperties (____ properties) const;
```
- `[in] properties`: A list of [`Napi::PropertyDescriptor`](property_descriptor.md). Can be one of the following types:
- const std::initializer_list<Napi::PropertyDescriptor>&
Expand All @@ -220,7 +220,7 @@ Defines properties on the object.
### Freeze()

```cpp
void Napi::Object::Freeze()
void Napi::Object::Freeze() const;
```

The `Napi::Object::Freeze()` method freezes an object. A frozen object can no
Expand All @@ -233,7 +233,7 @@ freezing an object also prevents its prototype from being changed.
### Seal()

```cpp
void Napi::Object::Seal()
void Napi::Object::Seal() const;
```

The `Napi::Object::Seal()` method seals an object, preventing new properties
Expand All @@ -244,77 +244,44 @@ writable.
### operator\[\]()

```cpp
Napi::PropertyLValue<std::string> Napi::Object::operator[] (const char* utf8name);
Napi::PropertyLValue<std::string> Napi::Object::operator[] (const char* utf8name) const;
```
- `[in] utf8name`: UTF-8 encoded null-terminated property name.

Returns a [`Napi::Object::PropertyLValue`](propertylvalue.md) as the named
property or sets the named property.

```cpp
Napi::PropertyLValue<std::string> Napi::Object::operator[] (const std::string& utf8name);
Napi::PropertyLValue<std::string> Napi::Object::operator[] (const std::string& utf8name) const;
```
- `[in] utf8name`: UTF-8 encoded property name.

Returns a [`Napi::Object::PropertyLValue`](propertylvalue.md) as the named
property or sets the named property.

```cpp
Napi::PropertyLValue<uint32_t> Napi::Object::operator[] (uint32_t index);
Napi::PropertyLValue<uint32_t> Napi::Object::operator[] (uint32_t index) const;
```
- `[in] index`: Element index.

Returns a [`Napi::Object::PropertyLValue`](propertylvalue.md) or sets an
indexed property or array element.

```cpp
Napi::Value Napi::Object::operator[] (const char* utf8name) const;
```
- `[in] utf8name`: UTF-8 encoded null-terminated property name.

Returns the named property as a [`Napi::Value`](value.md).

```cpp
Napi::Value Napi::Object::operator[] (const std::string& utf8name) const;
```
- `[in] utf8name`: UTF-8 encoded property name.

Returns the named property as a [`Napi::Value`](value.md).

```cpp
Napi::Value Napi::Object::operator[] (uint32_t index) const;
```
- `[in] index`: Element index.

Returns an indexed property or array element as a [`Napi::Value`](value.md).

### begin()

```cpp
Napi::Object::iterator Napi::Object::begin() const;
```

Returns a constant iterator to the beginning of the object.

```cpp
Napi::Object::iterator Napi::Object::begin();
```

Returns a non constant iterator to the beginning of the object.
Returns an iterator to the beginning of the object.

### end()

```cpp
Napi::Object::iterator Napi::Object::end() const;
```

Returns a constant iterator to the end of the object.

```cpp
Napi::Object::iterator Napi::Object::end();
```

Returns a non constant iterator to the end of the object.
Returns an iterator to the end of the object.

## Iterator

Expand All @@ -324,71 +291,15 @@ Iterators expose an `std::pair<...>`, where the `first` property is a
holds the currently iterated value. Iterators are only available if C++
exceptions are enabled (by defining `NAPI_CPP_EXCEPTIONS` during the build).

### Constant Iterator

In constant iterators, the iterated values are immutable.

#### operator++()

```cpp
inline Napi::Object::const_iterator& Napi::Object::const_iterator::operator++();
```

Moves the iterator one step forward.

#### operator==

```cpp
inline bool Napi::Object::const_iterator::operator==(const Napi::Object::const_iterator& other) const;
```
- `[in] other`: Another iterator to compare the current iterator to.

Returns whether both iterators are at the same index.

#### operator!=

```cpp
inline bool Napi::Object::const_iterator::operator!=(const Napi::Object::const_iterator& other) const;
```
- `[in] other`: Another iterator to compare the current iterator to.

Returns whether both iterators are at different indices.

#### operator*()

```cpp
inline const std::pair<Napi::Value, Napi::Object::PropertyLValue<Napi::Value>> Napi::Object::const_iterator::operator*() const;
```

Returns the currently iterated key and value.

#### Example
```cpp
Value Sum(const CallbackInfo& info) {
Object object = info[0].As<Object>();
int64_t sum = 0;

for (const auto& e : object) {
sum += static_cast<Value>(e.second).As<Number>().Int64Value();
}

return Number::New(info.Env(), sum);
}
```

### Non Constant Iterator

In non constant iterators, the iterated values are mutable.

#### operator++()
### operator++()

```cpp
inline Napi::Object::iterator& Napi::Object::iterator::operator++();
```

Moves the iterator one step forward.

#### operator==
### operator==

```cpp
inline bool Napi::Object::iterator::operator==(const Napi::Object::iterator& other) const;
Expand All @@ -397,7 +308,7 @@ inline bool Napi::Object::iterator::operator==(const Napi::Object::iterator& oth

Returns whether both iterators are at the same index.

#### operator!=
### operator!=

```cpp
inline bool Napi::Object::iterator::operator!=(const Napi::Object::iterator& other) const;
Expand All @@ -406,15 +317,15 @@ inline bool Napi::Object::iterator::operator!=(const Napi::Object::iterator& oth

Returns whether both iterators are at different indices.

#### operator*()
### operator*()

```cpp
inline std::pair<Napi::Value, Napi::Object::PropertyLValue<Napi::Value>> Napi::Object::iterator::operator*();
inline std::pair<Napi::Value, Napi::Object::PropertyLValue<Napi::Value>> Napi::Object::iterator::operator*() const;
```

Returns the currently iterated key and value.

#### Example
### Example
```cpp
void Increment(const CallbackInfo& info) {
Env env = info.Env();
Expand Down
2 changes: 1 addition & 1 deletion doc/object_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ The `value` can be any of the following types:
### Get

```cpp
Napi::Value Napi::ObjectReference::Get(___ key);
Napi::Value Napi::ObjectReference::Get(___ key) const;
```

* `[in] key`: The name of the property to return the value for.
Expand Down
4 changes: 2 additions & 2 deletions doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ Returns the value held by the `Napi::Reference`.
### Ref

```cpp
uint32_t Napi::Reference::Ref();
uint32_t Napi::Reference::Ref() const;
```

Increments the reference count for the `Napi::Reference` and returns the resulting reference count. Throws an error if the increment fails.

### Unref

```cpp
uint32_t Napi::Reference::Unref();
uint32_t Napi::Reference::Unref() const;
```

Decrements the reference count for the `Napi::Reference` and returns the resulting reference count. Throws an error if the decrement fails.
Expand Down
6 changes: 3 additions & 3 deletions doc/threadsafe_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Add a thread to this thread-safe function object, indicating that a new thread
will start making use of the thread-safe function.

```cpp
napi_status Napi::ThreadSafeFunction::Acquire()
napi_status Napi::ThreadSafeFunction::Acquire() const
```

Returns one of:
Expand All @@ -100,7 +100,7 @@ thread-safe function. Using any thread-safe APIs after having called this API
has undefined results in the current thread, as it may have been destroyed.

```cpp
napi_status Napi::ThreadSafeFunction::Release()
napi_status Napi::ThreadSafeFunction::Release() const
```

Returns one of:
Expand All @@ -122,7 +122,7 @@ make no further use of the thread-safe function because it is no longer
guaranteed to be allocated.

```cpp
napi_status Napi::ThreadSafeFunction::Abort()
napi_status Napi::ThreadSafeFunction::Abort() const
```

Returns one of:
Expand Down
4 changes: 2 additions & 2 deletions doc/typed_threadsafe_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ has undefined results in the current thread, as the thread-safe function may
have been destroyed.

```cpp
napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Release()
napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Release() const
```

Returns one of:
Expand All @@ -146,7 +146,7 @@ function call a thread must make no further use of the thread-safe function
because it is no longer guaranteed to be allocated.

```cpp
napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Abort()
napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Abort() const
```

Returns one of:
Expand Down
Loading