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

Unified Diff: tool/input_sdk/private/js_helper.dart

Issue 1243503007: fixes #221, initial sync*, async, async* implementation (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 5 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 | « tool/input_sdk/private/isolate_helper.dart ('k') | tool/sdk_expected_errors.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tool/input_sdk/private/js_helper.dart
diff --git a/tool/input_sdk/private/js_helper.dart b/tool/input_sdk/private/js_helper.dart
index 20be8e50285e03dec2bab8c57a9c238311b70bde..2abc46a0ed8e18be07fa3d1d156247b25548a8fd 100644
--- a/tool/input_sdk/private/js_helper.dart
+++ b/tool/input_sdk/private/js_helper.dart
@@ -763,3 +763,35 @@ int random64() {
String jsonEncodeNative(String string) {
return JS("String", "JSON.stringify(#)", string);
}
+
+
+// TODO(jmesserly): this adapter is to work around:
+// https://github.com/dart-lang/dev_compiler/issues/247
+class SyncIterator<E> implements Iterator<E> {
+ final dynamic _jsIterator;
+ E _current;
+
+ SyncIterator(this._jsIterator);
+
+ E get current => _current;
+
+ bool moveNext() {
+ final ret = JS('', '#.next()', _jsIterator);
+ _current = JS('', '#.value', ret);
+ return JS('bool', '!#.done', ret);
+ }
+}
+
+class SyncIterable<E> extends IterableBase<E> {
+ final dynamic _generator;
+ final dynamic _args;
+
+ SyncIterable(this._generator, this._args);
+
+ // TODO(jmesserly): this should be [Symbol.iterator]() method. Unfortunately
+ // we have no way of telling the compiler yet, so it will generate an extra
+ // layer of indirection that wraps the SyncIterator.
+ _jsIterator() => JS('', '#(...#)', _generator, _args);
+
+ Iterator<E> get iterator => new SyncIterator<E>(_jsIterator());
+}
« no previous file with comments | « tool/input_sdk/private/isolate_helper.dart ('k') | tool/sdk_expected_errors.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698