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

src: do not use non-static class member for constant value #1134

Merged
merged 1 commit into from Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions napi-inl.h
Expand Up @@ -2607,8 +2607,8 @@ inline Error::Error(napi_env env, napi_value value) : ObjectReference(env, nullp

// property flag that we attach to show the error object is wrapped
napi_property_descriptor wrapObjFlag = {
ERROR_WRAP_VALUE, // Unique GUID identifier since Symbol isn't a
// viable option
ERROR_WRAP_VALUE(), // Unique GUID identifier since Symbol isn't a
// viable option
nullptr,
nullptr,
nullptr,
Expand Down Expand Up @@ -2648,15 +2648,17 @@ inline Object Error::Value() const {
// We are checking if the object is wrapped
bool isWrappedObject = false;

status = napi_has_property(
_env, refValue, String::From(_env, ERROR_WRAP_VALUE), &isWrappedObject);
status = napi_has_property(_env,
refValue,
String::From(_env, ERROR_WRAP_VALUE()),
&isWrappedObject);

// Don't care about status
if (isWrappedObject) {
napi_value unwrappedValue;
status = napi_get_property(_env,
refValue,
String::From(_env, ERROR_WRAP_VALUE),
String::From(_env, ERROR_WRAP_VALUE()),
&unwrappedValue);
NAPI_THROW_IF_FAILED(_env, status, Object());

Expand Down Expand Up @@ -2772,6 +2774,10 @@ inline const char* Error::what() const NAPI_NOEXCEPT {

#endif // NAPI_CPP_EXCEPTIONS

inline const char* Error::ERROR_WRAP_VALUE() NAPI_NOEXCEPT {
return "4bda9e7e-4913-4dbc-95de-891cbf66598e-errorVal";
}

template <typename TError>
inline TError Error::New(napi_env env,
const char* message,
Expand Down
3 changes: 1 addition & 2 deletions napi.h
Expand Up @@ -1720,8 +1720,7 @@ namespace Napi {
/// !endcond

private:
const char* ERROR_WRAP_VALUE =
"4bda9e7e-4913-4dbc-95de-891cbf66598e-errorVal";
static inline const char* ERROR_WRAP_VALUE() NAPI_NOEXCEPT;
mutable std::string _message;
};

Expand Down