Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: sdk/lib/_internal/js_runtime/lib/async_patch.dart

Issue 2858463002: js_runtime: Split _asyncHelper into separate functions (Closed)
Patch Set: update test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/js_runtime/lib/async_patch.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/async_patch.dart b/sdk/lib/_internal/js_runtime/lib/async_patch.dart
index 893a2ebb044f27f7f7de91f19bafdfc1be420b97..f4ad69480378f8a7a67500db3a7d2d0d57138043 100644
--- a/sdk/lib/_internal/js_runtime/lib/async_patch.dart
+++ b/sdk/lib/_internal/js_runtime/lib/async_patch.dart
@@ -130,38 +130,53 @@ class Timer {
}
}
-/// Runtime support for async-await transformation.
+/// Initiates the computation of an `async` function.
///
-/// This function is called by a transformed function on each await and return
-/// in the untransformed function, and before starting.
+/// Used as part of the runtime support for the async/await transformation.
///
-/// If [object] is not a future it will be wrapped in a `new Future.value`.
+/// This function sets up the first call into the transformed [bodyFunction].
+/// Independently, it takes the [completer] and returns the future of the
+/// completer for convenience of the transformed code.
+dynamic _asyncStart(_WrappedAsyncBody bodyFunction, Completer completer) {
+ // Expansion and specialization of `await null`.
+ Function thenCallback =
+ (result) => bodyFunction(async_error_codes.SUCCESS, result);
+ // We can skip the zone registration, since the bodyFunction is already
+ // registered (see [_wrapJsFunctionForAsync]).
+ Future._nullFuture._thenNoZoneRegistration(thenCallback, null);
+ return completer.future;
+}
+
+/// Performs the `await` operation of an `async` function.
///
-/// If [asyncBody] is [async_error_codes.SUCCESS]/[async_error_codes.ERROR] it
-/// indicates a return or throw from the async function, and
-/// complete/completeError is called on [completer] with [object].
+/// Used as part of the runtime support for the async/await transformation.
///
-/// Otherwise [asyncBody] is set up to be called when the future is completed
-/// with a code [async_error_codes.SUCCESS]/[async_error_codes.ERROR] depending
-/// on the success of the future.
+/// Arranges for [bodyFunction] to be called when the future or value [object]
+/// is completed with a code [async_error_codes.SUCCESS] or
+/// [async_error_codes.ERROR] depending on the success of the future.
+dynamic _asyncAwait(dynamic object, _WrappedAsyncBody bodyFunction) {
+ _awaitOnObject(object, bodyFunction);
+}
+
+/// Completes the future of an `async` function.
///
-/// Returns the future of the completer for convenience of the first call.
-dynamic _asyncHelper(
- dynamic object,
- dynamic /* int | _WrappedAsyncBody */ bodyFunctionOrErrorCode,
- Completer completer) {
- if (identical(bodyFunctionOrErrorCode, async_error_codes.SUCCESS)) {
- completer.complete(object);
- return;
- } else if (identical(bodyFunctionOrErrorCode, async_error_codes.ERROR)) {
- // The error is a js-error.
- completer.completeError(
- unwrapException(object), getTraceFromException(object));
- return;
- }
+/// Used as part of the runtime support for the async/await transformation.
+///
+/// This function is used when the `async` function returns (explicitly or
+/// implicitly).
+dynamic _asyncReturn(dynamic object, Completer completer) {
+ completer.complete(object);
+}
- _awaitOnObject(object, bodyFunctionOrErrorCode);
- return completer.future;
+/// Completes the future of an `async` function with an error.
+///
+/// Used as part of the runtime support for the async/await transformation.
+///
+/// This function is used when the `async` function re-throws an exception.
+dynamic _asyncRethrow(dynamic object, Completer completer) {
+ // The error is a js-error.
+ completer.completeError(
+ unwrapException(object), getTraceFromException(object));
}
/// Awaits on the given [object].
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend_impact.dart ('k') | tests/compiler/dart2js/async_await_js_transform_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698