-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Remove old futureToPromise. #55847
Conversation
| abstract class FlutterAppRunner { | ||
| factory FlutterAppRunner({required RunAppFn runApp,}) => FlutterAppRunner._( | ||
| runApp: (([RunAppFnParameters? args]) => futureToPromise(runApp(args) as Future<JSObject>)).toJS | ||
| runApp: (([RunAppFnParameters? args]) => (runApp(args) as Future<JSObject>).toPromise).toJS |
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.
If I remove the as cast, toPromise stops working (?)
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.
Right, it looks like runApp statically returns a FlutterApp which isn't a JS type since it isn't an interop extension type:
| @JS() |
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.
FlutterAppisn't a JS type since it isn't an interop extension type
This makes sense to me. Next steps would be to start migrating this whole js_interop directory to the proper extension-type based interop types.
(That's another Yak, though :P)
| /// This is the same as package:js_interop's FutureToPromise (.toJS), but with | ||
| /// a more descriptive error message. | ||
| /// | ||
| /// TODO(srujzs/dit): Move to js_interop's .toJS. |
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.
We need to revisit the JS Interop's JSPromise error reporting. The current version boxes hides the message and stack trace in a non-standard place, and makes the reporting in the JS console bad (I'll probably create an issue in dart-lang)
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.
The stack property is somewhat recognized fwiw: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack, but it may be better to populate the error message directly with a stack trace for readability. Hopefully we can come up with something here without a breaking change!
|
/cc @srujzs this is what I ended up with from our talk today! |
srujzs
left a comment
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.
Thanks for digging further, David!
| /// This is the same as package:js_interop's FutureToPromise (.toJS), but with | ||
| /// a more descriptive error message. | ||
| /// | ||
| /// TODO(srujzs/dit): Move to js_interop's .toJS. |
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.
The stack property is somewhat recognized fwiw: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack, but it may be better to populate the error message directly with a stack trace for readability. Hopefully we can come up with something here without a breaking change!
| abstract class FlutterAppRunner { | ||
| factory FlutterAppRunner({required RunAppFn runApp,}) => FlutterAppRunner._( | ||
| runApp: (([RunAppFnParameters? args]) => futureToPromise(runApp(args) as Future<JSObject>)).toJS | ||
| runApp: (([RunAppFnParameters? args]) => (runApp(args) as Future<JSObject>).toPromise).toJS |
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.
Right, it looks like runApp statically returns a FlutterApp which isn't a JS type since it isn't an interop extension type:
| @JS() |
| /// A [JSPromise] that either resolves with the result of the completed | ||
| /// [Future] or rejects with an object that contains its error. | ||
| JSPromise<T> get toPromise { | ||
| return JSPromise<T>((JSFunction resolve, JSFunction reject) { |
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.
Hmm, the only functional difference between this and toJS I see is that the then value here doesn't return anything in either the onValue or onError functions, but it would be strange if that makes a difference. Are you still seeing the same issues with toJS? Would the sane issue manifest with toPromise if we returned value and wrapper in the onValue and onError functions here?
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.
I think the problem I was seeing was the .toJS not being correctly applied because of the type of the JS Object that was being wrapped in the promise.
The only meaningful difference this has is attempting to compose a string that contains the Dart error text to create the JS Error object when rejecting the promise.
eyebrowsoffire
left a comment
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.
LGTM!
|
(Updating to apply the auto-submit label after a fresh run of tests) |
|
auto label is removed for flutter/engine/55847, due to - The status or check suite Mac mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
Try again my dear bots! |
flutter/engine@50f6d98...ec6e28a 2024-10-23 jonahwilliams@google.com [display_list] grow display list backing store by power of two. (flutter/engine#56004) 2024-10-23 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from xPbin_33tT-_omeQT... to NxrFCTty8wV4-6Cpl... (flutter/engine#56056) 2024-10-23 skia-flutter-autoroll@skia.org Roll Dart SDK from 20470aaa17be to 2a4b728f6a03 (3 revisions) (flutter/engine#56055) 2024-10-23 robert.ancell@canonical.com Move get_keyboard_state from FlKeyboardViewDelegate to FlKeyboardManager. (flutter/engine#56021) 2024-10-23 robert.ancell@canonical.com Move send_key_event from FlKeyboardViewDelegate to FlKeyboardManager. (flutter/engine#56020) 2024-10-23 bdero@google.com [Flutter GPU] Fix assert failure in createDeviceBufferWithCopy. (flutter/engine#56039) 2024-10-22 skia-flutter-autoroll@skia.org Roll Dart SDK from 8de85635d731 to 20470aaa17be (4 revisions) (flutter/engine#56038) 2024-10-22 ditman@gmail.com [web] Remove old futureToPromise. (flutter/engine#55847) 2024-10-22 737941+loic-sharma@users.noreply.github.com [dart:ui] Improve Clip's docs (flutter/engine#55978) 2024-10-22 jonahwilliams@google.com [Impeller] flush thread local resources during toImage/toImageSync. (flutter/engine#56037) 2024-10-22 kpsroka@users.noreply.github.com [canvaskit] Makes access to CkSurface null-safer (flutter/engine#54895) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from xPbin_33tT-_ to NxrFCTty8wV4 If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC codefu@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…57453) flutter/engine@50f6d98...ec6e28a 2024-10-23 jonahwilliams@google.com [display_list] grow display list backing store by power of two. (flutter/engine#56004) 2024-10-23 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from xPbin_33tT-_omeQT... to NxrFCTty8wV4-6Cpl... (flutter/engine#56056) 2024-10-23 skia-flutter-autoroll@skia.org Roll Dart SDK from 20470aaa17be to 2a4b728f6a03 (3 revisions) (flutter/engine#56055) 2024-10-23 robert.ancell@canonical.com Move get_keyboard_state from FlKeyboardViewDelegate to FlKeyboardManager. (flutter/engine#56021) 2024-10-23 robert.ancell@canonical.com Move send_key_event from FlKeyboardViewDelegate to FlKeyboardManager. (flutter/engine#56020) 2024-10-23 bdero@google.com [Flutter GPU] Fix assert failure in createDeviceBufferWithCopy. (flutter/engine#56039) 2024-10-22 skia-flutter-autoroll@skia.org Roll Dart SDK from 8de85635d731 to 20470aaa17be (4 revisions) (flutter/engine#56038) 2024-10-22 ditman@gmail.com [web] Remove old futureToPromise. (flutter/engine#55847) 2024-10-22 737941+loic-sharma@users.noreply.github.com [dart:ui] Improve Clip's docs (flutter/engine#55978) 2024-10-22 jonahwilliams@google.com [Impeller] flush thread local resources during toImage/toImageSync. (flutter/engine#56037) 2024-10-22 kpsroka@users.noreply.github.com [canvaskit] Makes access to CkSurface null-safer (flutter/engine#54895) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from xPbin_33tT-_ to NxrFCTty8wV4 If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC codefu@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This PR removes the old `futureToPromise` implementation (which was barely used), and replaces it by a more standard js_interop approach. Fixes flutter#155732 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This PR removes the old
futureToPromiseimplementation (which was barely used), and replaces it by a more standard js_interop approach.Fixes flutter/flutter#155732
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.