-
-
Notifications
You must be signed in to change notification settings - Fork 547
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
Bytes as ArrayBuffer #1590
base: main
Are you sure you want to change the base?
Bytes as ArrayBuffer #1590
Conversation
Nice! Here's some feedback from the top of my head. I think it would also be fine if we rename
The constructed object is not properly initialized, I'd suggest adding new public ArrayBufferInstance Construct(byte[] data)
{
var obj = OrdinaryCreateFromConstructor(
this,
static intrinsics => intrinsics.ArrayBuffer.PrototypeObject,
static (engine, _, state) => new ArrayBufferInstance(engine, state!),
data);
return obj;
} And changing your converter logic to: if (value is byte[] bytes)
{
result = engine.Realm.Intrinsics.ArrayBuffer.Construct(bytes);
return true;
} Note, now
I think there might be small problem with ambiguity here. You could also want to have your
Everything what makes Jint more usable in interop scenarios sounds good to me. |
Thank you for a prompt and in-depth reply @lahma . This is my first more serious work with Jint codebase so that I'm stepping into unfamiliar territory. Let me dive deeper with your comments in mind and get this PR altered over the weekend. |
With #1591 I did some preliminary work and did the rename and expose of type. If you find it useful for future, could also unseal it if there's some benefit with different backing store implementations. So if you rebase, you should have things readily available. |
This PR introduces a capability to convert raw byte chunks like
byte[]
as anArrayBuffer
. It does it by implementing an object converter directly inJint
core project. This is done to not make theArrayBufferInstance
public and keep the API change as minimal.Open questions:
Memory<byte>
which would require offset bookkeeping in the ArrayBuffer (I can implement it).