Please correct the definition TJSCrypto class (Web.pas), the correct is 'crypto'
TJSCrypto = class external name 'crypto' (TJSObject)

Mailing lists / pas2js / 2019-08
9 messages · 3 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Please correct the definition TJSCrypto class (Web.pas), the correct is 'crypto'
TJSCrypto = class external name 'crypto' (TJSObject)
warleyalex wrotePlease correct the definition TJSCrypto class (Web.pas), the correct is 'crypto'
not according to
https://developer.mozilla.org/en-US/docs/Web/API/Crypto
The window.crypto property is lowercased, but not the interface.
Michael.
the original definition in Web.pas
===================================
TJSCrypto = class external name 'Crypto' (TJSObject)
private
Fsubtle: TJSSubtleCrypto; external name 'subtle';
Public
class procedure getRandomValues (anArray : TJSTypedArray);
property subtle : TJSSubtleCrypto Read Fsubtle;
end;
===================================... I need to access the getRandomValues method.
e.g.
TJSCrypto.getRandomValues(data);the method getRandomValues is not available!
the minor error within name "crypto" definition, I believe the correct is:
TJSCrypto = class external name 'crypto' (TJSObject)
to generate the correct output
window.crypto.getRandomValues(array);Nono. You are accessing it wrong.
This is the code you should be using:
Window.crypto.getRandomValues(data);Michael.
Then it should be " class external name 'Window.crypto' ", should it not?
Mattias
No. The interface is called "Crypto".
The only instance of this interface is available through Window.Crypto.
You cannot create an instance of this class/interface.
Michael.
code to reproduce the issue:
------
var
data: TJSUint8Array;
begin
data := TJSUint8Array.New(16);
TJSCrypto.getRandomValues(data);
------We have this msg when compiling:
Error: Cannot access this member from a class
*******
...to make to work, I have to make 2 changes in the definition:
1st) add the modifier class procedure and
2nd) put the external name "crypto" instead of "Crypto" to avoid
Uncaught TypeError: Crypto.getRandomValues is not a function
I repeat, you are doing this wrong.
Your code should be:
Window.Crypto.getRandomValues(data);Michael.
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.