Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2019-08

TJSCrypto name minor error

9 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

warleyalex
to Michael Van Canneyt
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);

Reply by email

Michael Van Canneyt
to warleyalex
warleyalex wrote 23 lines
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.

Reply by email

Mattias Gaertner
to Michael Van Canneyt
Show quoted text 32 lines
On Mon, 12 Aug 2019, warleyalex via Pas2js wrote: > 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);

Then it should be " class external name 'Window.crypto' ", should it not?

Mattias

Reply by email

Michael Van Canneyt
to Mattias Gaertner
Mattias Gaertner wrote 38 lines
On Mon, 12 Aug 2019 14:38:46 +0200 (CEST) Michael Van Canneyt wrote: > On Mon, 12 Aug 2019, warleyalex via Pas2js wrote: > > > 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); Then it should be " class external name 'Window.crypto' ", should it not?

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.

Reply by email

warleyalex
to Michael Van Canneyt
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

Reply by email

Michael Van Canneyt
to warleyalex
warleyalex wrote 11 lines
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);

Michael.

Reply by email

Michael Van Canneyt
to Michael Van Canneyt
Michael Van Canneyt wrote 20 lines
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.

Reply by email