-
Notifications
You must be signed in to change notification settings - Fork 578
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
to_binary() should never return a null BinaryData #5161
Conversation
@@ -917,6 919,14 @@ typename T::Value Value<T>::from_mixed(ContextType ctx, std::shared_ptr<Realm> r | |||
} | |||
} | |||
|
|||
template <typename T> | |||
inline OwnedBinaryData Value<T>::to_binary(typename T::Context ctx, const ValueType& value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The real fix was introducing making to_binary
a wrapper function that makes sure not to return null BinaryData
. This felt cleaner to me than adding the logic to all return paths on both implementations.
binary_data = NodeBinaryManager<Napi::DataView, Napi::Value>{value}.create_binary_blob(); | ||
legal_conversion = true; | ||
} | ||
else if (value.IsBuffer()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buffer
is a subclass of TypedArray
, so this version was redundant with the next.
@@ -250,33 250,23 @@ inline double node::Value::to_number(Napi::Env env, const Napi::Value& value) | |||
} | |||
|
|||
template <> | |||
inline OwnedBinaryData node::Value::to_binary(Napi::Env env, const Napi::Value& value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code and the related node_buffer.hpp was bad enough that I felt a duty to clean it up. If you would prefer, I can split this to a different commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to split it as it is a relative small commit
@@ -250,33 250,23 @@ inline double node::Value::to_number(Napi::Env env, const Napi::Value& value) | |||
} | |||
|
|||
template <> | |||
inline OwnedBinaryData node::Value::to_binary(Napi::Env env, const Napi::Value& value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to split it as it is a relative small commit
What, How & Why?
This closes #5114
☑️ ToDos
[ ] 📝Compatibility
label is updated or copied from previous entry[ ] 📝 UpdateCOMPATIBILITY.md
[ ] 🔀 Executed flexible sync tests locally if modifying flexible sync[ ] 📦 Updated internal package version in consumingpackage.json
s (if updating internal packages)[ ] 📱 Check the React Native/other sample apps work if necessary[ ] 📝 Public documentation PR created or is not necessary[ ] 💥Breaking
label has been applied or is not necessaryIf this PR adds or changes public API's:
[ ] typescript definitions file is updated[ ] jsdoc files updated