-
Notifications
You must be signed in to change notification settings - Fork 470
Add base types of ArrayBuffer, SharedArrayBuffer #6683
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
Conversation
6b88b9f
to
6e73d3a
Compare
This should be moved into Core. Onlt |
ce2c6b9
to
7f64c21
Compare
@@ -0,0 +1,6 @@ | |||
type t = { |
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.
I'd suggest marking the record as private so it's not possible to create by hand.
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.
Since not every record with the fields is the ArrayBuffer
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.
That's basically prevented by nominal typing
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.
I mean to prevent the code like this:
let myArrayBuffer: Js.ArrayBuffer.t = {
byteLenght: 2,
maxByteLength: 4,
detached: false,
resizable: false
}
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.
If we don't want that, we shouldn't use the binding pattern of exposing getters as record fields for every this-bounded object.
I thought it was already a widely used (even encouraged) pattern, more for practicality than strictness. for example: TheSpyder/rescript-webapi#78 (comment)
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.
I personally use private
for my projects. It kind of solves the problem:
type t = private {
byteLength: int,
maxByteLength: int,
detached: bool,
resizable: bool,
}
But I see one downside compared to getter
pattern:
You need to annotate the value when you access the field
let fn = (arrayBuffer: ArrayBuffer.t) => arrayBuffer.byteLenght
// vs
let fn = (arrayBuffer) => arrayBuffer->Js.ArrayBuffer.byteLength
It's fine for this case but when you have a type with a lot of complicated type arguments I prefer not to write annotations.
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.
Maybe we can just leave type t
here, but what about the Core's direction? @zth
I'll tune in to that.
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.
Wait, so does it make sense to provide compatibility with Js' type in the first place?
ok I'm going to close this and move it to Core entirely. If the direction is to remove JS in v12, I think there is no reason to change here, regardless of whether |
TypedArray.prototype.buffer
is polymorphic.ArrayBuffer
orSharedArrayBuffer
Atomics
is mostly used withInt32Array
on SAB.It's quite a corner case, but not a common use case, so I think it's not practical to make the module structure or type variants represent it strictly.