HaxeFoundation / HaxeFoundation/haxe

Typed array views should unify with ArrayBufferView

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

Description

Since typed array views [implement the ArrayBufferView interface](https://www.khronos.org/registry/typedarray/specs/latest/#TypedArray), this should work:

``` haxe
var view:haxe.io.ArrayBufferView = new haxe.io.Float32Array(3)
```

However, although `haxe.io.Float32Array` abstracts `haxe.io.ArrayBufferView` it does not implicitly cast to it. `(new Float32Array(3)).view` works but seems unnecessary.

An example of where this is useful is in the WebGL API where `:ArrayBufferView` is the accepted type for a number of parameters.

I think it'd be worthwhile to add `to ArrayBufferView` (or similar) to the typed array abstracts and look into _maybe_ removing the `.view` field since it should no longer be needed. If you agree I'll create a PR.

(There's also a [public `get_view` field](https://github.com/HaxeFoundation/haxe/blob/development/std/haxe/io/Float32Array.hx#L40) on the typed array views which seems like it should be private?)

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.