[Pas2js] Pas2js 0.9.20
Michael Van Canneyt
michael at freepascal.org
Sat May 12 10:28:09 CEST 2018
On Sat, 12 May 2018, Ryan Joseph wrote:
>
>
>> On May 12, 2018, at 2:43 PM, Michael Van Canneyt <michael at freepascal.org> wrote:
>>
>> Hence my proposal to add overloads
>> _set (arr : Array of BaseType);
>> _set (arr : Array of BaseType; aOffset :NativeInt);
>> to each descendant.
>
> That would help and be nice but lots of working making overloads though
> and it’s possible we’re enforcing type safety where there shouldn’t be.
> You may very well be able to pass an array of ints to a Float32Array for
> example.
Maybe, but the result may not be what you expect or what you would expect if
it were pascal buffers.
a=new Uint8Array(3);
Uint8Array [ 0, 0, 0 ]
a.set([412,412,415])
undefined
console.log(a);
Uint8Array [ 156, 156, 159 ]
I would expect an error since the values are out of range. what happened
instead is that values were cut, presumably by taking the low byte of a
word-sized or integer-sized value.
So, forcing people to do a typecast to make them aware of this seems like a
good idea.
In short:
- One can use a typed array.
- One can use an array of the declared basetype
For all other cases, you must make a typecast.
Michael.
More information about the Pas2js
mailing list