HaxeFoundation / HaxeFoundation/haxe

Inconsistent behaviour `new BytesOutput().getBytes().getData()` in standard library

Open
#8,974 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

```haxe
//swf,cpp:
var output = new haxe.io.BytesOutput();
for (i in 0...256) output.writeInt16(1);

var bytes = output.getBytes();
trace(bytes.length); // 512

var data = bytes.getData();
trace(data.length); // 512;
```
```haxe
//js:
var output = new haxe.io.BytesOutput();
for (i in 0...256) output.writeInt16(1);

var bytes = output.getBytes();
trace(bytes.length); // 512

var data = bytes.getData();
trace(data.length); // ERROR: haxe.io.BytesData has no field length

trace(data.byteLength); // 609, should be 512
```
How to reproduce (Haxe 4.0.2):
- Compile first example with -swf or -cpp
- both bytes.length and data.length are correct
- Compile second example with -js
- first problem: length property is not defined
- second problem: switching to byteLength, it seems the internal buffer is returned instead of the actual written bytes

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.