wasm_run
wasm_run copied to clipboard
wasm_run_flutter on Safari browser: build() fails
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 aTableTy
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 isfuncRef
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?,
);
}
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());
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
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
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
Could you publish the update of wasm_run_flutter so that it targets wasm_run 0.1.0+2 ? Thank you
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
Confirmed, works :) updated from +1 to +2