juancastillo0 / wasm_run

A WebAssembly executor for Dart and Flutter applications. Uses Rust's wasmtime optimizing runtime or wasmi interpreter to parse and execute WASM and WAT files.
https://juancastillo0.github.io/wasm_run/
MIT License
112 stars 10 forks source link

`isVoidReturn` should be exposed #39

Closed gmpassos closed 11 months ago

gmpassos commented 12 months ago

Since the use of the inner Function should be allowed, it's important to be able to check if the returned value is void.

juancastillo0 commented 11 months ago

Hi thanks for the issue!

On native platforms you can use the WasmFunction.results.length to check whether a function returns something.

On web you can use js_util.typeofEquals<dynamic>(result, 'undefined') to check whether the return is undefined. Before Dart 3.0 I think you need to use the following code for web (in wasm_run we use both methods):

bool isVoidReturn(dynamic value) {
  switch (value) {
    case null:
      return false;
    default:
      return value == null;
  }
}

Although we can could expose it I don't feel it's necessary. But I could be wrong, please let me know if those methods workd for you or if you think we should expose isVoidReturn.

Thanks