HaxeFoundation / HaxeFoundation/haxe
ArrayBufferView.subarray without `end` param
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
With this code
``` haxe
var arr = [1, 256, 2, 3];
var u8Arr = UInt8Array.fromArray(arr);
var subView = u8Arr.sub(1).view;
var subarrayView = u8Arr.subarray(1).view;
trace('sub : begin ${subView.byteOffset}, byteLength ${subView.byteLength}');
trace('subarray : begin ${subarrayView.byteOffset}, byteLength ${subarrayView.byteLength}');
```
neko outputs
```
sub : begin 1, byteLength 3
subarray : begin 1, byteLength 2
```
js outputs
```
sub : begin 1, byteLength 3
subarray : begin 1, byteLength 0
```
Both are wrong regarding subarray.
1. For neko it seems that the cause is [this line](https://github.com/HaxeFoundation/haxe/blob/b55a3422fd01b92caa8ac95a2ba6d6c510e185a9/std/haxe/io/ArrayBufferView.hx#L42), which should read `end = byteLength;`.
2. While for js has to do with the generated code, which looks like this:
``` js
var sub = u8Arr.subarray(1,u8Arr.length);
var subarray = u8Arr.subarray(1,null); // <- here
```
avoiding passing that null, or passing undefined seems to fix it for me.
Not a regression, I get the same behaviour with both ~latest haxe and one from mid january.
Contributor guide
Assessment
This issue has not been assessed yet.