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

Support []byte in Value #356

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Support []byte in Value #356

wants to merge 2 commits into from

Conversation

fizx
Copy link
Collaborator

@fizx fizx commented Dec 19, 2022

This is a reduction of the longstanding #143 to do the minimum I actually need: letting me put []byte's into and out of values.

Copy link
Collaborator

@RGood RGood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent changes 👍 🚀

std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
static_cast<void*>(const_cast<uint8_t*>(v)), len,
[](void* data, size_t length, void *deleter_data) {
free(data);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this seems to be the correct deallocator to use but I couldn't find a convincing example.

// Returns length of the array (number of elements, not number of bytes)
uint64_t ValueToArrayLength(ValuePtr ptr) {
LOCAL_VALUE(ptr);
MaybeLocal<TypedArray> array = value.As<TypedArray>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check if this is empty?

uint64_t ValueToArrayLength(ValuePtr ptr) {
  LOCAL_VALUE(ptr);
  MaybeLocal<TypedArray> array = value.As<TypedArray>();
  if (array.IsEmpty()) {
    return 0;
  }
  return array.ToLocalChecked()->Length();
}

Same question above in ValueToUint8Array().

@codecov
Copy link

codecov bot commented Jan 23, 2023

Codecov Report

Base: 95.28% // Head: 95.33% // Increases project coverage by +0.04% 🎉

Coverage data is based on head (aedc302) compared to base (7d843f1).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #356      +/-   ##
==========================================
+ Coverage   95.28%   95.33%   +0.04%     
==========================================
  Files          17       17              
  Lines         594      600       +6     
==========================================
+ Hits          566      572       +6     
  Misses         19       19              
  Partials        9        9              
Impacted Files Coverage Δ
value.go 95.02% <100.00%> (+0.17%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants