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
[web] Migrate DOM shim to JS types. #40310
Conversation
9d8d713
to
c4e3526
Compare
@ditman @eyebrowsoffire @mdebbar , this is basically ready for review. There may be some bugs and back and forth while I do some framework testing, but this CL is large, and we want to land it as quickly as possible so we can unblock other efforts, so it makes sense to start the review ASAP. These will be the patterns for JS interop we will use until we have inline classes, which will be later this year. That migration will be much smaller than this one as it just involves changing how the classes are defined. Some things to note:
|
@srujzs FYI. Please feel free to leave comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the change LGTM if it LGT @eyebrowsoffire. I just have a few questions to understand things better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! If everybody else's happy, and tests pass; I'm happy!
Also I've read in a comment to Mouad that we have rules that are (going to be) automatically enforceable when compiling libraries, so hit it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with a minor nitpick. I also wanted to share a few non-blocking thoughts on how this is shaping up.
- One thing that bothers me a little bit is
JSNumber.toDart
, which secretly means "double". I think atoDart
function is perfectly fine for things where their translation is immediately obvious, likeJSString -> String
. But for things that are actually ambiguous likeJSNumber
, I sort of wish it hadtoInt
andtoDouble
but notoDart
. I understand thattoDart
is actually onObject
(I think?) so maybe this is not that tractable, but I thought I'd share my general feeling about this. - Definitely not necessary for this PR or anything like that, but I actually feel like a lot of the
toDart
andtoJS
calls should actually go to the call sites, not indom.dart
.dom.dart
is more or less a direct representation of the browser API itself, and as such, if you're using the APIs exposed in here, you are very much aware that you are interacting with JavaScript. Therefore, I believe it is on the layer above to decide if and how to do that marshaling.
There are many situations in which we might be taking a JSString
directly from a browser API and passing it back into another browser API, which doesn't necessarily need a translation. With this setup, we are always doing conversions back and forth even if we don't need it. This combined with the fact that the profiles of wasm startup are heavily bogged down in JS<->Dart string conversions, I think we should really start thinking about doing another pass at some point that makes all the APIs in dom.dart
deal with JS objects purely, and modify the call sites. That being said, this PR is probably the simpler and more iterative way to do it, so I think that is a bridge to cross another day.
This is an interesting idea. I definitely see both sides, and there are a lot of points in the design space. Let's roll out
Huge +1 to this, let's do this work as a follow on. It will be a nice cleanup that will make it crystal clear to engine developers where the exact boundary between Dart and JS is. I also agree with your point on efficiency. There are probably many places where these conversions are not necessary, even in a local sense, let alone if we decide we want to hold on to JS types in maps and so forth instead of their Dart counterparts. I added a comment. |
Roll Flutter Engine from 476985ae3014 to 59e21ffbf9b8 (1 revision)
…122895) Commit: 038eea6312b4f868488d08807d788f4a6133e923
This CL is the first in a small set of CLs to migrate the DOM shim to JS types.