Feature request - Declare Function in WASM

When we need to use an external call in WASM, the only option we have is to use EVAL.

The drawbacks of that is that EVAL has no designtime checks, no parameter validation (type checking), and does not support type inference when the result is assigned to a variable.

To make things easier, we could use the VB construct Declare Function.

To elaborate:

I have the following JS function in the Html:

function myFunction(p1, p2) {
  return p1 * p2;   // The function returns the product of p1 and p2
}

To call this function, I have to write:

Dim res As Double = CType(Eval("myFunction(2, 3)", Double)

And I have to do this at any call to it.

  • not really readable
  • no checks at all

The solution for this would be if I could DECLARE the JS function is WASM:

Declare Function myFunction(p1 As Double, p2 As Double) As Double

Then I can use it without EVAL:

Dim res = MyFunction(2, 3)

Much more readable, typechecks on the parameters and type inference,

For the correctness of the Declare: That won’t be checked. If it is wrong it will fail in runtime.

We should be able to declare anything that can be called by eval.

1 Like

bugs://E25486: WebAssembly: allow “external” methods to create strongly-typed Eval() wrappers

1 Like

Addition to the request:

When the external function returns a Future, we should be able to define it as:

Declare Async Function myFunction(p1 As Double, p2 As Double) As Task(of Double)

Added

1 Like