Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm_run_flutter on Safari browser: build() fails #56

Open
michelerenzullo opened this issue May 15, 2024 · 8 comments
Open

wasm_run_flutter on Safari browser: build() fails #56

michelerenzullo opened this issue May 15, 2024 · 8 comments

Comments

@michelerenzullo
Copy link
Contributor

michelerenzullo commented May 15, 2024

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
Copy link
Contributor Author

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
Copy link
Contributor Author

michelerenzullo commented May 16, 2024

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
Copy link
Contributor Author

michelerenzullo commented May 16, 2024

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

@juancastillo0
Copy link
Owner

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

@michelerenzullo
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@juancastillo0
Copy link
Owner

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

@michelerenzullo
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants