-
Notifications
You must be signed in to change notification settings - Fork 165
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
Is a TypedArray a sequence? #868
Comments
Browsing this repository for what a sequence is, unless missing a critical part of what is being described, per https://tc39.es/ecma262/#sec-%typedarray%.prototype-@@iterator a
Therefore it should not be necessary to do
for the
should suffice for passing a |
The argument in question is You’re correct that a TypedArray can be converted to a sequence. But that’s exactly what you’re seeing. The members of the iterable become strings because they’re originally numbers — and numbers can be coerced to USVString (in BlobPart) but not BufferSource of Blob. |
Closing, since this has been answered. |
This is the part that am not grasping
Why does What does |
The Float32Array is a |
What happens here:
outputs
where do the extra Am trying to concretely determine when |
(Should a note be included in File API conveying there is a difference between passing the two options to the constructor, or is that expected to be common knowledge?) |
In neither case is the TypedArray converted to a string. In the former case, the members of the iterable are converted to strings, and in the latter case they are not, because the TypedArray is already a BufferSource. In other words, the following two statements are effectively the same — both provide a sequence whose members are numbers, and those numbers end up being cast to string: new Blob(Uint8Array.of(1, 2, 3));
new Blob([ 1, 2, 3 ]); |
That clarifies the algorithm somewhat. However, that example, and the fundamental difference between passing a
is used compared to
however, as asked above, is that difference simply expected to be common knowledge, without a published example with accompanying description of the two options? |
I couldn’t say what the intentions or history are. In theory, the type of the argument could have been Whether such a change is web-compatible now, I’m not sure; you could open an issue on the File API repo if you think it’s worth investigating. I’d suggest searching there as well in case this has come up previously. It wouldn’t be a Web IDL level issue. FWIW, just to keep the picture clear, it’s not that an array is mandatory. It’s that the argument’s type is |
Am not sure if it is worth investigating from a specification standpoint. The first time encountered that was probably due to user error by passing an array of arrays (of Yes, experimented with From a front-end standpoint the inclusion or omission of |
Consider the following from File API
and this repository description of sequence
It is not immediately clear if a JavaScript
TypedArray
is considered a sequence either in File API or in this specification.When
[]
is not used inBlob
constructor and aTypedArray
is passed the values of theTypedArray
are converted to string, resulting in aRangeError
when attempting to convert theArrayBuffer
representation of theBlob
back to aTypedArray
the
RangeError
can be avoided and conversion back toTypedArray
fromArrayBuffer
is possible when the value passed atBlob
constructor is within[]
If a
TypedArray
is already a sequence it should not be necessary to wrap theTypedArray
in array literal inBlob
constructor to avoid theTypedArray
values being converted to a string.See w3c/FileAPI#147 (comment) and the test cases that follow at w3c/FileAPI#147 (comment).
Is a
TypedArray
a sequence?Is this working as intended?
The text was updated successfully, but these errors were encountered: