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

Side by Side Diff: sdk/lib/_internal/js_runtime/lib/async_patch.dart

Issue 1677063003: More tests for async* functions (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add another test. Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Patch file for the dart:async library. 5 // Patch file for the dart:async library.
6 6
7 import 'dart:_js_helper' show 7 import 'dart:_js_helper' show
8 patch, 8 patch,
9 ExceptionAndStackTrace, 9 ExceptionAndStackTrace,
10 Primitives, 10 Primitives,
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 /// [IterationMarker] to the stream. If the stream subscription has been 248 /// [IterationMarker] to the stream. If the stream subscription has been
249 /// paused, return early. Otherwise schedule the helper function to be 249 /// paused, return early. Otherwise schedule the helper function to be
250 /// executed again. 250 /// executed again.
251 /// 251 ///
252 /// If [object] is a yield-star [IterationMarker], starts listening to the 252 /// If [object] is a yield-star [IterationMarker], starts listening to the
253 /// yielded stream, and adds all events and errors to our own controller (taking 253 /// yielded stream, and adds all events and errors to our own controller (taking
254 /// care if the subscription has been paused or canceled) - when the sub-stream 254 /// care if the subscription has been paused or canceled) - when the sub-stream
255 /// is done, schedules [asyncBody] again. 255 /// is done, schedules [asyncBody] again.
256 /// 256 ///
257 /// If the async* function wants to do an await it calls this function with 257 /// If the async* function wants to do an await it calls this function with
258 /// [object] not and [IterationMarker]. 258 /// [object] not an [IterationMarker].
259 /// 259 ///
260 /// If [object] is not a [Future], it is wrapped in a `Future.value`. 260 /// If [object] is not a [Future], it is wrapped in a `Future.value`.
261 /// The [asyncBody] is called on completion of the future (see [asyncHelper]. 261 /// The [asyncBody] is called on completion of the future (see [asyncHelper].
262 /// If the stream has been canceled in the meantime, the body is
263 /// called with [async_error_codes.STREAM_WAS_CANCELED] once the future
264 /// completes.
Lasse Reichstein Nielsen 2016/02/08 17:44:24 That's not correct. Canceled async* functions must
Lasse Reichstein Nielsen 2016/02/08 20:54:44 (or maybe I'm not understanding exactly what happe
floitsch 2016/02/09 16:56:34 My fault. I reverted these changes.
262 void _asyncStarHelper(dynamic object, 265 void _asyncStarHelper(dynamic object,
263 dynamic /* int | _WrappedAsyncBody */ bodyFunctionOrErrorCode, 266 dynamic /* int | _WrappedAsyncBody */ bodyFunctionOrErrorCode,
264 _AsyncStarStreamController controller) { 267 _AsyncStarStreamController controller) {
265 if (identical(bodyFunctionOrErrorCode, async_error_codes.SUCCESS)) { 268 if (identical(bodyFunctionOrErrorCode, async_error_codes.SUCCESS)) {
266 // This happens on return from the async* function. 269 // This happens on return from the async* function.
267 if (controller.isCanceled) { 270 if (controller.isCanceled) {
268 controller.cancelationCompleter.complete(); 271 controller.cancelationCompleter.complete();
269 } else { 272 } else {
270 controller.close(); 273 controller.close();
271 } 274 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // after insertion of each element. 318 // after insertion of each element.
316 int errorCode = controller.isCanceled 319 int errorCode = controller.isCanceled
317 ? async_error_codes.STREAM_WAS_CANCELED 320 ? async_error_codes.STREAM_WAS_CANCELED
318 : async_error_codes.SUCCESS; 321 : async_error_codes.SUCCESS;
319 bodyFunctionOrErrorCode(errorCode, null); 322 bodyFunctionOrErrorCode(errorCode, null);
320 }); 323 });
321 return; 324 return;
322 } 325 }
323 } 326 }
324 327
325 _awaitOnObject(object, bodyFunctionOrErrorCode); 328 // Executes the body-function, unless the subscription was canceled while
329 // waiting for the object.
330 void runBodyOrCancel(int errorCode, dynamic result) {
331 if (controller.isCanceled) {
332 bodyFunctionOrErrorCode(async_error_codes.STREAM_WAS_CANCELED, null);
333 return;
334 }
335 bodyFunctionOrErrorCode(errorCode, result);
336 }
337
338 _awaitOnObject(object, runBodyOrCancel);
326 } 339 }
327 340
328 Stream _streamOfController(_AsyncStarStreamController controller) { 341 Stream _streamOfController(_AsyncStarStreamController controller) {
329 return controller.stream; 342 return controller.stream;
330 } 343 }
331 344
332 /// A wrapper around a [StreamController] that keeps track of the state of 345 /// A wrapper around a [StreamController] that keeps track of the state of
333 /// the execution of an async* function. 346 /// the execution of an async* function.
334 /// It can be in 1 of 3 states: 347 /// It can be in 1 of 3 states:
335 /// 348 ///
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 529
517 Iterator get iterator => new _SyncStarIterator(JS('', '#()', _outerHelper)); 530 Iterator get iterator => new _SyncStarIterator(JS('', '#()', _outerHelper));
518 } 531 }
519 532
520 @patch 533 @patch
521 void _rethrow(Object error, StackTrace stackTrace) { 534 void _rethrow(Object error, StackTrace stackTrace) {
522 error = wrapException(error); 535 error = wrapException(error);
523 JS("void", "#.stack = #", error, stackTrace.toString()); 536 JS("void", "#.stack = #", error, stackTrace.toString());
524 JS("void", "throw #", error); 537 JS("void", "throw #", error);
525 } 538 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698