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

Side by Side Diff: sdk/lib/async/zone.dart

Issue 2529393002: Make core libraries use generic method syntax. (Closed)
Patch Set: Update status files. Created 3 years, 11 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
« no previous file with comments | « sdk/lib/async/timer.dart ('k') | sdk/lib/collection/iterable.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.async; 5 part of dart.async;
6 6
7 typedef R ZoneCallback<R>(); 7 typedef R ZoneCallback<R>();
8 typedef R ZoneUnaryCallback<R, T>(T arg); 8 typedef R ZoneUnaryCallback<R, T>(T arg);
9 typedef R ZoneBinaryCallback<R, T1, T2>(T1 arg1, T2 arg2); 9 typedef R ZoneBinaryCallback<R, T1, T2>(T1 arg1, T2 arg2);
10 10
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 * 209 *
210 * While zones have access to their parent zone (through [Zone.parent]) it is 210 * While zones have access to their parent zone (through [Zone.parent]) it is
211 * recommended to call the methods on the provided parent delegate for two 211 * recommended to call the methods on the provided parent delegate for two
212 * reasons: 212 * reasons:
213 * 1. the delegate methods take an additional `zone` argument which is the 213 * 1. the delegate methods take an additional `zone` argument which is the
214 * zone the action has been initiated in. 214 * zone the action has been initiated in.
215 * 2. delegate calls are more efficient, since the implementation knows how 215 * 2. delegate calls are more efficient, since the implementation knows how
216 * to skip zones that would just delegate to their parents. 216 * to skip zones that would just delegate to their parents.
217 */ 217 */
218 abstract class ZoneDelegate { 218 abstract class ZoneDelegate {
219 /*=R*/ handleUncaughtError/*<R>*/( 219 R handleUncaughtError<R>(
220 Zone zone, error, StackTrace stackTrace); 220 Zone zone, error, StackTrace stackTrace);
221 /*=R*/ run/*<R>*/(Zone zone, /*=R*/ f()); 221 R run<R>(Zone zone, R f());
222 /*=R*/ runUnary/*<R, T>*/(Zone zone, /*=R*/ f(/*=T*/ arg), /*=T*/ arg); 222 R runUnary<R, T>(Zone zone, R f(T arg), T arg);
223 /*=R*/ runBinary/*<R, T1, T2>*/(Zone zone, 223 R runBinary<R, T1, T2>(Zone zone,
224 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2); 224 R f(T1 arg1, T2 arg2), T1 arg1, T2 arg2);
225 ZoneCallback/*<R>*/ registerCallback/*<R>*/(Zone zone, /*=R*/ f()); 225 ZoneCallback<R> registerCallback<R>(Zone zone, R f());
226 ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( 226 ZoneUnaryCallback<R, T> registerUnaryCallback<R, T>(
227 Zone zone, /*=R*/ f(/*=T*/ arg)); 227 Zone zone, R f(T arg));
228 ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( 228 ZoneBinaryCallback<R, T1, T2> registerBinaryCallback<R, T1, T2>(
229 Zone zone, /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)); 229 Zone zone, R f(T1 arg1, T2 arg2));
230 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace); 230 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace);
231 void scheduleMicrotask(Zone zone, void f()); 231 void scheduleMicrotask(Zone zone, void f());
232 Timer createTimer(Zone zone, Duration duration, void f()); 232 Timer createTimer(Zone zone, Duration duration, void f());
233 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); 233 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer));
234 void print(Zone zone, String line); 234 void print(Zone zone, String line);
235 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); 235 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues);
236 } 236 }
237 237
238 /** 238 /**
239 * A zone represents an environment that remains stable across asynchronous 239 * A zone represents an environment that remains stable across asynchronous
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 * chains, but for which no child registered an error handler. 315 * chains, but for which no child registered an error handler.
316 * Most asynchronous classes, like [Future] or [Stream] push errors to their 316 * Most asynchronous classes, like [Future] or [Stream] push errors to their
317 * listeners. Errors are propagated this way until either a listener handles 317 * listeners. Errors are propagated this way until either a listener handles
318 * the error (for example with [Future.catchError]), or no listener is 318 * the error (for example with [Future.catchError]), or no listener is
319 * available anymore. In the latter case, futures and streams invoke the 319 * available anymore. In the latter case, futures and streams invoke the
320 * zone's [handleUncaughtError]. 320 * zone's [handleUncaughtError].
321 * 321 *
322 * By default, when handled by the root zone, uncaught asynchronous errors are 322 * By default, when handled by the root zone, uncaught asynchronous errors are
323 * treated like uncaught synchronous exceptions. 323 * treated like uncaught synchronous exceptions.
324 */ 324 */
325 /*=R*/ handleUncaughtError/*<R>*/(error, StackTrace stackTrace); 325 R handleUncaughtError<R>(error, StackTrace stackTrace);
326 326
327 /** 327 /**
328 * The parent zone of the this zone. 328 * The parent zone of the this zone.
329 * 329 *
330 * Is `null` if `this` is the [ROOT] zone. 330 * Is `null` if `this` is the [ROOT] zone.
331 * 331 *
332 * Zones are created by [fork] on an existing zone, or by [runZoned] which 332 * Zones are created by [fork] on an existing zone, or by [runZoned] which
333 * forks the [current] zone. The new zone's parent zone is the zone it was 333 * forks the [current] zone. The new zone's parent zone is the zone it was
334 * forked from. 334 * forked from.
335 */ 335 */
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 * By default (as implemented in the [ROOT] zone), runs [action] 416 * By default (as implemented in the [ROOT] zone), runs [action]
417 * with [current] set to this zone. 417 * with [current] set to this zone.
418 * 418 *
419 * If [action] throws, the synchronous exception is not caught by the zone's 419 * If [action] throws, the synchronous exception is not caught by the zone's
420 * error handler. Use [runGuarded] to achieve that. 420 * error handler. Use [runGuarded] to achieve that.
421 * 421 *
422 * Since the root zone is the only zone that can modify the value of 422 * Since the root zone is the only zone that can modify the value of
423 * [current], custom zones intercepting run should always delegate to their 423 * [current], custom zones intercepting run should always delegate to their
424 * parent zone. They may take actions before and after the call. 424 * parent zone. They may take actions before and after the call.
425 */ 425 */
426 /*=R*/ run/*<R>*/(/*=R*/ action()); 426 R run<R>(R action());
427 427
428 /** 428 /**
429 * Executes the given [action] with [argument] in this zone. 429 * Executes the given [action] with [argument] in this zone.
430 * 430 *
431 * As [run] except that [action] is called with one [argument] instead of 431 * As [run] except that [action] is called with one [argument] instead of
432 * none. 432 * none.
433 */ 433 */
434 /*=R*/ runUnary/*<R, T>*/(/*=R*/ action(/*=T*/ argument), /*=T*/ argument); 434 R runUnary<R, T>(R action(T argument), T argument);
435 435
436 /** 436 /**
437 * Executes the given [action] with [argument1] and [argument2] in this 437 * Executes the given [action] with [argument1] and [argument2] in this
438 * zone. 438 * zone.
439 * 439 *
440 * As [run] except that [action] is called with two arguments instead of none. 440 * As [run] except that [action] is called with two arguments instead of none.
441 */ 441 */
442 /*=R*/ runBinary/*<R, T1, T2>*/( 442 R runBinary<R, T1, T2>(
443 /*=R*/ action(/*=T1*/ argument1, /*=T2*/ argument2), /*=T1*/ argument1, 443 R action(T1 argument1, T2 argument2), T1 argument1,
444 /*=T2*/ argument2); 444 T2 argument2);
445 445
446 /** 446 /**
447 * Executes the given [action] in this zone and catches synchronous 447 * Executes the given [action] in this zone and catches synchronous
448 * errors. 448 * errors.
449 * 449 *
450 * This function is equivalent to: 450 * This function is equivalent to:
451 * ``` 451 * ```
452 * try { 452 * try {
453 * return this.run(action); 453 * return this.run(action);
454 * } catch (e, s) { 454 * } catch (e, s) {
455 * return this.handleUncaughtError(e, s); 455 * return this.handleUncaughtError(e, s);
456 * } 456 * }
457 * ``` 457 * ```
458 * 458 *
459 * See [run]. 459 * See [run].
460 */ 460 */
461 /*=R*/ runGuarded/*<R>*/(/*=R*/ action()); 461 R runGuarded<R>(R action());
462 462
463 /** 463 /**
464 * Executes the given [action] with [argument] in this zone and 464 * Executes the given [action] with [argument] in this zone and
465 * catches synchronous errors. 465 * catches synchronous errors.
466 * 466 *
467 * See [runGuarded]. 467 * See [runGuarded].
468 */ 468 */
469 /*=R*/ runUnaryGuarded/*<R, T>*/(/*=R*/ action(/*=T*/ argument), 469 R runUnaryGuarded<R, T>(R action(T argument),
470 /*=T*/ argument); 470 T argument);
471 471
472 /** 472 /**
473 * Executes the given [action] with [argument1] and [argument2] in this 473 * Executes the given [action] with [argument1] and [argument2] in this
474 * zone and catches synchronous errors. 474 * zone and catches synchronous errors.
475 * 475 *
476 * See [runGuarded]. 476 * See [runGuarded].
477 */ 477 */
478 /*=R*/ runBinaryGuarded/*<R, T1, T2>*/( 478 R runBinaryGuarded<R, T1, T2>(
479 /*=R*/ action(/*=T1*/ argument1, /*=T2*/ argument2), /*=T1*/ argument1, 479 R action(T1 argument1, T2 argument2), T1 argument1,
480 /*=T2*/ argument2); 480 T2 argument2);
481 481
482 /** 482 /**
483 * Registers the given callback in this zone. 483 * Registers the given callback in this zone.
484 * 484 *
485 * When implementing an asynchronous primitive that uses callbacks, the 485 * When implementing an asynchronous primitive that uses callbacks, the
486 * callback must be registered using [registerCallback] at the point where the 486 * callback must be registered using [registerCallback] at the point where the
487 * user provides the callback. This allows zones to record other information 487 * user provides the callback. This allows zones to record other information
488 * that they need at the same time, perhaps even wrapping the callback, so 488 * that they need at the same time, perhaps even wrapping the callback, so
489 * that the callback is prepared when it is later run in the same zones 489 * that the callback is prepared when it is later run in the same zones
490 * (using [run]). For example, a zone may decide 490 * (using [run]). For example, a zone may decide
491 * to store the stack trace (at the time of the registration) with the 491 * to store the stack trace (at the time of the registration) with the
492 * callback. 492 * callback.
493 * 493 *
494 * Returns the callback that should be used in place of the provided 494 * Returns the callback that should be used in place of the provided
495 * [callback]. Frequently zones simply return the original callback. 495 * [callback]. Frequently zones simply return the original callback.
496 * 496 *
497 * Custom zones may intercept this operation. The default implementation in 497 * Custom zones may intercept this operation. The default implementation in
498 * [Zone.ROOT] returns the original callback unchanged. 498 * [Zone.ROOT] returns the original callback unchanged.
499 */ 499 */
500 ZoneCallback/*<R>*/ registerCallback/*<R>*/(/*=R*/ callback()); 500 ZoneCallback<R> registerCallback<R>(R callback());
501 501
502 /** 502 /**
503 * Registers the given callback in this zone. 503 * Registers the given callback in this zone.
504 * 504 *
505 * Similar to [registerCallback] but with a unary callback. 505 * Similar to [registerCallback] but with a unary callback.
506 */ 506 */
507 ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( 507 ZoneUnaryCallback<R, T> registerUnaryCallback<R, T>(
508 /*=R*/ callback(/*=T*/ arg)); 508 R callback(T arg));
509 509
510 /** 510 /**
511 * Registers the given callback in this zone. 511 * Registers the given callback in this zone.
512 * 512 *
513 * Similar to [registerCallback] but with a unary callback. 513 * Similar to [registerCallback] but with a unary callback.
514 */ 514 */
515 ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( 515 ZoneBinaryCallback<R, T1, T2> registerBinaryCallback<R, T1, T2>(
516 /*=R*/ callback(/*=T1*/ arg1, /*=T2*/ arg2)); 516 R callback(T1 arg1, T2 arg2));
517 517
518 /** 518 /**
519 * Equivalent to: 519 * Equivalent to:
520 * 520 *
521 * ZoneCallback registered = this.registerCallback(action); 521 * ZoneCallback registered = this.registerCallback(action);
522 * if (runGuarded) return () => this.runGuarded(registered); 522 * if (runGuarded) return () => this.runGuarded(registered);
523 * return () => this.run(registered); 523 * return () => this.run(registered);
524 * 524 *
525 */ 525 */
526 ZoneCallback/*<R>*/ bindCallback/*<R>*/( 526 ZoneCallback<R> bindCallback<R>(
527 /*=R*/ action(), { bool runGuarded: true }); 527 R action(), { bool runGuarded: true });
528 528
529 /** 529 /**
530 * Equivalent to: 530 * Equivalent to:
531 * 531 *
532 * ZoneCallback registered = this.registerUnaryCallback(action); 532 * ZoneCallback registered = this.registerUnaryCallback(action);
533 * if (runGuarded) return (arg) => this.runUnaryGuarded(registered, arg); 533 * if (runGuarded) return (arg) => this.runUnaryGuarded(registered, arg);
534 * return (arg) => thin.runUnary(registered, arg); 534 * return (arg) => thin.runUnary(registered, arg);
535 */ 535 */
536 ZoneUnaryCallback/*<R, T>*/ bindUnaryCallback/*<R, T>*/( 536 ZoneUnaryCallback<R, T> bindUnaryCallback<R, T>(
537 /*=R*/ action(/*=T*/ argument), { bool runGuarded: true }); 537 R action(T argument), { bool runGuarded: true });
538 538
539 /** 539 /**
540 * Equivalent to: 540 * Equivalent to:
541 * 541 *
542 * ZoneCallback registered = registerBinaryCallback(action); 542 * ZoneCallback registered = registerBinaryCallback(action);
543 * if (runGuarded) { 543 * if (runGuarded) {
544 * return (arg1, arg2) => this.runBinaryGuarded(registered, arg); 544 * return (arg1, arg2) => this.runBinaryGuarded(registered, arg);
545 * } 545 * }
546 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2); 546 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2);
547 */ 547 */
548 ZoneBinaryCallback/*<R, T1, T2>*/ bindBinaryCallback/*<R, T1, T2>*/( 548 ZoneBinaryCallback<R, T1, T2> bindBinaryCallback<R, T1, T2>(
549 /*=R*/ action(/*=T1*/ argument1, /*=T2*/ argument2), 549 R action(T1 argument1, T2 argument2),
550 { bool runGuarded: true }); 550 { bool runGuarded: true });
551 551
552 /** 552 /**
553 * Intercepts errors when added programatically to a `Future` or `Stream`. 553 * Intercepts errors when added programatically to a `Future` or `Stream`.
554 * 554 *
555 * When calling [Completer.completeError], [Stream.addError], 555 * When calling [Completer.completeError], [Stream.addError],
556 * or some [Future] constructors, the current zone is allowed to intercept 556 * or some [Future] constructors, the current zone is allowed to intercept
557 * and replace the error. 557 * and replace the error.
558 * 558 *
559 * Future constructors invoke this function when the error is received 559 * Future constructors invoke this function when the error is received
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 ZoneDelegate _parentDelegate(_Zone zone) { 665 ZoneDelegate _parentDelegate(_Zone zone) {
666 if (zone.parent == null) return null; 666 if (zone.parent == null) return null;
667 return zone.parent._delegate; 667 return zone.parent._delegate;
668 } 668 }
669 669
670 class _ZoneDelegate implements ZoneDelegate { 670 class _ZoneDelegate implements ZoneDelegate {
671 final _Zone _delegationTarget; 671 final _Zone _delegationTarget;
672 672
673 _ZoneDelegate(this._delegationTarget); 673 _ZoneDelegate(this._delegationTarget);
674 674
675 /*=R*/ handleUncaughtError/*<R>*/( 675 R handleUncaughtError<R>(
676 Zone zone, error, StackTrace stackTrace) { 676 Zone zone, error, StackTrace stackTrace) {
677 var implementation = _delegationTarget._handleUncaughtError; 677 var implementation = _delegationTarget._handleUncaughtError;
678 _Zone implZone = implementation.zone; 678 _Zone implZone = implementation.zone;
679 HandleUncaughtErrorHandler handler = implementation.function; 679 HandleUncaughtErrorHandler handler = implementation.function;
680 // TODO(floitsch): make this a generic method call on '<R>' once it's 680 // TODO(floitsch): make this a generic method call on '<R>' once it's
681 // supported. Remove the unnecessary cast. 681 // supported. Remove the unnecessary cast.
682 return handler( 682 return handler(
683 implZone, _parentDelegate(implZone), zone, error, stackTrace) 683 implZone, _parentDelegate(implZone), zone, error, stackTrace)
684 as Object/*=R*/; 684 as Object/*=R*/;
685 } 685 }
686 686
687 /*=R*/ run/*<R>*/(Zone zone, /*=R*/ f()) { 687 R run<R>(Zone zone, R f()) {
688 var implementation = _delegationTarget._run; 688 var implementation = _delegationTarget._run;
689 _Zone implZone = implementation.zone; 689 _Zone implZone = implementation.zone;
690 RunHandler handler = implementation.function; 690 RunHandler handler = implementation.function;
691 // TODO(floitsch): make this a generic method call on '<R>' once it's 691 // TODO(floitsch): make this a generic method call on '<R>' once it's
692 // supported. Remove the unnecessary cast. 692 // supported. Remove the unnecessary cast.
693 return handler(implZone, _parentDelegate(implZone), zone, f) 693 return handler(implZone, _parentDelegate(implZone), zone, f)
694 as Object/*=R*/; 694 as Object/*=R*/;
695 } 695 }
696 696
697 /*=R*/ runUnary/*<R, T>*/(Zone zone, /*=R*/ f(/*=T*/ arg), /*=T*/ arg) { 697 R runUnary<R, T>(Zone zone, R f(T arg), T arg) {
698 var implementation = _delegationTarget._runUnary; 698 var implementation = _delegationTarget._runUnary;
699 _Zone implZone = implementation.zone; 699 _Zone implZone = implementation.zone;
700 RunUnaryHandler handler = implementation.function; 700 RunUnaryHandler handler = implementation.function;
701 // TODO(floitsch): make this a generic method call on '<R, T>' once it's 701 // TODO(floitsch): make this a generic method call on '<R, T>' once it's
702 // supported. Remove the unnecessary cast. 702 // supported. Remove the unnecessary cast.
703 return handler( 703 return handler(
704 implZone, _parentDelegate(implZone), zone, f, arg) as Object/*=R*/; 704 implZone, _parentDelegate(implZone), zone, f, arg) as Object/*=R*/;
705 } 705 }
706 706
707 /*=R*/ runBinary/*<R, T1, T2>*/(Zone zone, 707 R runBinary<R, T1, T2>(Zone zone,
708 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { 708 R f(T1 arg1, T2 arg2), T1 arg1, T2 arg2) {
709 var implementation = _delegationTarget._runBinary; 709 var implementation = _delegationTarget._runBinary;
710 _Zone implZone = implementation.zone; 710 _Zone implZone = implementation.zone;
711 RunBinaryHandler handler = implementation.function; 711 RunBinaryHandler handler = implementation.function;
712 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once 712 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once
713 // it's supported. Remove the unnecessary cast. 713 // it's supported. Remove the unnecessary cast.
714 return handler( 714 return handler(
715 implZone, _parentDelegate(implZone), zone, f, arg1, arg2) 715 implZone, _parentDelegate(implZone), zone, f, arg1, arg2)
716 as Object/*=R*/; 716 as Object/*=R*/;
717 } 717 }
718 718
719 ZoneCallback/*<R>*/ registerCallback/*<R>*/(Zone zone, /*=R*/ f()) { 719 ZoneCallback<R> registerCallback<R>(Zone zone, R f()) {
720 var implementation = _delegationTarget._registerCallback; 720 var implementation = _delegationTarget._registerCallback;
721 _Zone implZone = implementation.zone; 721 _Zone implZone = implementation.zone;
722 RegisterCallbackHandler handler = implementation.function; 722 RegisterCallbackHandler handler = implementation.function;
723 // TODO(floitsch): make this a generic method call on '<R>' once it's 723 // TODO(floitsch): make this a generic method call on '<R>' once it's
724 // supported. Remove the unnecessary cast. 724 // supported. Remove the unnecessary cast.
725 return handler(implZone, _parentDelegate(implZone), zone, f) 725 return handler(implZone, _parentDelegate(implZone), zone, f)
726 as Object/*=ZoneCallback<R>*/; 726 as Object/*=ZoneCallback<R>*/;
727 } 727 }
728 728
729 ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( 729 ZoneUnaryCallback<R, T> registerUnaryCallback<R, T>(
730 Zone zone, /*=R*/ f(/*=T*/ arg)) { 730 Zone zone, R f(T arg)) {
731 var implementation = _delegationTarget._registerUnaryCallback; 731 var implementation = _delegationTarget._registerUnaryCallback;
732 _Zone implZone = implementation.zone; 732 _Zone implZone = implementation.zone;
733 RegisterUnaryCallbackHandler handler = implementation.function; 733 RegisterUnaryCallbackHandler handler = implementation.function;
734 // TODO(floitsch): make this a generic method call on '<R, T>' once it's 734 // TODO(floitsch): make this a generic method call on '<R, T>' once it's
735 // supported. Remove the unnecessary cast. 735 // supported. Remove the unnecessary cast.
736 return handler(implZone, _parentDelegate(implZone), zone, f) 736 return handler(implZone, _parentDelegate(implZone), zone, f)
737 as Object/*=ZoneUnaryCallback<R, T>*/; 737 as Object/*=ZoneUnaryCallback<R, T>*/;
738 } 738 }
739 739
740 ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( 740 ZoneBinaryCallback<R, T1, T2> registerBinaryCallback<R, T1, T2>(
741 Zone zone, /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)) { 741 Zone zone, R f(T1 arg1, T2 arg2)) {
742 var implementation = _delegationTarget._registerBinaryCallback; 742 var implementation = _delegationTarget._registerBinaryCallback;
743 _Zone implZone = implementation.zone; 743 _Zone implZone = implementation.zone;
744 RegisterBinaryCallbackHandler handler = implementation.function; 744 RegisterBinaryCallbackHandler handler = implementation.function;
745 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once 745 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once
746 // it's supported. Remove the unnecessary cast. 746 // it's supported. Remove the unnecessary cast.
747 return handler(implZone, _parentDelegate(implZone), zone, f) 747 return handler(implZone, _parentDelegate(implZone), zone, f)
748 as Object/*=ZoneBinaryCallback<R, T1, T2>*/; 748 as Object/*=ZoneBinaryCallback<R, T1, T2>*/;
749 } 749 }
750 750
751 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace) { 751 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 } 912 }
913 913
914 /** 914 /**
915 * The closest error-handling zone. 915 * The closest error-handling zone.
916 * 916 *
917 * Returns `this` if `this` has an error-handler. Otherwise returns the 917 * Returns `this` if `this` has an error-handler. Otherwise returns the
918 * parent's error-zone. 918 * parent's error-zone.
919 */ 919 */
920 Zone get errorZone => _handleUncaughtError.zone; 920 Zone get errorZone => _handleUncaughtError.zone;
921 921
922 /*=R*/ runGuarded/*<R>*/(/*=R*/ f()) { 922 R runGuarded<R>(R f()) {
923 try { 923 try {
924 return run(f); 924 return run(f);
925 } catch (e, s) { 925 } catch (e, s) {
926 return handleUncaughtError(e, s); 926 return handleUncaughtError(e, s);
927 } 927 }
928 } 928 }
929 929
930 /*=R*/ runUnaryGuarded/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { 930 R runUnaryGuarded<R, T>(R f(T arg), T arg) {
931 try { 931 try {
932 return runUnary(f, arg); 932 return runUnary(f, arg);
933 } catch (e, s) { 933 } catch (e, s) {
934 return handleUncaughtError(e, s); 934 return handleUncaughtError(e, s);
935 } 935 }
936 } 936 }
937 937
938 /*=R*/ runBinaryGuarded/*<R, T1, T2>*/( 938 R runBinaryGuarded<R, T1, T2>(
939 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { 939 R f(T1 arg1, T2 arg2), T1 arg1, T2 arg2) {
940 try { 940 try {
941 return runBinary(f, arg1, arg2); 941 return runBinary(f, arg1, arg2);
942 } catch (e, s) { 942 } catch (e, s) {
943 return handleUncaughtError(e, s); 943 return handleUncaughtError(e, s);
944 } 944 }
945 } 945 }
946 946
947 ZoneCallback/*<R>*/ bindCallback/*<R>*/( 947 ZoneCallback<R> bindCallback<R>(
948 /*=R*/ f(), { bool runGuarded: true }) { 948 R f(), { bool runGuarded: true }) {
949 var registered = registerCallback(f); 949 var registered = registerCallback(f);
950 if (runGuarded) { 950 if (runGuarded) {
951 return () => this.runGuarded(registered); 951 return () => this.runGuarded(registered);
952 } else { 952 } else {
953 return () => this.run(registered); 953 return () => this.run(registered);
954 } 954 }
955 } 955 }
956 956
957 ZoneUnaryCallback/*<R, T>*/ bindUnaryCallback/*<R, T>*/( 957 ZoneUnaryCallback<R, T> bindUnaryCallback<R, T>(
958 /*=R*/ f(/*=T*/ arg), { bool runGuarded: true }) { 958 R f(T arg), { bool runGuarded: true }) {
959 var registered = registerUnaryCallback(f); 959 var registered = registerUnaryCallback(f);
960 if (runGuarded) { 960 if (runGuarded) {
961 return (arg) => this.runUnaryGuarded(registered, arg); 961 return (arg) => this.runUnaryGuarded(registered, arg);
962 } else { 962 } else {
963 return (arg) => this.runUnary(registered, arg); 963 return (arg) => this.runUnary(registered, arg);
964 } 964 }
965 } 965 }
966 966
967 ZoneBinaryCallback/*<R, T1, T2>*/ bindBinaryCallback/*<R, T1, T2>*/( 967 ZoneBinaryCallback<R, T1, T2> bindBinaryCallback<R, T1, T2>(
968 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), { bool runGuarded: true }) { 968 R f(T1 arg1, T2 arg2), { bool runGuarded: true }) {
969 var registered = registerBinaryCallback(f); 969 var registered = registerBinaryCallback(f);
970 if (runGuarded) { 970 if (runGuarded) {
971 return (arg1, arg2) => this.runBinaryGuarded(registered, arg1, arg2); 971 return (arg1, arg2) => this.runBinaryGuarded(registered, arg1, arg2);
972 } else { 972 } else {
973 return (arg1, arg2) => this.runBinary(registered, arg1, arg2); 973 return (arg1, arg2) => this.runBinary(registered, arg1, arg2);
974 } 974 }
975 } 975 }
976 976
977 operator [](Object key) { 977 operator [](Object key) {
978 var result = _map[key]; 978 var result = _map[key];
979 if (result != null || _map.containsKey(key)) return result; 979 if (result != null || _map.containsKey(key)) return result;
980 // If we are not the root zone, look up in the parent zone. 980 // If we are not the root zone, look up in the parent zone.
981 if (parent != null) { 981 if (parent != null) {
982 // We do not optimize for repeatedly looking up a key which isn't 982 // We do not optimize for repeatedly looking up a key which isn't
983 // there. That would require storing the key and keeping it alive. 983 // there. That would require storing the key and keeping it alive.
984 // Copying the key/value from the parent does not keep any new values 984 // Copying the key/value from the parent does not keep any new values
985 // alive. 985 // alive.
986 var value = parent[key]; 986 var value = parent[key];
987 if (value != null) { 987 if (value != null) {
988 _map[key] = value; 988 _map[key] = value;
989 } 989 }
990 return value; 990 return value;
991 } 991 }
992 assert(this == _ROOT_ZONE); 992 assert(this == _ROOT_ZONE);
993 return null; 993 return null;
994 } 994 }
995 995
996 // Methods that can be customized by the zone specification. 996 // Methods that can be customized by the zone specification.
997 997
998 /*=R*/ handleUncaughtError/*<R>*/(error, StackTrace stackTrace) { 998 R handleUncaughtError<R>(error, StackTrace stackTrace) {
999 var implementation = this._handleUncaughtError; 999 var implementation = this._handleUncaughtError;
1000 assert(implementation != null); 1000 assert(implementation != null);
1001 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 1001 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
1002 HandleUncaughtErrorHandler handler = implementation.function; 1002 HandleUncaughtErrorHandler handler = implementation.function;
1003 // TODO(floitsch): make this a generic method call on '<R>' once it's 1003 // TODO(floitsch): make this a generic method call on '<R>' once it's
1004 // supported. Remove the unnecessary cast. 1004 // supported. Remove the unnecessary cast.
1005 return handler( 1005 return handler(
1006 implementation.zone, parentDelegate, this, error, stackTrace) 1006 implementation.zone, parentDelegate, this, error, stackTrace)
1007 as Object/*=R*/; 1007 as Object/*=R*/;
1008 } 1008 }
1009 1009
1010 Zone fork({ZoneSpecification specification, Map zoneValues}) { 1010 Zone fork({ZoneSpecification specification, Map zoneValues}) {
1011 var implementation = this._fork; 1011 var implementation = this._fork;
1012 assert(implementation != null); 1012 assert(implementation != null);
1013 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 1013 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
1014 ForkHandler handler = implementation.function; 1014 ForkHandler handler = implementation.function;
1015 return handler(implementation.zone, parentDelegate, this, 1015 return handler(implementation.zone, parentDelegate, this,
1016 specification, zoneValues); 1016 specification, zoneValues);
1017 } 1017 }
1018 1018
1019 /*=R*/ run/*<R>*/(/*=R*/ f()) { 1019 R run<R>(R f()) {
1020 var implementation = this._run; 1020 var implementation = this._run;
1021 assert(implementation != null); 1021 assert(implementation != null);
1022 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 1022 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
1023 RunHandler handler = implementation.function; 1023 RunHandler handler = implementation.function;
1024 // TODO(floitsch): make this a generic method call on '<R>' once it's 1024 // TODO(floitsch): make this a generic method call on '<R>' once it's
1025 // supported. Remove the unnecessary cast. 1025 // supported. Remove the unnecessary cast.
1026 return handler(implementation.zone, parentDelegate, this, f) 1026 return handler(implementation.zone, parentDelegate, this, f)
1027 as Object/*=R*/; 1027 as Object/*=R*/;
1028 } 1028 }
1029 1029
1030 /*=R*/ runUnary/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { 1030 R runUnary<R, T>(R f(T arg), T arg) {
1031 var implementation = this._runUnary; 1031 var implementation = this._runUnary;
1032 assert(implementation != null); 1032 assert(implementation != null);
1033 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 1033 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
1034 RunUnaryHandler handler = implementation.function; 1034 RunUnaryHandler handler = implementation.function;
1035 // TODO(floitsch): make this a generic method call on '<R, T>' once it's 1035 // TODO(floitsch): make this a generic method call on '<R, T>' once it's
1036 // supported. Remove the unnecessary cast. 1036 // supported. Remove the unnecessary cast.
1037 return handler(implementation.zone, parentDelegate, this, f, arg) 1037 return handler(implementation.zone, parentDelegate, this, f, arg)
1038 as Object/*=R*/; 1038 as Object/*=R*/;
1039 } 1039 }
1040 1040
1041 /*=R*/ runBinary/*<R, T1, T2>*/( 1041 R runBinary<R, T1, T2>(
1042 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { 1042 R f(T1 arg1, T2 arg2), T1 arg1, T2 arg2) {
1043 var implementation = this._runBinary; 1043 var implementation = this._runBinary;
1044 assert(implementation != null); 1044 assert(implementation != null);
1045 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 1045 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
1046 RunBinaryHandler handler = implementation.function; 1046 RunBinaryHandler handler = implementation.function;
1047 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once 1047 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once
1048 // it's supported. Remove the unnecessary cast. 1048 // it's supported. Remove the unnecessary cast.
1049 return handler( 1049 return handler(
1050 implementation.zone, parentDelegate, this, f, arg1, arg2) 1050 implementation.zone, parentDelegate, this, f, arg1, arg2)
1051 as Object/*=R*/; 1051 as Object/*=R*/;
1052 } 1052 }
1053 1053
1054 ZoneCallback/*<R>*/ registerCallback/*<R>*/(/*=R*/ callback()) { 1054 ZoneCallback<R> registerCallback<R>(R callback()) {
1055 var implementation = this._registerCallback; 1055 var implementation = this._registerCallback;
1056 assert(implementation != null); 1056 assert(implementation != null);
1057 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 1057 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
1058 RegisterCallbackHandler handler = implementation.function; 1058 RegisterCallbackHandler handler = implementation.function;
1059 // TODO(floitsch): make this a generic method call on '<R>' once it's 1059 // TODO(floitsch): make this a generic method call on '<R>' once it's
1060 // supported. Remove the unnecessary cast. 1060 // supported. Remove the unnecessary cast.
1061 return handler(implementation.zone, parentDelegate, this, callback) 1061 return handler(implementation.zone, parentDelegate, this, callback)
1062 as Object/*=ZoneCallback<R>*/; 1062 as Object/*=ZoneCallback<R>*/;
1063 } 1063 }
1064 1064
1065 ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( 1065 ZoneUnaryCallback<R, T> registerUnaryCallback<R, T>(
1066 /*=R*/ callback(/*=T*/ arg)) { 1066 R callback(T arg)) {
1067 var implementation = this._registerUnaryCallback; 1067 var implementation = this._registerUnaryCallback;
1068 assert(implementation != null); 1068 assert(implementation != null);
1069 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 1069 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
1070 RegisterUnaryCallbackHandler handler = implementation.function; 1070 RegisterUnaryCallbackHandler handler = implementation.function;
1071 // TODO(floitsch): make this a generic method call on '<R, T>' once it's 1071 // TODO(floitsch): make this a generic method call on '<R, T>' once it's
1072 // supported. Remove the unnecessary cast. 1072 // supported. Remove the unnecessary cast.
1073 return handler(implementation.zone, parentDelegate, this, callback) 1073 return handler(implementation.zone, parentDelegate, this, callback)
1074 as Object/*=ZoneUnaryCallback<R, T>*/; 1074 as Object/*=ZoneUnaryCallback<R, T>*/;
1075 } 1075 }
1076 1076
1077 ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( 1077 ZoneBinaryCallback<R, T1, T2> registerBinaryCallback<R, T1, T2>(
1078 /*=R*/ callback(/*=T1*/ arg1, /*=T2*/ arg2)) { 1078 R callback(T1 arg1, T2 arg2)) {
1079 var implementation = this._registerBinaryCallback; 1079 var implementation = this._registerBinaryCallback;
1080 assert(implementation != null); 1080 assert(implementation != null);
1081 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 1081 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
1082 RegisterBinaryCallbackHandler handler = implementation.function; 1082 RegisterBinaryCallbackHandler handler = implementation.function;
1083 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once 1083 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once
1084 // it's supported. Remove the unnecessary cast. 1084 // it's supported. Remove the unnecessary cast.
1085 return handler(implementation.zone, parentDelegate, this, callback) 1085 return handler(implementation.zone, parentDelegate, this, callback)
1086 as Object/*=ZoneBinaryCallback<R, T1, T2>*/; 1086 as Object/*=ZoneBinaryCallback<R, T1, T2>*/;
1087 } 1087 }
1088 1088
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 1124
1125 void print(String line) { 1125 void print(String line) {
1126 var implementation = this._print; 1126 var implementation = this._print;
1127 assert(implementation != null); 1127 assert(implementation != null);
1128 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); 1128 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
1129 PrintHandler handler = implementation.function; 1129 PrintHandler handler = implementation.function;
1130 return handler(implementation.zone, parentDelegate, this, line); 1130 return handler(implementation.zone, parentDelegate, this, line);
1131 } 1131 }
1132 } 1132 }
1133 1133
1134 /*=R*/ _rootHandleUncaughtError/*<R>*/( 1134 R _rootHandleUncaughtError<R>(
1135 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { 1135 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) {
1136 _schedulePriorityAsyncCallback(() { 1136 _schedulePriorityAsyncCallback(() {
1137 if (error == null) error = new NullThrownError(); 1137 if (error == null) error = new NullThrownError();
1138 if (stackTrace == null) throw error; 1138 if (stackTrace == null) throw error;
1139 _rethrow(error, stackTrace); 1139 _rethrow(error, stackTrace);
1140 }); 1140 });
1141 } 1141 }
1142 1142
1143 external void _rethrow(Object error, StackTrace stackTrace); 1143 external void _rethrow(Object error, StackTrace stackTrace);
1144 1144
1145 /*=R*/ _rootRun/*<R>*/(Zone self, ZoneDelegate parent, Zone zone, /*=R*/ f()) { 1145 R _rootRun<R>(Zone self, ZoneDelegate parent, Zone zone, R f()) {
1146 if (Zone._current == zone) return f(); 1146 if (Zone._current == zone) return f();
1147 1147
1148 Zone old = Zone._enter(zone); 1148 Zone old = Zone._enter(zone);
1149 try { 1149 try {
1150 return f(); 1150 return f();
1151 } finally { 1151 } finally {
1152 Zone._leave(old); 1152 Zone._leave(old);
1153 } 1153 }
1154 } 1154 }
1155 1155
1156 /*=R*/ _rootRunUnary/*<R, T>*/(Zone self, ZoneDelegate parent, Zone zone, 1156 R _rootRunUnary<R, T>(Zone self, ZoneDelegate parent, Zone zone,
1157 /*=R*/ f(/*=T*/ arg), /*=T*/ arg) { 1157 R f(T arg), T arg) {
1158 if (Zone._current == zone) return f(arg); 1158 if (Zone._current == zone) return f(arg);
1159 1159
1160 Zone old = Zone._enter(zone); 1160 Zone old = Zone._enter(zone);
1161 try { 1161 try {
1162 return f(arg); 1162 return f(arg);
1163 } finally { 1163 } finally {
1164 Zone._leave(old); 1164 Zone._leave(old);
1165 } 1165 }
1166 } 1166 }
1167 1167
1168 /*=R*/ _rootRunBinary/*<R, T1, T2>*/(Zone self, ZoneDelegate parent, Zone zone, 1168 R _rootRunBinary<R, T1, T2>(Zone self, ZoneDelegate parent, Zone zone,
1169 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { 1169 R f(T1 arg1, T2 arg2), T1 arg1, T2 arg2) {
1170 if (Zone._current == zone) return f(arg1, arg2); 1170 if (Zone._current == zone) return f(arg1, arg2);
1171 1171
1172 Zone old = Zone._enter(zone); 1172 Zone old = Zone._enter(zone);
1173 try { 1173 try {
1174 return f(arg1, arg2); 1174 return f(arg1, arg2);
1175 } finally { 1175 } finally {
1176 Zone._leave(old); 1176 Zone._leave(old);
1177 } 1177 }
1178 } 1178 }
1179 1179
1180 ZoneCallback/*<R>*/ _rootRegisterCallback/*<R>*/( 1180 ZoneCallback<R> _rootRegisterCallback<R>(
1181 Zone self, ZoneDelegate parent, Zone zone, /*=R*/ f()) { 1181 Zone self, ZoneDelegate parent, Zone zone, R f()) {
1182 return f; 1182 return f;
1183 } 1183 }
1184 1184
1185 ZoneUnaryCallback/*<R, T>*/ _rootRegisterUnaryCallback/*<R, T>*/( 1185 ZoneUnaryCallback<R, T> _rootRegisterUnaryCallback<R, T>(
1186 Zone self, ZoneDelegate parent, Zone zone, /*=R*/ f(/*=T*/ arg)) { 1186 Zone self, ZoneDelegate parent, Zone zone, R f(T arg)) {
1187 return f; 1187 return f;
1188 } 1188 }
1189 1189
1190 ZoneBinaryCallback/*<R, T1, T2>*/ _rootRegisterBinaryCallback/*<R, T1, T2>*/( 1190 ZoneBinaryCallback<R, T1, T2> _rootRegisterBinaryCallback<R, T1, T2>(
1191 Zone self, ZoneDelegate parent, Zone zone, 1191 Zone self, ZoneDelegate parent, Zone zone,
1192 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)) { 1192 R f(T1 arg1, T2 arg2)) {
1193 return f; 1193 return f;
1194 } 1194 }
1195 1195
1196 AsyncError _rootErrorCallback(Zone self, ZoneDelegate parent, Zone zone, 1196 AsyncError _rootErrorCallback(Zone self, ZoneDelegate parent, Zone zone,
1197 Object error, StackTrace stackTrace) => null; 1197 Object error, StackTrace stackTrace) => null;
1198 1198
1199 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { 1199 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) {
1200 if (!identical(_ROOT_ZONE, zone)) { 1200 if (!identical(_ROOT_ZONE, zone)) {
1201 bool hasErrorHandler = !_ROOT_ZONE.inSameErrorZone(zone); 1201 bool hasErrorHandler = !_ROOT_ZONE.inSameErrorZone(zone);
1202 f = zone.bindCallback(f, runGuarded: hasErrorHandler); 1202 f = zone.bindCallback(f, runGuarded: hasErrorHandler);
1203 // Use root zone as event zone if the function is already bound. 1203 // Use root zone as event zone if the function is already bound.
1204 zone = _ROOT_ZONE; 1204 zone = _ROOT_ZONE;
1205 } 1205 }
1206 _scheduleAsyncCallback(f); 1206 _scheduleAsyncCallback(f);
1207 } 1207 }
1208 1208
1209 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, 1209 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone,
1210 Duration duration, void callback()) { 1210 Duration duration, void callback()) {
1211 if (!identical(_ROOT_ZONE, zone)) { 1211 if (!identical(_ROOT_ZONE, zone)) {
1212 callback = zone.bindCallback(callback); 1212 callback = zone.bindCallback(callback);
1213 } 1213 }
1214 return Timer._createTimer(duration, callback); 1214 return Timer._createTimer(duration, callback);
1215 } 1215 }
1216 1216
1217 Timer _rootCreatePeriodicTimer( 1217 Timer _rootCreatePeriodicTimer(
1218 Zone self, ZoneDelegate parent, Zone zone, 1218 Zone self, ZoneDelegate parent, Zone zone,
1219 Duration duration, void callback(Timer timer)) { 1219 Duration duration, void callback(Timer timer)) {
1220 if (!identical(_ROOT_ZONE, zone)) { 1220 if (!identical(_ROOT_ZONE, zone)) {
1221 // TODO(floitsch): the return type should be 'void'. 1221 // TODO(floitsch): the return type should be 'void'.
1222 callback = zone.bindUnaryCallback/*<dynamic, Timer>*/(callback); 1222 callback = zone.bindUnaryCallback<dynamic, Timer>(callback);
1223 } 1223 }
1224 return Timer._createPeriodicTimer(duration, callback); 1224 return Timer._createPeriodicTimer(duration, callback);
1225 } 1225 }
1226 1226
1227 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) { 1227 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) {
1228 printToConsole(line); 1228 printToConsole(line);
1229 } 1229 }
1230 1230
1231 void _printToZone(String line) { 1231 void _printToZone(String line) {
1232 Zone.current.print(line); 1232 Zone.current.print(line);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 /** 1314 /**
1315 * The closest error-handling zone. 1315 * The closest error-handling zone.
1316 * 1316 *
1317 * Returns `this` if `this` has an error-handler. Otherwise returns the 1317 * Returns `this` if `this` has an error-handler. Otherwise returns the
1318 * parent's error-zone. 1318 * parent's error-zone.
1319 */ 1319 */
1320 Zone get errorZone => this; 1320 Zone get errorZone => this;
1321 1321
1322 // Zone interface. 1322 // Zone interface.
1323 1323
1324 /*=R*/ runGuarded/*<R>*/(/*=R*/ f()) { 1324 R runGuarded<R>(R f()) {
1325 try { 1325 try {
1326 if (identical(_ROOT_ZONE, Zone._current)) { 1326 if (identical(_ROOT_ZONE, Zone._current)) {
1327 return f(); 1327 return f();
1328 } 1328 }
1329 return _rootRun/*<R>*/(null, null, this, f); 1329 return _rootRun<R>(null, null, this, f);
1330 } catch (e, s) { 1330 } catch (e, s) {
1331 return handleUncaughtError/*<R>*/(e, s); 1331 return handleUncaughtError<R>(e, s);
1332 } 1332 }
1333 } 1333 }
1334 1334
1335 /*=R*/ runUnaryGuarded/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { 1335 R runUnaryGuarded<R, T>(R f(T arg), T arg) {
1336 try { 1336 try {
1337 if (identical(_ROOT_ZONE, Zone._current)) { 1337 if (identical(_ROOT_ZONE, Zone._current)) {
1338 return f(arg); 1338 return f(arg);
1339 } 1339 }
1340 return _rootRunUnary/*<R, T>*/(null, null, this, f, arg); 1340 return _rootRunUnary<R, T>(null, null, this, f, arg);
1341 } catch (e, s) { 1341 } catch (e, s) {
1342 return handleUncaughtError/*<R>*/(e, s); 1342 return handleUncaughtError<R>(e, s);
1343 } 1343 }
1344 } 1344 }
1345 1345
1346 /*=R*/ runBinaryGuarded/*<R, T1, T2>*/( 1346 R runBinaryGuarded<R, T1, T2>(
1347 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { 1347 R f(T1 arg1, T2 arg2), T1 arg1, T2 arg2) {
1348 try { 1348 try {
1349 if (identical(_ROOT_ZONE, Zone._current)) { 1349 if (identical(_ROOT_ZONE, Zone._current)) {
1350 return f(arg1, arg2); 1350 return f(arg1, arg2);
1351 } 1351 }
1352 return _rootRunBinary/*<R, T1, T2>*/(null, null, this, f, arg1, arg2); 1352 return _rootRunBinary<R, T1, T2>(null, null, this, f, arg1, arg2);
1353 } catch (e, s) { 1353 } catch (e, s) {
1354 return handleUncaughtError/*<R>*/(e, s); 1354 return handleUncaughtError<R>(e, s);
1355 } 1355 }
1356 } 1356 }
1357 1357
1358 ZoneCallback/*<R>*/ bindCallback/*<R>*/( 1358 ZoneCallback<R> bindCallback<R>(
1359 /*=R*/ f(), { bool runGuarded: true }) { 1359 R f(), { bool runGuarded: true }) {
1360 if (runGuarded) { 1360 if (runGuarded) {
1361 return () => this.runGuarded/*<R>*/(f); 1361 return () => this.runGuarded<R>(f);
1362 } else { 1362 } else {
1363 return () => this.run/*<R>*/(f); 1363 return () => this.run<R>(f);
1364 } 1364 }
1365 } 1365 }
1366 1366
1367 ZoneUnaryCallback/*<R, T>*/ bindUnaryCallback/*<R, T>*/( 1367 ZoneUnaryCallback<R, T> bindUnaryCallback<R, T>(
1368 /*=R*/ f(/*=T*/ arg), { bool runGuarded: true }) { 1368 R f(T arg), { bool runGuarded: true }) {
1369 if (runGuarded) { 1369 if (runGuarded) {
1370 return (arg) => this.runUnaryGuarded/*<R, T>*/(f, arg); 1370 return (arg) => this.runUnaryGuarded<R, T>(f, arg);
1371 } else { 1371 } else {
1372 return (arg) => this.runUnary/*<R, T>*/(f, arg); 1372 return (arg) => this.runUnary<R, T>(f, arg);
1373 } 1373 }
1374 } 1374 }
1375 1375
1376 ZoneBinaryCallback/*<R, T1, T2>*/ bindBinaryCallback/*<R, T1, T2>*/( 1376 ZoneBinaryCallback<R, T1, T2> bindBinaryCallback<R, T1, T2>(
1377 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), { bool runGuarded: true }) { 1377 R f(T1 arg1, T2 arg2), { bool runGuarded: true }) {
1378 if (runGuarded) { 1378 if (runGuarded) {
1379 return (arg1, arg2) => 1379 return (arg1, arg2) =>
1380 this.runBinaryGuarded/*<R, T1, T2>*/(f, arg1, arg2); 1380 this.runBinaryGuarded<R, T1, T2>(f, arg1, arg2);
1381 } else { 1381 } else {
1382 return (arg1, arg2) => this.runBinary/*<R, T1, T2>*/(f, arg1, arg2); 1382 return (arg1, arg2) => this.runBinary<R, T1, T2>(f, arg1, arg2);
1383 } 1383 }
1384 } 1384 }
1385 1385
1386 operator [](Object key) => null; 1386 operator [](Object key) => null;
1387 1387
1388 // Methods that can be customized by the zone specification. 1388 // Methods that can be customized by the zone specification.
1389 1389
1390 /*=R*/ handleUncaughtError/*<R>*/(error, StackTrace stackTrace) { 1390 R handleUncaughtError<R>(error, StackTrace stackTrace) {
1391 return _rootHandleUncaughtError(null, null, this, error, stackTrace); 1391 return _rootHandleUncaughtError(null, null, this, error, stackTrace);
1392 } 1392 }
1393 1393
1394 Zone fork({ZoneSpecification specification, Map zoneValues}) { 1394 Zone fork({ZoneSpecification specification, Map zoneValues}) {
1395 return _rootFork(null, null, this, specification, zoneValues); 1395 return _rootFork(null, null, this, specification, zoneValues);
1396 } 1396 }
1397 1397
1398 /*=R*/ run/*<R>*/(/*=R*/ f()) { 1398 R run<R>(R f()) {
1399 if (identical(Zone._current, _ROOT_ZONE)) return f(); 1399 if (identical(Zone._current, _ROOT_ZONE)) return f();
1400 return _rootRun(null, null, this, f); 1400 return _rootRun(null, null, this, f);
1401 } 1401 }
1402 1402
1403 /*=R*/ runUnary/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { 1403 R runUnary<R, T>(R f(T arg), T arg) {
1404 if (identical(Zone._current, _ROOT_ZONE)) return f(arg); 1404 if (identical(Zone._current, _ROOT_ZONE)) return f(arg);
1405 return _rootRunUnary(null, null, this, f, arg); 1405 return _rootRunUnary(null, null, this, f, arg);
1406 } 1406 }
1407 1407
1408 /*=R*/ runBinary/*<R, T1, T2>*/( 1408 R runBinary<R, T1, T2>(
1409 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { 1409 R f(T1 arg1, T2 arg2), T1 arg1, T2 arg2) {
1410 if (identical(Zone._current, _ROOT_ZONE)) return f(arg1, arg2); 1410 if (identical(Zone._current, _ROOT_ZONE)) return f(arg1, arg2);
1411 return _rootRunBinary(null, null, this, f, arg1, arg2); 1411 return _rootRunBinary(null, null, this, f, arg1, arg2);
1412 } 1412 }
1413 1413
1414 ZoneCallback/*<R>*/ registerCallback/*<R>*/(/*=R*/ f()) => f; 1414 ZoneCallback<R> registerCallback<R>(R f()) => f;
1415 1415
1416 ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( 1416 ZoneUnaryCallback<R, T> registerUnaryCallback<R, T>(
1417 /*=R*/ f(/*=T*/ arg)) => f; 1417 R f(T arg)) => f;
1418 1418
1419 ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( 1419 ZoneBinaryCallback<R, T1, T2> registerBinaryCallback<R, T1, T2>(
1420 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)) => f; 1420 R f(T1 arg1, T2 arg2)) => f;
1421 1421
1422 AsyncError errorCallback(Object error, StackTrace stackTrace) => null; 1422 AsyncError errorCallback(Object error, StackTrace stackTrace) => null;
1423 1423
1424 void scheduleMicrotask(void f()) { 1424 void scheduleMicrotask(void f()) {
1425 _rootScheduleMicrotask(null, null, this, f); 1425 _rootScheduleMicrotask(null, null, this, f);
1426 } 1426 }
1427 1427
1428 Timer createTimer(Duration duration, void f()) { 1428 Timer createTimer(Duration duration, void f()) {
1429 return Timer._createTimer(duration, f); 1429 return Timer._createTimer(duration, f);
1430 } 1430 }
(...skipping 27 matching lines...) Expand all
1458 * future = future.catchError((e) { print("Never reached!"); }); 1458 * future = future.catchError((e) { print("Never reached!"); });
1459 * }, onError: (e) { print("unused error handler"); }); 1459 * }, onError: (e) { print("unused error handler"); });
1460 * }, onError: (e) { print("catches error of first error-zone."); }); 1460 * }, onError: (e) { print("catches error of first error-zone."); });
1461 * 1461 *
1462 * Example: 1462 * Example:
1463 * 1463 *
1464 * runZoned(() { 1464 * runZoned(() {
1465 * new Future(() { throw "asynchronous error"; }); 1465 * new Future(() { throw "asynchronous error"; });
1466 * }, onError: print); // Will print "asynchronous error". 1466 * }, onError: print); // Will print "asynchronous error".
1467 */ 1467 */
1468 /*=R*/ runZoned/*<R>*/(/*=R*/ body(), 1468 R runZoned<R>(R body(),
1469 { Map zoneValues, 1469 { Map zoneValues,
1470 ZoneSpecification zoneSpecification, 1470 ZoneSpecification zoneSpecification,
1471 Function onError }) { 1471 Function onError }) {
1472 HandleUncaughtErrorHandler errorHandler; 1472 HandleUncaughtErrorHandler errorHandler;
1473 if (onError != null) { 1473 if (onError != null) {
1474 errorHandler = (Zone self, ZoneDelegate parent, Zone zone, 1474 errorHandler = (Zone self, ZoneDelegate parent, Zone zone,
1475 error, StackTrace stackTrace) { 1475 error, StackTrace stackTrace) {
1476 try { 1476 try {
1477 if (onError is ZoneBinaryCallback<dynamic/*=R*/, dynamic, StackTrace>) { 1477 if (onError is ZoneBinaryCallback<R, dynamic, StackTrace>) {
1478 return self.parent.runBinary(onError, error, stackTrace); 1478 return self.parent.runBinary(onError, error, stackTrace);
1479 } 1479 }
1480 return self.parent.runUnary(onError, error); 1480 return self.parent.runUnary(onError, error);
1481 } catch(e, s) { 1481 } catch(e, s) {
1482 if (identical(e, error)) { 1482 if (identical(e, error)) {
1483 return parent.handleUncaughtError(zone, error, stackTrace); 1483 return parent.handleUncaughtError(zone, error, stackTrace);
1484 } else { 1484 } else {
1485 return parent.handleUncaughtError(zone, e, s); 1485 return parent.handleUncaughtError(zone, e, s);
1486 } 1486 }
1487 } 1487 }
1488 }; 1488 };
1489 } 1489 }
1490 if (zoneSpecification == null) { 1490 if (zoneSpecification == null) {
1491 zoneSpecification = 1491 zoneSpecification =
1492 new ZoneSpecification(handleUncaughtError: errorHandler); 1492 new ZoneSpecification(handleUncaughtError: errorHandler);
1493 } else if (errorHandler != null) { 1493 } else if (errorHandler != null) {
1494 zoneSpecification = 1494 zoneSpecification =
1495 new ZoneSpecification.from(zoneSpecification, 1495 new ZoneSpecification.from(zoneSpecification,
1496 handleUncaughtError: errorHandler); 1496 handleUncaughtError: errorHandler);
1497 } 1497 }
1498 Zone zone = Zone.current.fork(specification: zoneSpecification, 1498 Zone zone = Zone.current.fork(specification: zoneSpecification,
1499 zoneValues: zoneValues); 1499 zoneValues: zoneValues);
1500 if (onError != null) { 1500 if (onError != null) {
1501 return zone.runGuarded(body); 1501 return zone.runGuarded(body);
1502 } else { 1502 } else {
1503 return zone.run(body); 1503 return zone.run(body);
1504 } 1504 }
1505 } 1505 }
OLDNEW
« no previous file with comments | « sdk/lib/async/timer.dart ('k') | sdk/lib/collection/iterable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698