Skip to content

Commit

Permalink
src: mark methods of wrapper classes const
Browse files Browse the repository at this point in the history
PR-URL: #874
Reviewed-By: Gabriel Schulhof <[email protected]>
Reviewed-By: Michael Dawson <[email protected]
  • Loading branch information
seishun authored and mhdawson committed Mar 11, 2022
1 parent 5e2c1f2 commit b8449e1
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 187 deletions.
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
45 changes: 12 additions & 33 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,50 +244,29 @@ 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
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

0 comments on commit b8449e1

Please sign in to comment.