diff --git a/doc/env.md b/doc/env.md index c04b72529..9842de6bb 100644 --- a/doc/env.md +++ b/doc/env.md @@ -57,7 +57,7 @@ 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. @@ -65,7 +65,7 @@ Returns an `Napi::Error` object representing the environment's pending exception ### RunScript ```cpp -Napi::Value Napi::Env::RunScript(____ script); +Napi::Value Napi::Env::RunScript(____ script) const; ``` - `[in] script`: A string containing JavaScript code to execute. @@ -78,7 +78,7 @@ The `script` can be any of the following types: ### GetInstanceData ```cpp -template T* GetInstanceData(); +template T* GetInstanceData() const; ``` Returns the instance data that was previously associated with the environment, @@ -89,7 +89,7 @@ or `nullptr` if none was associated. ```cpp template using Finalizer = void (*)(Env, T*); template fini = Env::DefaultFini> -void SetInstanceData(T* data); +void SetInstanceData(T* data) const; ``` - `[template] fini`: A function to call when the instance data is to be deleted. @@ -112,7 +112,7 @@ template fini = Env::DefaultFiniWithHint> -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. diff --git a/doc/object.md b/doc/object.md index 677ff5532..8cec358aa 100644 --- a/doc/object.md +++ b/doc/object.md @@ -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. @@ -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. @@ -143,7 +143,7 @@ Note: This is equivalent to the JavaScript instanceof operator. ### AddFinalizer() ```cpp template -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. @@ -161,7 +161,7 @@ where `data` is the pointer that was passed into the call to `AddFinalizer()`. template inline void AddFinalizer(Finalizer finalizeCallback, T* data, - Hint* finalizeHint); + Hint* finalizeHint) const; ``` - `[in] data`: The data to associate with the object. @@ -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. @@ -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). @@ -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& @@ -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 @@ -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 @@ -244,7 +244,7 @@ writable. ### operator\[\]() ```cpp -Napi::PropertyLValue Napi::Object::operator[] (const char* utf8name); +Napi::PropertyLValue Napi::Object::operator[] (const char* utf8name) const; ``` - `[in] utf8name`: UTF-8 encoded null-terminated property name. @@ -252,7 +252,7 @@ Returns a [`Napi::Object::PropertyLValue`](propertylvalue.md) as the named property or sets the named property. ```cpp -Napi::PropertyLValue Napi::Object::operator[] (const std::string& utf8name); +Napi::PropertyLValue Napi::Object::operator[] (const std::string& utf8name) const; ``` - `[in] utf8name`: UTF-8 encoded property name. @@ -260,34 +260,13 @@ Returns a [`Napi::Object::PropertyLValue`](propertylvalue.md) as the named property or sets the named property. ```cpp -Napi::PropertyLValue Napi::Object::operator[] (uint32_t index); +Napi::PropertyLValue 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 diff --git a/doc/object_reference.md b/doc/object_reference.md index 38d6acc0e..1ee697980 100644 --- a/doc/object_reference.md +++ b/doc/object_reference.md @@ -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. diff --git a/doc/reference.md b/doc/reference.md index 42ddc0609..0420990e7 100644 --- a/doc/reference.md +++ b/doc/reference.md @@ -69,7 +69,7 @@ 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. @@ -77,7 +77,7 @@ Increments the reference count for the `Napi::Reference` and returns the resulti ### 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. diff --git a/doc/threadsafe_function.md b/doc/threadsafe_function.md index 6943bacf2..fcbc2dff1 100644 --- a/doc/threadsafe_function.md +++ b/doc/threadsafe_function.md @@ -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: @@ -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: @@ -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: diff --git a/doc/typed_threadsafe_function.md b/doc/typed_threadsafe_function.md index efd173482..74d3cc2ed 100644 --- a/doc/typed_threadsafe_function.md +++ b/doc/typed_threadsafe_function.md @@ -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::Release() +napi_status Napi::TypedThreadSafeFunction::Release() const ``` Returns one of: @@ -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::Abort() +napi_status Napi::TypedThreadSafeFunction::Abort() const ``` Returns one of: diff --git a/napi-inl.h b/napi-inl.h index 2aa5ae24b..c3f712c9b 100644 --- a/napi-inl.h +++ b/napi-inl.h @@ -487,7 +487,7 @@ inline bool Env::IsExceptionPending() const { return result; } -inline Error Env::GetAndClearPendingException() { +inline Error Env::GetAndClearPendingException() const { napi_value value; napi_status status = napi_get_and_clear_last_exception(_env, &value); if (status != napi_ok) { @@ -497,16 +497,16 @@ inline Error Env::GetAndClearPendingException() { return Error(_env, value); } -inline MaybeOrValue Env::RunScript(const char* utf8script) { +inline MaybeOrValue Env::RunScript(const char* utf8script) const { String script = String::New(_env, utf8script); return RunScript(script); } -inline MaybeOrValue Env::RunScript(const std::string& utf8script) { +inline MaybeOrValue Env::RunScript(const std::string& utf8script) const { return RunScript(utf8script.c_str()); } -inline MaybeOrValue Env::RunScript(String script) { +inline MaybeOrValue Env::RunScript(String script) const { napi_value result; napi_status status = napi_run_script(_env, script, &result); NAPI_RETURN_OR_THROW_IF_FAILED( @@ -535,7 +535,7 @@ void Env::CleanupHook::WrapperWithArg(void* data) NAPI_NOEXCEPT { #if NAPI_VERSION > 5 template fini> -inline void Env::SetInstanceData(T* data) { +inline void Env::SetInstanceData(T* data) const { napi_status status = napi_set_instance_data(_env, data, [](napi_env env, void* data, void*) { fini(env, static_cast(data)); @@ -546,7 +546,7 @@ inline void Env::SetInstanceData(T* data) { template fini> -inline void Env::SetInstanceData(DataType* data, HintType* hint) { +inline void Env::SetInstanceData(DataType* data, HintType* hint) const { napi_status status = napi_set_instance_data(_env, data, [](napi_env env, void* data, void* hint) { @@ -556,7 +556,7 @@ inline void Env::SetInstanceData(DataType* data, HintType* hint) { } template -inline T* Env::GetInstanceData() { +inline T* Env::GetInstanceData() const { void* data = nullptr; napi_status status = napi_get_instance_data(_env, &data); @@ -1298,39 +1298,25 @@ inline Object::Object() : Value() { inline Object::Object(napi_env env, napi_value value) : Value(env, value) { } -inline Object::PropertyLValue Object::operator [](const char* utf8name) { +inline Object::PropertyLValue Object::operator[]( + const char* utf8name) const { return PropertyLValue(*this, utf8name); } -inline Object::PropertyLValue Object::operator [](const std::string& utf8name) { +inline Object::PropertyLValue Object::operator[]( + const std::string& utf8name) const { return PropertyLValue(*this, utf8name); } -inline Object::PropertyLValue Object::operator [](uint32_t index) { +inline Object::PropertyLValue Object::operator[]( + uint32_t index) const { return PropertyLValue(*this, index); } -inline Object::PropertyLValue Object::operator[](Value index) { - return PropertyLValue(*this, index); -} - inline Object::PropertyLValue Object::operator[](Value index) const { return PropertyLValue(*this, index); } -inline MaybeOrValue Object::operator[](const char* utf8name) const { - return Get(utf8name); -} - -inline MaybeOrValue Object::operator[]( - const std::string& utf8name) const { - return Get(utf8name); -} - -inline MaybeOrValue Object::operator[](uint32_t index) const { - return Get(index); -} - inline MaybeOrValue Object::Has(napi_value key) const { bool result; napi_status status = napi_has_property(_env, _value, key, &result); @@ -1400,14 +1386,15 @@ inline MaybeOrValue Object::Get(const std::string& utf8name) const { } template -inline MaybeOrValue Object::Set(napi_value key, const ValueType& value) { +inline MaybeOrValue Object::Set(napi_value key, + const ValueType& value) const { napi_status status = napi_set_property(_env, _value, key, Value::From(_env, value)); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool); } template -inline MaybeOrValue Object::Set(Value key, const ValueType& value) { +inline MaybeOrValue Object::Set(Value key, const ValueType& value) const { napi_status status = napi_set_property(_env, _value, key, Value::From(_env, value)); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool); @@ -1415,7 +1402,7 @@ inline MaybeOrValue Object::Set(Value key, const ValueType& value) { template inline MaybeOrValue Object::Set(const char* utf8name, - const ValueType& value) { + const ValueType& value) const { napi_status status = napi_set_named_property(_env, _value, utf8name, Value::From(_env, value)); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool); @@ -1423,27 +1410,27 @@ inline MaybeOrValue Object::Set(const char* utf8name, template inline MaybeOrValue Object::Set(const std::string& utf8name, - const ValueType& value) { + const ValueType& value) const { return Set(utf8name.c_str(), value); } -inline MaybeOrValue Object::Delete(napi_value key) { +inline MaybeOrValue Object::Delete(napi_value key) const { bool result; napi_status status = napi_delete_property(_env, _value, key, &result); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, result, bool); } -inline MaybeOrValue Object::Delete(Value key) { +inline MaybeOrValue Object::Delete(Value key) const { bool result; napi_status status = napi_delete_property(_env, _value, key, &result); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, result, bool); } -inline MaybeOrValue Object::Delete(const char* utf8name) { +inline MaybeOrValue Object::Delete(const char* utf8name) const { return Delete(String::New(_env, utf8name)); } -inline MaybeOrValue Object::Delete(const std::string& utf8name) { +inline MaybeOrValue Object::Delete(const std::string& utf8name) const { return Delete(String::New(_env, utf8name)); } @@ -1460,13 +1447,14 @@ inline MaybeOrValue Object::Get(uint32_t index) const { } template -inline MaybeOrValue Object::Set(uint32_t index, const ValueType& value) { +inline MaybeOrValue Object::Set(uint32_t index, + const ValueType& value) const { napi_status status = napi_set_element(_env, _value, index, Value::From(_env, value)); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool); } -inline MaybeOrValue Object::Delete(uint32_t index) { +inline MaybeOrValue Object::Delete(uint32_t index) const { bool result; napi_status status = napi_delete_element(_env, _value, index, &result); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, result, bool); @@ -1479,21 +1467,21 @@ inline MaybeOrValue Object::GetPropertyNames() const { } inline MaybeOrValue Object::DefineProperty( - const PropertyDescriptor& property) { + const PropertyDescriptor& property) const { napi_status status = napi_define_properties(_env, _value, 1, reinterpret_cast(&property)); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool); } inline MaybeOrValue Object::DefineProperties( - const std::initializer_list& properties) { + const std::initializer_list& properties) const { napi_status status = napi_define_properties(_env, _value, properties.size(), reinterpret_cast(properties.begin())); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool); } inline MaybeOrValue Object::DefineProperties( - const std::vector& properties) { + const std::vector& properties) const { napi_status status = napi_define_properties(_env, _value, properties.size(), reinterpret_cast(properties.data())); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool); @@ -1507,7 +1495,7 @@ inline MaybeOrValue Object::InstanceOf( } template -inline void Object::AddFinalizer(Finalizer finalizeCallback, T* data) { +inline void Object::AddFinalizer(Finalizer finalizeCallback, T* data) const { details::FinalizeData* finalizeData = new details::FinalizeData( {std::move(finalizeCallback), nullptr}); @@ -1526,7 +1514,7 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback, T* data) { template inline void Object::AddFinalizer(Finalizer finalizeCallback, T* data, - Hint* finalizeHint) { + Hint* finalizeHint) const { details::FinalizeData* finalizeData = new details::FinalizeData( {std::move(finalizeCallback), finalizeHint}); @@ -1620,12 +1608,12 @@ Object::iterator::operator*() { #endif // NAPI_CPP_EXCEPTIONS #if NAPI_VERSION >= 8 -inline MaybeOrValue Object::Freeze() { +inline MaybeOrValue Object::Freeze() const { napi_status status = napi_object_freeze(_env, _value); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool); } -inline MaybeOrValue Object::Seal() { +inline MaybeOrValue Object::Seal() const { napi_status status = napi_object_seal(_env, _value); NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool); } @@ -2966,7 +2954,7 @@ inline T Reference::Value() const { } template -inline uint32_t Reference::Ref() { +inline uint32_t Reference::Ref() const { uint32_t result; napi_status status = napi_reference_ref(_env, _ref, &result); NAPI_THROW_IF_FAILED(_env, status, 0); @@ -2974,7 +2962,7 @@ inline uint32_t Reference::Ref() { } template -inline uint32_t Reference::Unref() { +inline uint32_t Reference::Unref() const { uint32_t result; napi_status status = napi_reference_unref(_env, _ref, &result); NAPI_THROW_IF_FAILED(_env, status, 0); @@ -3100,61 +3088,61 @@ inline MaybeOrValue ObjectReference::Get( } inline MaybeOrValue ObjectReference::Set(const char* utf8name, - napi_value value) { + napi_value value) const { HandleScope scope(_env); return Value().Set(utf8name, value); } inline MaybeOrValue ObjectReference::Set(const char* utf8name, - Napi::Value value) { + Napi::Value value) const { HandleScope scope(_env); return Value().Set(utf8name, value); } inline MaybeOrValue ObjectReference::Set(const char* utf8name, - const char* utf8value) { + const char* utf8value) const { HandleScope scope(_env); return Value().Set(utf8name, utf8value); } inline MaybeOrValue ObjectReference::Set(const char* utf8name, - bool boolValue) { + bool boolValue) const { HandleScope scope(_env); return Value().Set(utf8name, boolValue); } inline MaybeOrValue ObjectReference::Set(const char* utf8name, - double numberValue) { + double numberValue) const { HandleScope scope(_env); return Value().Set(utf8name, numberValue); } inline MaybeOrValue ObjectReference::Set(const std::string& utf8name, - napi_value value) { + napi_value value) const { HandleScope scope(_env); return Value().Set(utf8name, value); } inline MaybeOrValue ObjectReference::Set(const std::string& utf8name, - Napi::Value value) { + Napi::Value value) const { HandleScope scope(_env); return Value().Set(utf8name, value); } inline MaybeOrValue ObjectReference::Set(const std::string& utf8name, - std::string& utf8value) { + std::string& utf8value) const { HandleScope scope(_env); return Value().Set(utf8name, utf8value); } inline MaybeOrValue ObjectReference::Set(const std::string& utf8name, - bool boolValue) { + bool boolValue) const { HandleScope scope(_env); return Value().Set(utf8name, boolValue); } inline MaybeOrValue ObjectReference::Set(const std::string& utf8name, - double numberValue) { + double numberValue) const { HandleScope scope(_env); return Value().Set(utf8name, numberValue); } @@ -3176,36 +3164,37 @@ inline MaybeOrValue ObjectReference::Get(uint32_t index) const { } inline MaybeOrValue ObjectReference::Set(uint32_t index, - napi_value value) { + napi_value value) const { HandleScope scope(_env); return Value().Set(index, value); } inline MaybeOrValue ObjectReference::Set(uint32_t index, - Napi::Value value) { + Napi::Value value) const { HandleScope scope(_env); return Value().Set(index, value); } inline MaybeOrValue ObjectReference::Set(uint32_t index, - const char* utf8value) { + const char* utf8value) const { HandleScope scope(_env); return Value().Set(index, utf8value); } -inline MaybeOrValue ObjectReference::Set(uint32_t index, - const std::string& utf8value) { +inline MaybeOrValue ObjectReference::Set( + uint32_t index, const std::string& utf8value) const { HandleScope scope(_env); return Value().Set(index, utf8value); } -inline MaybeOrValue ObjectReference::Set(uint32_t index, bool boolValue) { +inline MaybeOrValue ObjectReference::Set(uint32_t index, + bool boolValue) const { HandleScope scope(_env); return Value().Set(index, boolValue); } inline MaybeOrValue ObjectReference::Set(uint32_t index, - double numberValue) { + double numberValue) const { HandleScope scope(_env); return Value().Set(index, numberValue); } @@ -5368,7 +5357,7 @@ template inline napi_status -TypedThreadSafeFunction::Release() { +TypedThreadSafeFunction::Release() const { return napi_release_threadsafe_function(_tsfn, napi_tsfn_release); } @@ -5376,7 +5365,7 @@ template inline napi_status -TypedThreadSafeFunction::Abort() { +TypedThreadSafeFunction::Abort() const { return napi_release_threadsafe_function(_tsfn, napi_tsfn_abort); } @@ -5706,11 +5695,11 @@ inline napi_status ThreadSafeFunction::Acquire() const { return napi_acquire_threadsafe_function(_tsfn); } -inline napi_status ThreadSafeFunction::Release() { +inline napi_status ThreadSafeFunction::Release() const { return napi_release_threadsafe_function(_tsfn, napi_tsfn_release); } -inline napi_status ThreadSafeFunction::Abort() { +inline napi_status ThreadSafeFunction::Abort() const { return napi_release_threadsafe_function(_tsfn, napi_tsfn_abort); } diff --git a/napi.h b/napi.h index d3adc3519..0684543f7 100644 --- a/napi.h +++ b/napi.h @@ -298,11 +298,11 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { Value Null() const; bool IsExceptionPending() const; - Error GetAndClearPendingException(); + Error GetAndClearPendingException() const; - MaybeOrValue RunScript(const char* utf8script); - MaybeOrValue RunScript(const std::string& utf8script); - MaybeOrValue RunScript(String script); + MaybeOrValue RunScript(const char* utf8script) const; + MaybeOrValue RunScript(const std::string& utf8script) const; + MaybeOrValue RunScript(String script) const; #if NAPI_VERSION > 2 template @@ -313,19 +313,20 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { #endif // NAPI_VERSION > 2 #if NAPI_VERSION > 5 - template T* GetInstanceData(); + template + T* GetInstanceData() const; template using Finalizer = void (*)(Env, T*); template fini = Env::DefaultFini> - void SetInstanceData(T* data); + void SetInstanceData(T* data) const; template using FinalizerWithHint = void (*)(Env, DataType*, HintType*); template fini = - Env::DefaultFiniWithHint> - void SetInstanceData(DataType* data, HintType* hint); + Env::DefaultFiniWithHint> + void SetInstanceData(DataType* data, HintType* hint) const; #endif // NAPI_VERSION > 5 private: @@ -739,42 +740,24 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { napi_value value); ///< Wraps a Node-API value primitive. /// Gets or sets a named property. - PropertyLValue operator []( - const char* utf8name ///< UTF-8 encoded null-terminated property name - ); + PropertyLValue operator[]( + const char* utf8name ///< UTF-8 encoded null-terminated property name + ) const; /// Gets or sets a named property. - PropertyLValue operator []( - const std::string& utf8name ///< UTF-8 encoded property name - ); - - /// Gets or sets an indexed property or array element. - PropertyLValue operator []( - uint32_t index /// Property / element index - ); + PropertyLValue operator[]( + const std::string& utf8name ///< UTF-8 encoded property name + ) const; /// Gets or sets an indexed property or array element. - PropertyLValue operator[](Value index /// Property / element index - ); + PropertyLValue operator[]( + uint32_t index /// Property / element index + ) const; /// Gets or sets an indexed property or array element. PropertyLValue operator[](Value index /// Property / element index ) const; - /// Gets a named property. - MaybeOrValue operator[]( - const char* utf8name ///< UTF-8 encoded null-terminated property name - ) const; - - /// Gets a named property. - MaybeOrValue operator[]( - const std::string& utf8name ///< UTF-8 encoded property name - ) const; - - /// Gets an indexed property or array element. - MaybeOrValue operator[](uint32_t index ///< Property / element index - ) const; - /// Checks whether a property is present. MaybeOrValue Has(napi_value key ///< Property key primitive ) const; @@ -834,44 +817,44 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { template MaybeOrValue Set(napi_value key, ///< Property key primitive const ValueType& value ///< Property value primitive - ); + ) const; /// Sets a property. template MaybeOrValue Set(Value key, ///< Property key const ValueType& value ///< Property value - ); + ) const; /// Sets a named property. template MaybeOrValue Set( const char* utf8name, ///< UTF-8 encoded null-terminated property name - const ValueType& value); + const ValueType& value) const; /// Sets a named property. template MaybeOrValue Set( const std::string& utf8name, ///< UTF-8 encoded property name const ValueType& value ///< Property value primitive - ); + ) const; /// Delete property. MaybeOrValue Delete(napi_value key ///< Property key primitive - ); + ) const; /// Delete property. MaybeOrValue Delete(Value key ///< Property key - ); + ) const; /// Delete property. MaybeOrValue Delete( const char* utf8name ///< UTF-8 encoded null-terminated property name - ); + ) const; /// Delete property. MaybeOrValue Delete( const std::string& utf8name ///< UTF-8 encoded property name - ); + ) const; /// Checks whether an indexed property is present. MaybeOrValue Has(uint32_t index ///< Property / element index @@ -885,11 +868,11 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { template MaybeOrValue Set(uint32_t index, ///< Property / element index const ValueType& value ///< Property value primitive - ); + ) const; /// Deletes an indexed property or array element. MaybeOrValue Delete(uint32_t index ///< Property / element index - ); + ) const; /// This operation can fail in case of Proxy.[[OwnPropertyKeys]] and /// Proxy.[[GetOwnProperty]] calling into JavaScript. See: @@ -907,7 +890,7 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { MaybeOrValue DefineProperty( const PropertyDescriptor& property ///< Descriptor for the property to be defined - ); + ) const; /// Defines properties on the object. /// @@ -917,7 +900,7 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { MaybeOrValue DefineProperties( const std::initializer_list& properties ///< List of descriptors for the properties to be defined - ); + ) const; /// Defines properties on the object. /// @@ -927,7 +910,7 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { MaybeOrValue DefineProperties( const std::vector& properties ///< Vector of descriptors for the properties to be defined - ); + ) const; /// Checks if an object is an instance created by a constructor function. /// @@ -942,12 +925,12 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { ) const; template - inline void AddFinalizer(Finalizer finalizeCallback, T* data); + inline void AddFinalizer(Finalizer finalizeCallback, T* data) const; template inline void AddFinalizer(Finalizer finalizeCallback, T* data, - Hint* finalizeHint); + Hint* finalizeHint) const; #ifdef NAPI_CPP_EXCEPTIONS class const_iterator; @@ -968,12 +951,12 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { /// JavaScript. /// See /// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof - MaybeOrValue Freeze(); + MaybeOrValue Freeze() const; /// This operation can fail in case of Proxy.[[GetPrototypeOf]] calling into /// JavaScript. /// See /// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof - MaybeOrValue Seal(); + MaybeOrValue Seal() const; #endif // NAPI_VERSION >= 8 }; @@ -1477,8 +1460,8 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { // within a HandleScope so that the value handle gets cleaned up efficiently. T Value() const; - uint32_t Ref(); - uint32_t Unref(); + uint32_t Ref() const; + uint32_t Unref() const; void Reset(); void Reset(const T& value, uint32_t refcount = 0); @@ -1515,24 +1498,27 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { MaybeOrValue Get(const char* utf8name) const; MaybeOrValue Get(const std::string& utf8name) const; - MaybeOrValue Set(const char* utf8name, napi_value value); - MaybeOrValue Set(const char* utf8name, Napi::Value value); - MaybeOrValue Set(const char* utf8name, const char* utf8value); - MaybeOrValue Set(const char* utf8name, bool boolValue); - MaybeOrValue Set(const char* utf8name, double numberValue); - MaybeOrValue Set(const std::string& utf8name, napi_value value); - MaybeOrValue Set(const std::string& utf8name, Napi::Value value); - MaybeOrValue Set(const std::string& utf8name, std::string& utf8value); - MaybeOrValue Set(const std::string& utf8name, bool boolValue); - MaybeOrValue Set(const std::string& utf8name, double numberValue); + MaybeOrValue Set(const char* utf8name, napi_value value) const; + MaybeOrValue Set(const char* utf8name, Napi::Value value) const; + MaybeOrValue Set(const char* utf8name, const char* utf8value) const; + MaybeOrValue Set(const char* utf8name, bool boolValue) const; + MaybeOrValue Set(const char* utf8name, double numberValue) const; + MaybeOrValue Set(const std::string& utf8name, napi_value value) const; + MaybeOrValue Set(const std::string& utf8name, + Napi::Value value) const; + MaybeOrValue Set(const std::string& utf8name, + std::string& utf8value) const; + MaybeOrValue Set(const std::string& utf8name, bool boolValue) const; + MaybeOrValue Set(const std::string& utf8name, + double numberValue) const; MaybeOrValue Get(uint32_t index) const; - MaybeOrValue Set(uint32_t index, const napi_value value); - MaybeOrValue Set(uint32_t index, const Napi::Value value); - MaybeOrValue Set(uint32_t index, const char* utf8value); - MaybeOrValue Set(uint32_t index, const std::string& utf8value); - MaybeOrValue Set(uint32_t index, bool boolValue); - MaybeOrValue Set(uint32_t index, double numberValue); + MaybeOrValue Set(uint32_t index, const napi_value value) const; + MaybeOrValue Set(uint32_t index, const Napi::Value value) const; + MaybeOrValue Set(uint32_t index, const char* utf8value) const; + MaybeOrValue Set(uint32_t index, const std::string& utf8value) const; + MaybeOrValue Set(uint32_t index, bool boolValue) const; + MaybeOrValue Set(uint32_t index, double numberValue) const; protected: ObjectReference(const ObjectReference&); @@ -2569,10 +2555,10 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { napi_status Acquire() const; // This API may be called from any thread. - napi_status Release(); + napi_status Release() const; // This API may be called from any thread. - napi_status Abort(); + napi_status Abort() const; struct ConvertibleContext { @@ -2768,10 +2754,10 @@ namespace NAPI_CPP_CUSTOM_NAMESPACE { napi_status Acquire() const; // This API may be called from any thread. - napi_status Release(); + napi_status Release() const; // This API may be called from any thread. - napi_status Abort(); + napi_status Abort() const; // This API may be called from any thread. ContextType* GetContext() const;