Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@ditman
Copy link
Member

@ditman ditman commented Oct 12, 2024

This PR removes the old futureToPromise implementation (which was barely used), and replaces it by a more standard js_interop approach.

Fixes flutter/flutter#155732

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Oct 12, 2024
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
Copy link
Member Author

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 (?)

Copy link
Contributor

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:

, and therefore your extension might not resolve.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlutterApp isn'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.
Copy link
Member Author

@ditman ditman Oct 12, 2024

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)

Copy link
Contributor

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!

@ditman ditman requested a review from srujzs October 12, 2024 03:30
@ditman
Copy link
Member Author

ditman commented Oct 12, 2024

/cc @srujzs this is what I ended up with from our talk today!

Copy link
Contributor

@srujzs srujzs left a 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.
Copy link
Contributor

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
Copy link
Contributor

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:

, and therefore your extension might not resolve.

/// 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) {
Copy link
Contributor

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?

Copy link
Member Author

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.

@ditman ditman marked this pull request as ready for review October 15, 2024 18:51
Copy link
Contributor

@eyebrowsoffire eyebrowsoffire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ditman
Copy link
Member Author

ditman commented Oct 21, 2024

(Updating to apply the auto-submit label after a fresh run of tests)

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 21, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 22, 2024
@auto-submit
Copy link
Contributor

auto-submit bot commented Oct 22, 2024

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.

@ditman
Copy link
Member Author

ditman commented Oct 22, 2024

Try again my dear bots!

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 22, 2024
@auto-submit auto-submit bot merged commit 5d3a474 into flutter:main Oct 22, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 23, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 23, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 23, 2024
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
M97Chahboun pushed a commit to M97Chahboun/flutter that referenced this pull request Oct 30, 2024
…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
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web] Rejected promises show up as console warnings.

3 participants