[Pas2js] TJSCrypto name minor error

Michael Van Canneyt michael at freepascal.org
Tue Aug 13 13:52:51 CEST 2019



On Tue, 13 Aug 2019, Michael Van Canneyt wrote:

>
>
> On Tue, 13 Aug 2019, warleyalex via Pas2js wrote:
>
>> code to reproduce the issue:
>> ------
>> var
>>  data: TJSUint8Array;
>>
>> begin
>>  data := TJSUint8Array.New(16);
>>  TJSCrypto.getRandomValues(data);
>> ------
>>
>> We have this msg when compiling:
>
> I repeat, you are doing this wrong.
>
> Your code should be:
> Window.Crypto.getRandomValues(data);

To make it more explicit:

Your code is transpiled to
   crypto.getRandomValues(data)

But because the global Javascript scope is always part of the window instance,
what you do is equivalent to
   window.crypto.getRandomValues(data)
That is why your code 'works', by accident.

But it is wrong none the less:
1. The name of the interface (it's an interface for a reason !) is Crypto.
2. getRandomValues is not a class method.
3. You can not instantiate an instance of Crypto.
    (this is actually a consequence of 1.)

I hope with this extended explanation you understand the issue.

Michael.


More information about the Pas2js mailing list