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

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart

Issue 2934623003: fix #29753, use ES5 constructors for ddc (Closed)
Patch Set: fix Created 3 years, 6 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/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
index cc022d2221fc9d272ccae1af70cf00c3220c3114..99d3b3f27f2a21c5a4539f2b5767fc55be30a8dd 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
@@ -14,12 +14,8 @@ part of dart._runtime;
final _jsIterator = JS('', 'Symbol("_jsIterator")');
final _current = JS('', 'Symbol("_current")');
-syncStar(gen, E, @rest args) => JS(
- '',
- '''(() => {
- const SyncIterable_E = ${getGenericClass(SyncIterable)}($E);
- return new SyncIterable_E($gen, $args);
-})()''');
+syncStar(gen, E, @rest args) =>
+ JS('', 'new (${getGenericClass(SyncIterable)}($E).new)($gen, $args)');
@JSExportName('async')
async_(gen, T, @rest args) => JS(
@@ -79,30 +75,30 @@ async_(gen, T, @rest args) => JS(
return result;
})()''');
-// Implementation inspired by _AsyncStarStreamController in
-// dart-lang/sdk's runtime/lib/core_patch.dart
-//
-// Given input like:
-//
-// foo() async* {
-// yield 1;
-// yield* bar();
-// print(await baz());
-// }
-//
-// This generates as:
-//
-// function foo() {
-// return dart.asyncStar(function*(stream) {
-// if (stream.add(1)) return;
-// yield;
-// if (stream.addStream(bar()) return;
-// yield;
-// print(yield baz());
-// });
-// }
-//
-// TODO(ochafik): Port back to Dart (which it used to be in the past).
+/// Implementation inspired by _AsyncStarStreamController in
+/// dart-lang/sdk's runtime/lib/core_patch.dart
+///
+/// Given input like:
+///
+/// foo() async* {
+/// yield 1;
+/// yield* bar();
+/// print(await baz());
+/// }
+///
+/// This generates as:
+///
+/// function foo() {
+/// return dart.asyncStar(function*(stream) {
+/// if (stream.add(1)) return;
+/// yield;
+/// if (stream.addStream(bar()) return;
+/// yield;
+/// print(yield baz());
+/// });
+/// }
+///
+// TODO(jmesserly): port back to Dart, based on VM's equivalent class.
final _AsyncStarStreamController = JS(
'',
'''
@@ -245,10 +241,6 @@ final _AsyncStarStreamController = JS(
}
''');
-/// Returns a Stream of T implemented by an async* function. */
-///
-asyncStar(gen, T, @rest args) => JS(
- '',
- '''(() => {
- return new $_AsyncStarStreamController($gen, $T, $args).controller.stream;
-})()''');
+/// Returns a Stream of T implemented by an async* function.
+asyncStar(gen, T, @rest args) => JS('', 'new #(#, #, #).controller.stream',
vsm 2017/06/12 19:39:31 Do we need a '.new' here on the constructor?
Jennifer Messerly 2017/06/12 22:19:34 we don't because it's a JavaScript class not a Dar
+ _AsyncStarStreamController, gen, T, args);

Powered by Google App Engine
This is Rietveld 408576698