call method
Calls the exported C symbol cSymbol (without the leading underscore)
with pre-converted JS arguments.
Two dispatch strategies, chosen at compile time: dart2wasm pays a Dart→JS string conversion + property lookup + apply per varargs call, so it uses a per-symbol JSFunction cache with fixed-arity invocation (1791→1185 ns on the scalar benchmark). dart2js optimises the varargs form better than the cached switch (283 vs 611 ns), so it keeps the direct path.
Implementation
JSAny? call(String cSymbol, List<JSAny?> args) {
if (const bool.fromEnvironment('dart.tool.dart2wasm')) {
final fn = _fns[cSymbol] ??= _resolve(cSymbol);
return switch (args.length) {
0 => fn.callAsFunction(module),
1 => fn.callAsFunction(module, args[0]),
2 => fn.callAsFunction(module, args[0], args[1]),
3 => fn.callAsFunction(module, args[0], args[1], args[2]),
4 => fn.callAsFunction(module, args[0], args[1], args[2], args[3]),
_ => module.callMethodVarArgs('_$cSymbol'.toJS, args),
};
}
if (!providesSymbol(cSymbol)) {
throw StateError(
'$libName: WASM module has no export "_$cSymbol". The .wasm/.js '
'artifacts are stale — rebuild them (web/build_web.sh) after '
'`nitrogen generate`.',
);
}
return module.callMethodVarArgs('_$cSymbol'.toJS, args);
}