cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.45k stars 160 forks source link

typed arrayBuffer views should extend ArrayBufferView #118

Open froyo-np opened 8 years ago

froyo-np commented 8 years ago

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays

the WebGL candy requires ArrayBufferView objects for many methods, however the typed implementations do not extend this class.

for example, jsweet.lang.Uint8Array simply extends jsweet.lang.Object. Instead it should extend jsweet.lang.ArrayBufferView.

I am guessing that this is true for all the typed arrays?

renaudpawlak commented 8 years ago

JSweet's API is a translation of TypeScript API. In TypeScript core lib, Uint8Array does not extend the ArrayBufferView interface... I think that it is because it is not mandatory in TypeScript since typing can be inferred from the interface properties. So, I think that you are right and that we should force that inheritance link in JSweet.

Note that it is a non-blocking issue and that you can always brute-force cast your arrays...

If you can, it would be nice to give us some code snippets of your use cases, so that we can add them to the test suite if appropriate.

Thanks.

froyo-np commented 8 years ago

Thanks for the response, as well as your help on issue #119 as well. I don't know why I didn't think of just doing a type-cast...

anyway, here's a code snippet that shows the issue for me (for your test suite if appropriate):

//not shown: gl=WebGLRenderingContext, valid webgl state set up for buffer reading int PX = 0; int PY = 0; ArrayBuffer arb = new ArrayBuffer(2 * 2 * 4); Uint8Array clrs = new Uint8Array(arb); //read values from currently bound texture object at PX,PY gl.readPixels((double)PX,(double)PY, (double)2, (double)2, this.gl.RGBA, this.gl.UNSIGNED_BYTE, clrs);