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

Unified Diff: pkg/compiler/lib/src/js_backend/backend.dart

Issue 1253333002: dart2js cps: Support async/await by rewriting the JavaScript AST. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rewrite to switch. Created 5 years, 4 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: pkg/compiler/lib/src/js_backend/backend.dart
diff --git a/pkg/compiler/lib/src/js_backend/backend.dart b/pkg/compiler/lib/src/js_backend/backend.dart
index 1c0f82c678f7346723807bd2df9ac4fab933c7a5..bdd1cc3a191627127c1f758e0476e1f6ecff0083 100644
--- a/pkg/compiler/lib/src/js_backend/backend.dart
+++ b/pkg/compiler/lib/src/js_backend/backend.dart
@@ -243,7 +243,7 @@ class JavaScriptBackend extends Backend {
String get patchVersion => emitter.patchVersion;
-
+
bool get supportsReflection => emitter.emitter.supportsReflection;
final Annotations annotations;
@@ -2731,6 +2731,61 @@ class JavaScriptBackend extends Backend {
}
return true;
}
+
+ jsAst.Expression rewriteAsync(FunctionElement element,
+ jsAst.Expression code) {
+ AsyncRewriterBase rewriter = null;
+ jsAst.Name name = namer.methodPropertyName(element);
+ switch (element.asyncMarker) {
+ case AsyncMarker.ASYNC:
+ rewriter = new AsyncRewriter(
+ compiler,
+ compiler.currentElement,
+ asyncHelper:
+ emitter.staticFunctionAccess(getAsyncHelper()),
+ newCompleter: emitter.staticFunctionAccess(
+ getCompleterConstructor()),
+ safeVariableName: namer.safeVariablePrefixForAsyncRewrite,
+ bodyName: namer.deriveAsyncBodyName(name));
+ break;
+ case AsyncMarker.SYNC_STAR:
+ rewriter = new SyncStarRewriter(
+ compiler,
+ compiler.currentElement,
+ endOfIteration: emitter.staticFunctionAccess(
+ getEndOfIteration()),
+ newIterable: emitter.staticFunctionAccess(
+ getSyncStarIterableConstructor()),
+ yieldStarExpression: emitter.staticFunctionAccess(
+ getYieldStar()),
+ uncaughtErrorExpression: emitter.staticFunctionAccess(
+ getSyncStarUncaughtError()),
+ safeVariableName: namer.safeVariablePrefixForAsyncRewrite,
+ bodyName: namer.deriveAsyncBodyName(name));
+ break;
+ case AsyncMarker.ASYNC_STAR:
+ rewriter = new AsyncStarRewriter(
+ compiler,
+ compiler.currentElement,
+ asyncStarHelper: emitter.staticFunctionAccess(
+ getAsyncStarHelper()),
+ streamOfController: emitter.staticFunctionAccess(
+ getStreamOfController()),
+ newController: emitter.staticFunctionAccess(
+ getASyncStarControllerConstructor()),
+ safeVariableName: namer.safeVariablePrefixForAsyncRewrite,
+ yieldExpression: emitter.staticFunctionAccess(
+ getYieldSingle()),
+ yieldStarExpression: emitter.staticFunctionAccess(
+ getYieldStar()),
+ bodyName: namer.deriveAsyncBodyName(name));
+ break;
+ default:
+ assert(element.asyncMarker == AsyncMarker.SYNC);
+ return code;
+ }
+ return rewriter.rewrite(code);
+ }
}
/// Handling of special annotations for tests.
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698