Re: [w3c/FileAPI] Why are Blob() and File() constructors at Chromium 81 throwing RangeError? (#147)

@inexorabletash 

Another example where using `[]` or not has a substantial impact on the result, even where the input is a `TypedArray`

```
var floats = new Float32Array([0.00005549501292989589, 0.00006459458381868899, 0.000058644378441385925, 0.00006201512587722391]);
var file = new Blob(floats); // pass TypedArray
file.arrayBuffer().then(b =>  console.log(new Float32Array(b))).catch(console.error);
// Chromium error message
RangeError: byte length of Float32Array should be a multiple of 4
    at new Float32Array (<anonymous>)
// Nightly error message
RangeError: "attempting to construct out-of-bounds TypedArray on ArrayBuffer"
// why?
file.text().then(console.log).catch(console.error);
Promise {<pending>}
0.000055495012929895890.000064594583818688990.0000586443784413859250.00006201512587722391
```

compare
```
var floats = new Float32Array([0.00005549501292989589, 0.00006459458381868899, 0.000058644378441385925, 0.00006201512587722391]);
var file = new Blob([floats]); // pass TypedArray within []
file.arrayBuffer().then(b =>  console.log(new Float32Array(b))).catch(console.error);
Promise {<pending>}
Float32Array(4) [0.00005549501292989589, 0.00006459458381868899, 0.000058644378441385925, 0.00006201512587722391]
// why?
file.text().then(console.log).catch(console.error);
Promise {<pending>}
Q�h8�v�8��u8�8
```

In this case the File API specification refers to 

> [4.2. BufferSource](https://heycam.github.io/webidl/#BufferSource)
> 
> `typedef (ArrayBufferView or ArrayBuffer) BufferSource;`
> 
> The BufferSource typedef is used to represent objects that are either themselves an ArrayBuffer **or which provide a view on to an ArrayBuffer.**

Emphasis added above beginning at "or".

Is a `TypedArray` already a sequence? Why is a `TypedArray` being converted to a string when `[]` is omitted from `Blob` constructor at `new Blob(TypedArray)`?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/FileAPI/issues/147#issuecomment-609444215

Received on Sunday, 5 April 2020 16:35:02 UTC