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

Unified Diff: pkg/compiler/lib/src/js/rewrite_async.dart

Issue 1163833002: Dart2js async-await. Bind the async-body to the current zone. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js/rewrite_async.dart
diff --git a/pkg/compiler/lib/src/js/rewrite_async.dart b/pkg/compiler/lib/src/js/rewrite_async.dart
index 9ea66a2a73e77221f38d4782a9fb324fa7329bed..be1f26a204a5e5dce8f5b2a4f67e5a73d6416eee 100644
--- a/pkg/compiler/lib/src/js/rewrite_async.dart
+++ b/pkg/compiler/lib/src/js/rewrite_async.dart
@@ -1671,11 +1671,13 @@ class AsyncRewriter extends AsyncRewriterBase {
/// Specific to async methods.
final js.Expression newCompleter;
+ final js.Expression wrapBody;
AsyncRewriter(DiagnosticListener diagnosticListener,
spannable,
{this.asyncHelper,
this.newCompleter,
+ this.wrapBody,
String safeVariableName(String proposedName),
String bodyName})
: super(diagnosticListener,
@@ -1756,13 +1758,13 @@ class AsyncRewriter extends AsyncRewriterBase {
return js.js("""
function (#parameters) {
#variableDeclarations;
- function #bodyName(#errorCode, #result) {
+ var #bodyName = #wrapBody(function (#errorCode, #result) {
if (#errorCode === #ERROR) {
#currentError = #result;
#goto = #handler;
}
#rewrittenBody;
- }
+ });
return #asyncHelper(null, #bodyName, #completer, null);
}""", {
"parameters": parameters,
@@ -1777,6 +1779,7 @@ class AsyncRewriter extends AsyncRewriterBase {
"result": resultName,
"asyncHelper": asyncHelper,
"completer": completer,
+ "wrapBody": wrapBody,
});
}
}
@@ -1971,6 +1974,8 @@ class AsyncStarRewriter extends AsyncRewriterBase {
/// Called with the stream to yield from.
final js.Expression yieldStarExpression;
+ final js.Expression wrapBody;
+
AsyncStarRewriter(DiagnosticListener diagnosticListener,
spannable,
{this.asyncStarHelper,
@@ -1978,6 +1983,7 @@ class AsyncStarRewriter extends AsyncRewriterBase {
this.newController,
this.yieldExpression,
this.yieldStarExpression,
+ this.wrapBody,
String safeVariableName(String proposedName),
String bodyName})
: super(diagnosticListener,
@@ -2023,8 +2029,7 @@ class AsyncStarRewriter extends AsyncRewriterBase {
js.VariableDeclarationList variableDeclarations) {
return js.js("""
function (#parameters) {
- #variableDeclarations;
- function #bodyName(#errorCode, #result) {
+ var #bodyName = #wrapBody(function (#errorCode, #result) {
if (#hasYield) {
switch (#errorCode) {
case #STREAM_WAS_CANCELED:
@@ -2042,7 +2047,8 @@ class AsyncStarRewriter extends AsyncRewriterBase {
}
}
#rewrittenBody;
- }
+ });
+ #variableDeclarations;
return #streamOfController(#controller);
}""", {
"parameters": parameters,
@@ -2061,6 +2067,7 @@ class AsyncStarRewriter extends AsyncRewriterBase {
"result": resultName,
"streamOfController": streamOfController,
"controller": controllerName,
+ "wrapBody": wrapBody,
});
}
@@ -2093,7 +2100,8 @@ class AsyncStarRewriter extends AsyncRewriterBase {
List<js.VariableInitialization> variables =
new List<js.VariableInitialization>();
variables.add(_makeVariableInitializer(controller,
- js.js('#(#)', [newController, bodyName])));
+ js.js('#(#)',
+ [newController, bodyName])));
if (analysis.hasYield) {
variables.add(_makeVariableInitializer(nextWhenCanceled, null));
}
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698