Issues calling javascript object methods directly vs callMethod #49399
Labels
area-web
Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop.
web-js-interop
Issues that impact all js interop
I have an open PR for grpc-dart to implement a fetch transport rather than XHR. I just recently realized the code wasn't working in release builds. I had to change the code from calling methods directly on a dynamic object that represents a javascript ReadableStream to using callMethod. The original code worked fine while debugging, but it wasn't until building in release and deploying it that I realized it didn't work.
Here's a link to the commit that works around the issue:
grpc/grpc-dart@5a8818b
The dart code in question from the PR looks something like this (from fetch_transport.dart):
This generates the following javascript:
The result is a type error
o.aNq is not a function
. That's not all that readable so I generated it with--dart-define=Dart2jsOptimization=O0
which results in the following snippet:This is quite a bit more readable, but it still fails on the
getReader$0()
call because this should just begetReader()
. If I change the code to use callMethod this resolves the issue, but results in more code and is less readable. As you can see from the commit I also had to stop calling read directly on the reader and instead use callMethod there too. My biggest complaint is really just the inconsistency between debugging and release though because having it's much easier to debug/troubleshoot it during dev than after it's been deployed.The final javascript with my changes (Note that it actually just calls
stream.getReader()
as expected):The text was updated successfully, but these errors were encountered: