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

to_binary() should never return a null BinaryData #5161

Merged
merged 1 commit into from
Dec 6, 2022

Conversation

RedBeard0531
Copy link
Contributor

What, How & Why?

This closes #5114

☑️ ToDos

  • 📝 Changelog entry
  • [ ] 📝 Compatibility label is updated or copied from previous entry
  • [ ] 📝 Update COMPATIBILITY.md
  • 🚦 Tests
  • [ ] 🔀 Executed flexible sync tests locally if modifying flexible sync
  • [ ] 📦 Updated internal package version in consuming package.jsons (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 necessary

If this PR adds or changes public API's:

  • [ ] typescript definitions file is updated
  • [ ] jsdoc files updated

@cla-bot cla-bot bot added the cla: yes label Dec 6, 2022
@@ -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)
Copy link
Contributor Author

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()) {
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.

Copy link
Contributor

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)
Copy link
Contributor

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

@RedBeard0531 RedBeard0531 merged commit caa4480 into master Dec 6, 2022
@RedBeard0531 RedBeard0531 deleted the ms/null_binary branch December 6, 2022 15:46
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArrayBuffer(0) and null
2 participants