wasm_run icon indicating copy to clipboard operation
wasm_run copied to clipboard

wasm_run_flutter on Safari browser: build() fails

Open michelerenzullo opened this issue 9 months ago • 8 comments

Trying to .build() a basic WASM module on Safari seems to return this error, while running the same on Firefox or Chrome works fine Tried also with .buildSync()

An error occurred: Invalid argument (name): No enum value with that name: "funcref"

I'm investigating, quite strange.

~It might be related to (?)~

  (table (;0;) 27 27 funcref)

UPDATE: A couple of Issues are around _getTableType + Enum ValueTy and _getType.

  • Chrome return a Map<String, Object?> null so _getTableType execution is stopped and return a TableTy null, while Safari throw an exception when calling _getType but for some reason continue the execution of _getTableType
  • till get stopped by a mismatch in t['element'] == 'funcref' while the enum is funcRef

michelerenzullo avatar May 15 '24 23:05 michelerenzullo

Playing around with the cached built files I found that the issue arise in _wasm_interop_web.dart:

TableTy? _getTableType(Object value) {
  final t = _getType(value);
  if (t == null) return null;
  final ty = ValueTy.values.byName(t['element']! as String);    //here fails on Safari
  return TableTy(
    element: ty,
    minimum: t['minimum']! as int,
    maximum: t['maximum'] as int?,
  );
}

michelerenzullo avatar May 16 '24 13:05 michelerenzullo

Fixed, "funcref" is not part of Enum ValueTy, because ValueTy has "funcRef", ~for some reason on Safari the case matters, while on Chrome is able to ignore the case~. Will clean up and send a pull request

UPDATE: Seems the divergences between browsers are not about case sensitive, is that Chrome return null in the line before, while this doesn't happen on Safari.

The code below does the trick and fix the .byName failure on Safari but would be more wise to fix _getType, how the object is manipulated / parsed. This will prevent divergences and potential new issues...

  final ty = ValueTy.values.firstWhere((value) =>
      value.toString().split('.').last.toLowerCase() ==
      (t['element']! as String).toLowerCase());

michelerenzullo avatar May 16 '24 13:05 michelerenzullo

There is something else strange,

Map<String, Object?>? _getType(Object value) {
  print("Properties of value: ${value.jsify()}");
  if (!js_util.hasProperty(value, 'type')) return null;
  final type = js_util.callMethod<Object?>(value, 'type', const []);
  return (js_util.dartify(type)! as Map).cast();
}

if (!js_util.hasProperty(value, 'type')) return null; throw an exception on Safari so is returned true somehow, so the code block is continued, on Chrome instead hasProperty 'type' is false so it returns null, and so _getTableType always return null

michelerenzullo avatar May 16 '24 14:05 michelerenzullo

Thanks for the issue and the PR! https://pub.dev/packages/wasm_run version ^0.1.0+2 has been published, please let me know if it works for you

juancastillo0 avatar May 24 '24 12:05 juancastillo0

Thanks! As soon is approved on pub.dev will try my test, I think shall be good. Btw, do you have any thoughts about what I think is the main issue / parent in _getType? My assumption is that not only Safari should have been failed but also Chrome if _getType was working correctly and non returning null

michelerenzullo avatar May 24 '24 12:05 michelerenzullo

Could you publish the update of wasm_run_flutter so that it targets wasm_run 0.1.0+2 ? Thank you

michelerenzullo avatar May 24 '24 16:05 michelerenzullo

I believe flutter pub upgrade in your project should fix the issue. wasm_run_flutter has wasm_run : ^0.1.0 as the version restriction

juancastillo0 avatar May 25 '24 12:05 juancastillo0

Confirmed, works :) updated from +1 to +2

michelerenzullo avatar May 25 '24 19:05 michelerenzullo