Skip to content

Commit b8449e1

Browse files
seishunmhdawson
authored andcommitted
src: mark methods of wrapper classes const
PR-URL: #874 Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Michael Dawson <[email protected]
1 parent 5e2c1f2 commit b8449e1

File tree

8 files changed

+141
-187
lines changed

8 files changed

+141
-187
lines changed

doc/env.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ Returns a `bool` indicating if an exception is pending in the environment.
5757
### GetAndClearPendingException
5858

5959
```cpp
60-
Napi::Error Napi::Env::GetAndClearPendingException();
60+
Napi::Error Napi::Env::GetAndClearPendingException() const;
6161
```
6262

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

6565
### RunScript
6666

6767
```cpp
68-
Napi::Value Napi::Env::RunScript(____ script);
68+
Napi::Value Napi::Env::RunScript(____ script) const;
6969
```
7070
- `[in] script`: A string containing JavaScript code to execute.
7171
@@ -78,7 +78,7 @@ The `script` can be any of the following types:
7878
7979
### GetInstanceData
8080
```cpp
81-
template <typename T> T* GetInstanceData();
81+
template <typename T> T* GetInstanceData() const;
8282
```
8383

8484
Returns the instance data that was previously associated with the environment,
@@ -89,7 +89,7 @@ or `nullptr` if none was associated.
8989
```cpp
9090
template <typename T> using Finalizer = void (*)(Env, T*);
9191
template <typename T, Finalizer<T> fini = Env::DefaultFini<T>>
92-
void SetInstanceData(T* data);
92+
void SetInstanceData(T* data) const;
9393
```
9494
9595
- `[template] fini`: A function to call when the instance data is to be deleted.
@@ -112,7 +112,7 @@ template <typename DataType,
112112
typename HintType,
113113
FinalizerWithHint<DataType, HintType> fini =
114114
Env::DefaultFiniWithHint<DataType, HintType>>
115-
void SetInstanceData(DataType* data, HintType* hint);
115+
void SetInstanceData(DataType* data, HintType* hint) const;
116116
```
117117

118118
- `[template] fini`: A function to call when the instance data is to be deleted.

doc/object.md

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Creates a new `Napi::Object` value.
7272
### Set()
7373

7474
```cpp
75-
bool Napi::Object::Set (____ key, ____ value);
75+
bool Napi::Object::Set (____ key, ____ value) const;
7676
```
7777
- `[in] key`: The name for the property being assigned.
7878
- `[in] value`: The value being assigned to the property.
@@ -91,7 +91,7 @@ The `value` can be of any type that is accepted by [`Napi::Value::From`][].
9191
### Delete()
9292
9393
```cpp
94-
bool Napi::Object::Delete(____ key);
94+
bool Napi::Object::Delete(____ key) const;
9595
```
9696
- `[in] key`: The name of the property to delete.
9797

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

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

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

185185
### HasOwnProperty()
186186
```cpp
187-
bool Napi::Object::HasOwnProperty(____ key); const
187+
bool Napi::Object::HasOwnProperty(____ key) const;
188188
```
189189
- `[in] key` The name of the property to check.
190190
@@ -200,7 +200,7 @@ The key can be any of the following types:
200200
### DefineProperty()
201201
202202
```cpp
203-
bool Napi::Object::DefineProperty (const Napi::PropertyDescriptor& property);
203+
bool Napi::Object::DefineProperty (const Napi::PropertyDescriptor& property) const;
204204
```
205205
- `[in] property`: A [`Napi::PropertyDescriptor`](property_descriptor.md).
206206

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

211211
```cpp
212-
bool Napi::Object::DefineProperties (____ properties)
212+
bool Napi::Object::DefineProperties (____ properties) const;
213213
```
214214
- `[in] properties`: A list of [`Napi::PropertyDescriptor`](property_descriptor.md). Can be one of the following types:
215215
- const std::initializer_list<Napi::PropertyDescriptor>&
@@ -220,7 +220,7 @@ Defines properties on the object.
220220
### Freeze()
221221
222222
```cpp
223-
void Napi::Object::Freeze()
223+
void Napi::Object::Freeze() const;
224224
```
225225

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

235235
```cpp
236-
void Napi::Object::Seal()
236+
void Napi::Object::Seal() const;
237237
```
238238

239239
The `Napi::Object::Seal()` method seals an object, preventing new properties
@@ -244,50 +244,29 @@ writable.
244244
### operator\[\]()
245245

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

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

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

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

262262
```cpp
263-
Napi::PropertyLValue<uint32_t> Napi::Object::operator[] (uint32_t index);
263+
Napi::PropertyLValue<uint32_t> Napi::Object::operator[] (uint32_t index) const;
264264
```
265265
- `[in] index`: Element index.
266266

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

270-
```cpp
271-
Napi::Value Napi::Object::operator[] (const char* utf8name) const;
272-
```
273-
- `[in] utf8name`: UTF-8 encoded null-terminated property name.
274-
275-
Returns the named property as a [`Napi::Value`](value.md).
276-
277-
```cpp
278-
Napi::Value Napi::Object::operator[] (const std::string& utf8name) const;
279-
```
280-
- `[in] utf8name`: UTF-8 encoded property name.
281-
282-
Returns the named property as a [`Napi::Value`](value.md).
283-
284-
```cpp
285-
Napi::Value Napi::Object::operator[] (uint32_t index) const;
286-
```
287-
- `[in] index`: Element index.
288-
289-
Returns an indexed property or array element as a [`Napi::Value`](value.md).
290-
291270
### begin()
292271

293272
```cpp

doc/object_reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ The `value` can be any of the following types:
103103
### Get
104104

105105
```cpp
106-
Napi::Value Napi::ObjectReference::Get(___ key);
106+
Napi::Value Napi::ObjectReference::Get(___ key) const;
107107
```
108108
109109
* `[in] key`: The name of the property to return the value for.

doc/reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ Returns the value held by the `Napi::Reference`.
6969
### Ref
7070

7171
```cpp
72-
uint32_t Napi::Reference::Ref();
72+
uint32_t Napi::Reference::Ref() const;
7373
```
7474

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

7777
### Unref
7878

7979
```cpp
80-
uint32_t Napi::Reference::Unref();
80+
uint32_t Napi::Reference::Unref() const;
8181
```
8282

8383
Decrements the reference count for the `Napi::Reference` and returns the resulting reference count. Throws an error if the decrement fails.

doc/threadsafe_function.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Add a thread to this thread-safe function object, indicating that a new thread
8383
will start making use of the thread-safe function.
8484

8585
```cpp
86-
napi_status Napi::ThreadSafeFunction::Acquire()
86+
napi_status Napi::ThreadSafeFunction::Acquire() const
8787
```
8888

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

102102
```cpp
103-
napi_status Napi::ThreadSafeFunction::Release()
103+
napi_status Napi::ThreadSafeFunction::Release() const
104104
```
105105

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

124124
```cpp
125-
napi_status Napi::ThreadSafeFunction::Abort()
125+
napi_status Napi::ThreadSafeFunction::Abort() const
126126
```
127127

128128
Returns one of:

doc/typed_threadsafe_function.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ has undefined results in the current thread, as the thread-safe function may
124124
have been destroyed.
125125

126126
```cpp
127-
napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Release()
127+
napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Release() const
128128
```
129129

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

148148
```cpp
149-
napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Abort()
149+
napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Abort() const
150150
```
151151

152152
Returns one of:

0 commit comments

Comments
 (0)