JavaScript generator does not resolve array access to a function call

57 views
Skip to first unread message

vroad

unread,
Nov 7, 2014, 5:56:27 AM11/7/14
to haxe...@googlegroups.com
JavaScript generator tries to access it with array access operator[], even if it's not a JavaScript array.
Why it doesn't convert to a function call?

var starling_utils_VertexData = function(numVertices,premultipliedAlpha) {
...
this.mRawData = new lime_utils_Float32Array(0);
...
};
...
this.mRawData[targetIndex++] = rawData[i];
...

this.mRawData is JavaScript Object, not an array.
Since JavaScript does not support operator overloading, it doesn't make sense to access it with array index operator.
This code runs, but it just adds objects to this.mRawData. It doesn't change the content of lime's typed array.

I tried to compile latest version of Haxe to see whether this problem is fixed.
I had to remove "native" from TARGET_FLAGS to compile development version.
Even after that, compile failed with this message. What does it mean??

File "gencs.ml", line 3127, characters 22-31:
Error: The record type IlData.ilfield has no field fconstant

Dan Korostelev

unread,
Nov 7, 2014, 8:24:32 AM11/7/14
to haxe...@googlegroups.com
Looking at the docs https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Float32Array it supports array access, so I don't really understand what's wrong there.

As for the compilation issue, update submodule, do a "make clean" and try again.

пятница, 7 ноября 2014 г., 13:56:27 UTC+3 пользователь vroad написал:

vroad

unread,
Nov 7, 2014, 9:19:35 AM11/7/14
to haxe...@googlegroups.com
I should have mentioned that I have been trying to use OpenFL on node.js.
The code posted above is not typed array of html5(or node.js). It is a class included in lime's repository, which is backed by node's Buffer class on node.js target.

http://nodejs.org/api/buffer.html

The same thing happened with ByteArray when I tried to access it with array index operator.
JavaScript generator didn't convert this to __get function of ByteArray.
I think this is a bug.


For built-in classes like Float32Array on html5, yes, it is possible to access with array index operator, and generator doesn't need to convert in this case.
Since JavaScript doesn't support operator overloading, you can register these kind of classes only from native code, I guess.

As a workaround, I may switch from Buffer to node's typed array class.

I have tried recompiling after clean and submodule update, and still getting same error.
Doesn't this compile error happen on other enviroments? I'm using MinGW.

2014年11月7日金曜日 22時24分32秒 UTC+9 Dan Korostelev:

vroad

unread,
Nov 9, 2014, 4:01:15 AM11/9/14
to haxe...@googlegroups.com
I didn't understand the concept of ArrayAccess interface. It just indicates that the class is accessible with array index operator, and doesn't let you override array operator on js. If so, why does ByteArray implement ArrayAccess interface on js? Isn't this a mistake?
Reply all
Reply to author
Forward
0 new messages