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

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

Issue 331993005: Rewrite Zone implementation to avoid recursively looking up stuff in the parent chain. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/async/timer.dart ('k') | tests/lib/async/run_zoned9_test.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 dynamic ZoneCallback(); 7 typedef dynamic ZoneCallback();
8 typedef dynamic ZoneUnaryCallback(arg); 8 typedef dynamic ZoneUnaryCallback(arg);
9 typedef dynamic ZoneBinaryCallback(arg1, arg2); 9 typedef dynamic ZoneBinaryCallback(arg1, arg2);
10 10
(...skipping 16 matching lines...) Expand all
27 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); 27 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f());
28 typedef Timer CreatePeriodicTimerHandler( 28 typedef Timer CreatePeriodicTimerHandler(
29 Zone self, ZoneDelegate parent, Zone zone, 29 Zone self, ZoneDelegate parent, Zone zone,
30 Duration period, void f(Timer timer)); 30 Duration period, void f(Timer timer));
31 typedef void PrintHandler( 31 typedef void PrintHandler(
32 Zone self, ZoneDelegate parent, Zone zone, String line); 32 Zone self, ZoneDelegate parent, Zone zone, String line);
33 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, 33 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone,
34 ZoneSpecification specification, 34 ZoneSpecification specification,
35 Map zoneValues); 35 Map zoneValues);
36 36
37 class _ZoneFunction {
38 final _Zone zone;
39 final Function function;
40 const _ZoneFunction(this.zone, this.function);
41 }
42
37 /** 43 /**
38 * This class provides the specification for a forked zone. 44 * This class provides the specification for a forked zone.
39 * 45 *
40 * When forking a new zone (see [Zone.fork]) one can override the default 46 * When forking a new zone (see [Zone.fork]) one can override the default
41 * behavior of the zone by providing callbacks. These callbacks must be 47 * behavior of the zone by providing callbacks. These callbacks must be
42 * given in an instance of this class. 48 * given in an instance of this class.
43 * 49 *
44 * Handlers have the same signature as the same-named methods on [Zone] but 50 * Handlers have the same signature as the same-named methods on [Zone] but
45 * receive three additional arguments: 51 * receive three additional arguments:
46 * 52 *
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 * This class wraps zones for delegation. 200 * This class wraps zones for delegation.
195 * 201 *
196 * When forwarding to parent zones one can't just invoke the parent zone's 202 * When forwarding to parent zones one can't just invoke the parent zone's
197 * exposed functions (like [Zone.run]), but one needs to provide more 203 * exposed functions (like [Zone.run]), but one needs to provide more
198 * information (like the zone the `run` was initiated). Zone callbacks thus 204 * information (like the zone the `run` was initiated). Zone callbacks thus
199 * receive more information including this [ZoneDelegate] class. When delegating 205 * receive more information including this [ZoneDelegate] class. When delegating
200 * to the parent zone one should go through the given instance instead of 206 * to the parent zone one should go through the given instance instead of
201 * directly invoking the parent zone. 207 * directly invoking the parent zone.
202 */ 208 */
203 abstract class ZoneDelegate { 209 abstract class ZoneDelegate {
204 /// The [Zone] this class wraps.
205 Zone get _zone;
206
207 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); 210 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace);
208 dynamic run(Zone zone, f()); 211 dynamic run(Zone zone, f());
209 dynamic runUnary(Zone zone, f(arg), arg); 212 dynamic runUnary(Zone zone, f(arg), arg);
210 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); 213 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2);
211 ZoneCallback registerCallback(Zone zone, f()); 214 ZoneCallback registerCallback(Zone zone, f());
212 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); 215 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg));
213 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); 216 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2));
214 void scheduleMicrotask(Zone zone, f()); 217 void scheduleMicrotask(Zone zone, f());
215 Timer createTimer(Zone zone, Duration duration, void f()); 218 Timer createTimer(Zone zone, Duration duration, void f());
216 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); 219 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer));
(...skipping 22 matching lines...) Expand all
239 dynamic handleUncaughtError(error, StackTrace stackTrace); 242 dynamic handleUncaughtError(error, StackTrace stackTrace);
240 243
241 /** 244 /**
242 * Returns the parent zone. 245 * Returns the parent zone.
243 * 246 *
244 * Returns `null` if `this` is the [ROOT] zone. 247 * Returns `null` if `this` is the [ROOT] zone.
245 */ 248 */
246 Zone get parent; 249 Zone get parent;
247 250
248 /** 251 /**
252 * The error zone is the one that is responsible for dealing with uncaught
253 * errors.
254 * Errors are not allowed to cross between zones with different error-zones.
255 *
256 * This is the closest parent or ancestor zone of this zone that has a custom
257 * [handleUncaughtError] method.
258 */
259 Zone get errorZone;
260
261 /**
249 * Returns true if `this` and [otherZone] are in the same error zone. 262 * Returns true if `this` and [otherZone] are in the same error zone.
250 * 263 *
251 * Two zones are in the same error zone if they share the same 264 * Two zones are in the same error zone if they inherit their
252 * [handleUncaughtError] callback. 265 * [handleUncaughtError] callback from the same [errorZone].
253 */ 266 */
254 bool inSameErrorZone(Zone otherZone); 267 bool inSameErrorZone(Zone otherZone);
255 268
256 /** 269 /**
257 * Creates a new zone as a child of `this`. 270 * Creates a new zone as a child of `this`.
258 * 271 *
259 * The new zone will have behavior like the current zone, except where 272 * The new zone will have behavior like the current zone, except where
260 * overridden by functions in [specification]. 273 * overridden by functions in [specification].
261 * 274 *
262 * The new zone will have the same stored values (accessed through 275 * The new zone will have the same stored values (accessed through
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 * Creates a periodic Timer where the callback is executed in this zone. 393 * Creates a periodic Timer where the callback is executed in this zone.
381 */ 394 */
382 Timer createPeriodicTimer(Duration period, void callback(Timer timer)); 395 Timer createPeriodicTimer(Duration period, void callback(Timer timer));
383 396
384 /** 397 /**
385 * Prints the given [line]. 398 * Prints the given [line].
386 */ 399 */
387 void print(String line); 400 void print(String line);
388 401
389 /** 402 /**
390 * The error zone is the one that is responsible for dealing with uncaught
391 * errors. Errors are not allowed to cross zones with different error-zones.
392 */
393 Zone get _errorZone;
394
395 /**
396 * Call to enter the Zone. 403 * Call to enter the Zone.
397 * 404 *
398 * The previous current zone is returned. 405 * The previous current zone is returned.
399 */ 406 */
400 static Zone _enter(Zone zone) { 407 static Zone _enter(Zone zone) {
401 assert(zone != null); 408 assert(zone != null);
402 assert(!identical(zone, _current)); 409 assert(!identical(zone, _current));
403 Zone previous = _current; 410 Zone previous = _current;
404 _current = zone; 411 _current = zone;
405 return previous; 412 return previous;
(...skipping 16 matching lines...) Expand all
422 * parent zone. If the [key] is not found returns `null`. 429 * parent zone. If the [key] is not found returns `null`.
423 * 430 *
424 * Any object can be used as key, as long as it has compatible `operator ==` 431 * Any object can be used as key, as long as it has compatible `operator ==`
425 * and `hashCode` implementations. 432 * and `hashCode` implementations.
426 * By controlling access to the key, a zone can grant or deny access to the 433 * By controlling access to the key, a zone can grant or deny access to the
427 * zone value. 434 * zone value.
428 */ 435 */
429 operator [](Object key); 436 operator [](Object key);
430 } 437 }
431 438
439 ZoneDelegate _parentDelegate(_Zone zone) {
440 if (zone.parent == null) return null;
441 return zone.parent._delegate;
442 }
443
432 class _ZoneDelegate implements ZoneDelegate { 444 class _ZoneDelegate implements ZoneDelegate {
433 final _BaseZone _degelationTarget; 445 final _Zone _delegationTarget;
434 446
435 Zone get _zone => _degelationTarget; 447 _ZoneDelegate(this._delegationTarget);
436
437 const _ZoneDelegate(this._degelationTarget);
438 448
439 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace) { 449 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace) {
440 _BaseZone parent = _degelationTarget; 450 _ZoneFunction implementation = _delegationTarget._handleUncaughtError;
441 while (parent._specification.handleUncaughtError == null) { 451 _Zone implZone = implementation.zone;
442 parent = parent.parent; 452 return (implementation.function)(
443 } 453 implZone, _parentDelegate(implZone), zone, error, stackTrace);
444 return (parent._specification.handleUncaughtError)(
445 parent, new _ZoneDelegate(parent.parent), zone, error, stackTrace);
446 } 454 }
447 455
448 dynamic run(Zone zone, f()) { 456 dynamic run(Zone zone, f()) {
449 _BaseZone parent = _degelationTarget; 457 _ZoneFunction implementation = _delegationTarget._run;
450 while (parent._specification.run == null) { 458 _Zone implZone = implementation.zone;
451 parent = parent.parent; 459 return (implementation.function)(
452 } 460 implZone, _parentDelegate(implZone), zone, f);
453 return (parent._specification.run)(
454 parent, new _ZoneDelegate(parent.parent), zone, f);
455 } 461 }
456 462
457 dynamic runUnary(Zone zone, f(arg), arg) { 463 dynamic runUnary(Zone zone, f(arg), arg) {
458 _BaseZone parent = _degelationTarget; 464 _ZoneFunction implementation = _delegationTarget._runUnary;
459 while (parent._specification.runUnary == null) { 465 _Zone implZone = implementation.zone;
460 parent = parent.parent; 466 return (implementation.function)(
461 } 467 implZone, _parentDelegate(implZone), zone, f, arg);
462 return (parent._specification.runUnary)(
463 parent, new _ZoneDelegate(parent.parent), zone, f, arg);
464 } 468 }
465 469
466 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2) { 470 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2) {
467 _BaseZone parent = _degelationTarget; 471 _ZoneFunction implementation = _delegationTarget._runBinary;
468 while (parent._specification.runBinary == null) { 472 _Zone implZone = implementation.zone;
469 parent = parent.parent; 473 return (implementation.function)(
470 } 474 implZone, _parentDelegate(implZone), zone, f, arg1, arg2);
471 return (parent._specification.runBinary)(
472 parent, new _ZoneDelegate(parent.parent), zone, f, arg1, arg2);
473 } 475 }
474 476
475 ZoneCallback registerCallback(Zone zone, f()) { 477 ZoneCallback registerCallback(Zone zone, f()) {
476 _BaseZone parent = _degelationTarget; 478 _ZoneFunction implementation = _delegationTarget._registerCallback;
477 while (parent._specification.registerCallback == null) { 479 _Zone implZone = implementation.zone;
478 parent = parent.parent; 480 return (implementation.function)(
479 } 481 implZone, _parentDelegate(implZone), zone, f);
480 return (parent._specification.registerCallback)(
481 parent, new _ZoneDelegate(parent.parent), zone, f);
482 } 482 }
483 483
484 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)) { 484 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)) {
485 _BaseZone parent = _degelationTarget; 485 _ZoneFunction implementation = _delegationTarget._registerUnaryCallback;
486 while (parent._specification.registerUnaryCallback == null) { 486 _Zone implZone = implementation.zone;
487 parent = parent.parent; 487 return (implementation.function)(
488 } 488 implZone, _parentDelegate(implZone), zone, f);
489 return (parent._specification.registerUnaryCallback)(
490 parent, new _ZoneDelegate(parent.parent), zone, f);
491 } 489 }
492 490
493 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)) { 491 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)) {
494 _BaseZone parent = _degelationTarget; 492 _ZoneFunction implementation = _delegationTarget._registerBinaryCallback;
495 while (parent._specification.registerBinaryCallback == null) { 493 _Zone implZone = implementation.zone;
496 parent = parent.parent; 494 return (implementation.function)(
497 } 495 implZone, _parentDelegate(implZone), zone, f);
498 return (parent._specification.registerBinaryCallback)(
499 parent, new _ZoneDelegate(parent.parent), zone, f);
500 } 496 }
501 497
502 void scheduleMicrotask(Zone zone, f()) { 498 void scheduleMicrotask(Zone zone, f()) {
503 _BaseZone parent = _degelationTarget; 499 _ZoneFunction implementation = _delegationTarget._scheduleMicrotask;
504 while (parent._specification.scheduleMicrotask == null) { 500 _Zone implZone = implementation.zone;
505 parent = parent.parent; 501 (implementation.function)(
506 } 502 implZone, _parentDelegate(implZone), zone, f);
507 _ZoneDelegate grandParent = new _ZoneDelegate(parent.parent);
508 Function scheduleMicrotask = parent._specification.scheduleMicrotask;
509 scheduleMicrotask(parent, grandParent, zone, f);
510 } 503 }
511 504
512 Timer createTimer(Zone zone, Duration duration, void f()) { 505 Timer createTimer(Zone zone, Duration duration, void f()) {
513 _BaseZone parent = _degelationTarget; 506 _ZoneFunction implementation = _delegationTarget._createTimer;
514 while (parent._specification.createTimer == null) { 507 _Zone implZone = implementation.zone;
515 parent = parent.parent; 508 return (implementation.function)(
516 } 509 implZone, _parentDelegate(implZone), zone, duration, f);
517 return (parent._specification.createTimer)(
518 parent, new _ZoneDelegate(parent.parent), zone, duration, f);
519 } 510 }
520 511
521 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { 512 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) {
522 _BaseZone parent = _degelationTarget; 513 _ZoneFunction implementation = _delegationTarget._createPeriodicTimer;
523 while (parent._specification.createPeriodicTimer == null) { 514 _Zone implZone = implementation.zone;
524 parent = parent.parent; 515 return (implementation.function)(
525 } 516 implZone, _parentDelegate(implZone), zone, period, f);
526 return (parent._specification.createPeriodicTimer)(
527 parent, new _ZoneDelegate(parent.parent), zone, period, f);
528 } 517 }
529 518
530 void print(Zone zone, String line) { 519 void print(Zone zone, String line) {
531 _BaseZone parent = _degelationTarget; 520 _ZoneFunction implementation = _delegationTarget._print;
532 while (parent._specification.print == null) { 521 _Zone implZone = implementation.zone;
533 parent = parent.parent; 522 (implementation.function)(
534 } 523 implZone, _parentDelegate(implZone), zone, line);
535 (parent._specification.print)(
536 parent, new _ZoneDelegate(parent.parent), zone, line);
537 } 524 }
538 525
539 Zone fork(Zone zone, ZoneSpecification specification, 526 Zone fork(Zone zone, ZoneSpecification specification,
540 Map zoneValues) { 527 Map zoneValues) {
541 _BaseZone parent = _degelationTarget; 528 _ZoneFunction implementation = _delegationTarget._fork;
542 while (parent._specification.fork == null) { 529 _Zone implZone = implementation.zone;
543 parent = parent.parent; 530 return (implementation.function)(
544 } 531 implZone, _parentDelegate(implZone), zone, specification, zoneValues);
545 _ZoneDelegate grandParent = new _ZoneDelegate(parent.parent);
546 return (parent._specification.fork)(
547 parent, grandParent, zone, specification, zoneValues);
548 } 532 }
549 } 533 }
550 534
551 535
552 /** 536 /**
553 * Base class for Zone implementations. 537 * Base class for Zone implementations.
554 */ 538 */
555 abstract class _BaseZone implements Zone { 539 abstract class _Zone implements Zone {
556 const _BaseZone(); 540 const _Zone();
541
542 _ZoneFunction get _runUnary;
543 _ZoneFunction get _run;
544 _ZoneFunction get _runBinary;
545 _ZoneFunction get _registerCallback;
546 _ZoneFunction get _registerUnaryCallback;
547 _ZoneFunction get _registerBinaryCallback;
548 _ZoneFunction get _scheduleMicrotask;
549 _ZoneFunction get _createTimer;
550 _ZoneFunction get _createPeriodicTimer;
551 _ZoneFunction get _print;
552 _ZoneFunction get _fork;
553 _ZoneFunction get _handleUncaughtError;
554 _Zone get parent;
555 _ZoneDelegate get _delegate;
556 Map get _map;
557
558 bool inSameErrorZone(Zone otherZone) {
559 return identical(errorZone, otherZone.errorZone);
560 }
561 }
562
563 class _CustomZone extends _Zone {
564 // The actual zone and implementation of each of these
565 // inheritable zone functions.
566 _ZoneFunction _runUnary;
567 _ZoneFunction _run;
568 _ZoneFunction _runBinary;
569 _ZoneFunction _registerCallback;
570 _ZoneFunction _registerUnaryCallback;
571 _ZoneFunction _registerBinaryCallback;
572 _ZoneFunction _scheduleMicrotask;
573 _ZoneFunction _createTimer;
574 _ZoneFunction _createPeriodicTimer;
575 _ZoneFunction _print;
576 _ZoneFunction _fork;
577 _ZoneFunction _handleUncaughtError;
578
579 // A cached delegate to this zone.
580 ZoneDelegate _delegateCache;
557 581
558 /// The parent zone. 582 /// The parent zone.
559 _BaseZone get parent; 583 final _Zone parent;
560 /// The zone's handlers. 584
561 ZoneSpecification get _specification; 585 /// The zone's scoped value declaration map.
586 ///
587 /// This is always a [HashMap].
588 final Map _map;
589
590 ZoneDelegate get _delegate {
591 if (_delegateCache != null) return _delegateCache;
592 _delegateCache = new _ZoneDelegate(this);
593 return _delegateCache;
594 }
595
596 _CustomZone(this.parent, ZoneSpecification specification, this._map) {
597 // The root zone will have implementations of all parts of the
598 // specification, so it will never try to access the (null) parent.
599 // All other zones have a non-null parent.
600 _run = (specification.run != null)
601 ? new _ZoneFunction(this, specification.run)
602 : parent._run;
603 _runUnary = (specification.runUnary != null)
604 ? new _ZoneFunction(this, specification.runUnary)
605 : parent._runUnary;
606 _runBinary = (specification.runBinary != null)
607 ? new _ZoneFunction(this, specification.runBinary)
608 : parent._runBinary;
609 _registerCallback = (specification.registerCallback != null)
610 ? new _ZoneFunction(this, specification.registerCallback)
611 : parent._registerCallback;
612 _registerUnaryCallback = (specification.registerUnaryCallback != null)
613 ? new _ZoneFunction(this, specification.registerUnaryCallback)
614 : parent._registerUnaryCallback;
615 _registerBinaryCallback = (specification.registerBinaryCallback != null)
616 ? new _ZoneFunction(this, specification.registerBinaryCallback)
617 : parent._registerBinaryCallback;
618 _scheduleMicrotask = (specification.scheduleMicrotask != null)
619 ? new _ZoneFunction(this, specification.scheduleMicrotask)
620 : parent._scheduleMicrotask;
621 _createTimer = (specification.createTimer != null)
622 ? new _ZoneFunction(this, specification.createTimer)
623 : parent._createTimer;
624 _createPeriodicTimer = (specification.createPeriodicTimer != null)
625 ? new _ZoneFunction(this, specification.createPeriodicTimer)
626 : parent._createPeriodicTimer;
627 _print = (specification.print != null)
628 ? new _ZoneFunction(this, specification.print)
629 : parent._print;
630 _fork = (specification.fork != null)
631 ? new _ZoneFunction(this, specification.fork)
632 : parent._fork;
633 _handleUncaughtError = (specification.handleUncaughtError != null)
634 ? new _ZoneFunction(this, specification.handleUncaughtError)
635 : parent._handleUncaughtError;
636 }
637
562 /** 638 /**
563 * The closest error-handling zone. 639 * The closest error-handling zone.
564 * 640 *
565 * Returns `this` if `this` has an error-handler. Otherwise returns the 641 * Returns `this` if `this` has an error-handler. Otherwise returns the
566 * parent's error-zone. 642 * parent's error-zone.
567 */ 643 */
568 Zone get _errorZone; 644 Zone get errorZone => _handleUncaughtError.zone;
569
570 bool inSameErrorZone(Zone otherZone) => _errorZone == otherZone._errorZone;
571 645
572 dynamic runGuarded(f()) { 646 dynamic runGuarded(f()) {
573 try { 647 try {
574 return run(f); 648 return run(f);
575 } catch (e, s) { 649 } catch (e, s) {
576 return handleUncaughtError(e, s); 650 return handleUncaughtError(e, s);
577 } 651 }
578 } 652 }
579 653
580 dynamic runUnaryGuarded(f(arg), arg) { 654 dynamic runUnaryGuarded(f(arg), arg) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 687
614 ZoneBinaryCallback bindBinaryCallback( 688 ZoneBinaryCallback bindBinaryCallback(
615 f(arg1, arg2), { bool runGuarded: true }) { 689 f(arg1, arg2), { bool runGuarded: true }) {
616 ZoneBinaryCallback registered = registerBinaryCallback(f); 690 ZoneBinaryCallback registered = registerBinaryCallback(f);
617 if (runGuarded) { 691 if (runGuarded) {
618 return (arg1, arg2) => this.runBinaryGuarded(registered, arg1, arg2); 692 return (arg1, arg2) => this.runBinaryGuarded(registered, arg1, arg2);
619 } else { 693 } else {
620 return (arg1, arg2) => this.runBinary(registered, arg1, arg2); 694 return (arg1, arg2) => this.runBinary(registered, arg1, arg2);
621 } 695 }
622 } 696 }
623 }
624
625
626 /**
627 * Default implementation of a [Zone].
628 */
629 class _CustomizedZone extends _BaseZone {
630 final _BaseZone parent;
631 final ZoneSpecification _specification;
632
633 /// The zone's value map.
634 final Map _map;
635
636 const _CustomizedZone(this.parent, this._specification, this._map);
637
638 Zone get _errorZone {
639 if (_specification.handleUncaughtError != null) return this;
640 return parent._errorZone;
641 }
642 697
643 operator [](Object key) { 698 operator [](Object key) {
644 var result = _map[key]; 699 var result = _map[key];
645 if (result != null || _map.containsKey(key)) return result; 700 if (result != null || _map.containsKey(key)) return result;
646 // If we are not the root zone look up in the parent zone. 701 // If we are not the root zone, look up in the parent zone.
647 if (parent != null) return parent[key]; 702 if (parent != null) {
648 assert(this == Zone.ROOT); 703 // We do not optimizie for repeatedly looking up a key which isn't
floitsch 2014/06/24 12:50:30 optimize
704 // there. That would require storing the key and keeping it alive.
705 // Copying the key/value from the parent does not keep any new values
706 // alive.
707 var value = parent[key];
708 if (value != null) {
709 _map[key] = value;
710 }
711 return value;
712 }
713 assert(this == _ROOT_ZONE);
649 return null; 714 return null;
650 } 715 }
651 716
652 // Methods that can be customized by the zone specification. 717 // Methods that can be customized by the zone specification.
653 718
654 dynamic handleUncaughtError(error, StackTrace stackTrace) { 719 dynamic handleUncaughtError(error, StackTrace stackTrace) {
655 return new _ZoneDelegate(this).handleUncaughtError(this, error, stackTrace); 720 _ZoneFunction implementation = this._handleUncaughtError;
721 assert(implementation != null);
722 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
723 return (implementation.function)(
724 implementation.zone, parentDelegate, this, error, stackTrace);
656 } 725 }
657 726
658 Zone fork({ZoneSpecification specification, Map zoneValues}) { 727 Zone fork({ZoneSpecification specification, Map zoneValues}) {
659 return new _ZoneDelegate(this).fork(this, specification, zoneValues); 728 _ZoneFunction implementation = this._fork;
729 assert(implementation != null);
730 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
731 return (implementation.function)(
732 implementation.zone, parentDelegate, this,
733 specification, zoneValues);
660 } 734 }
661 735
662 dynamic run(f()) { 736 dynamic run(f()) {
663 return new _ZoneDelegate(this).run(this, f); 737 _ZoneFunction implementation = this._run;
738 assert(implementation != null);
739 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
740 return (implementation.function)(
741 implementation.zone, parentDelegate, this, f);
664 } 742 }
665 743
666 dynamic runUnary(f(arg), arg) { 744 dynamic runUnary(f(arg), arg) {
667 return new _ZoneDelegate(this).runUnary(this, f, arg); 745 _ZoneFunction implementation = this._runUnary;
746 assert(implementation != null);
747 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
748 return (implementation.function)(
749 implementation.zone, parentDelegate, this, f, arg);
668 } 750 }
669 751
670 dynamic runBinary(f(arg1, arg2), arg1, arg2) { 752 dynamic runBinary(f(arg1, arg2), arg1, arg2) {
671 return new _ZoneDelegate(this).runBinary(this, f, arg1, arg2); 753 _ZoneFunction implementation = this._runBinary;
754 assert(implementation != null);
755 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
756 return (implementation.function)(
757 implementation.zone, parentDelegate, this, f, arg1, arg2);
672 } 758 }
673 759
674 ZoneCallback registerCallback(f()) { 760 ZoneCallback registerCallback(f()) {
675 return new _ZoneDelegate(this).registerCallback(this, f); 761 _ZoneFunction implementation = this._registerCallback;
762 assert(implementation != null);
763 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
764 return (implementation.function)(
765 implementation.zone, parentDelegate, this, f);
676 } 766 }
677 767
678 ZoneUnaryCallback registerUnaryCallback(f(arg)) { 768 ZoneUnaryCallback registerUnaryCallback(f(arg)) {
679 return new _ZoneDelegate(this).registerUnaryCallback(this, f); 769 _ZoneFunction implementation = this._registerUnaryCallback;
770 assert(implementation != null);
771 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
772 return (implementation.function)(
773 implementation.zone, parentDelegate, this, f);
680 } 774 }
681 775
682 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) { 776 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) {
683 return new _ZoneDelegate(this).registerBinaryCallback(this, f); 777 _ZoneFunction implementation = this._registerBinaryCallback;
778 assert(implementation != null);
779 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
780 return (implementation.function)(
781 implementation.zone, parentDelegate, this, f);
684 } 782 }
685 783
686 void scheduleMicrotask(void f()) { 784 void scheduleMicrotask(void f()) {
687 new _ZoneDelegate(this).scheduleMicrotask(this, f); 785 _ZoneFunction implementation = this._scheduleMicrotask;
786 assert(implementation != null);
787 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
788 return (implementation.function)(
789 implementation.zone, parentDelegate, this, f);
688 } 790 }
689 791
690 Timer createTimer(Duration duration, void f()) { 792 Timer createTimer(Duration duration, void f()) {
691 return new _ZoneDelegate(this).createTimer(this, duration, f); 793 _ZoneFunction implementation = this._createTimer;
794 assert(implementation != null);
795 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
796 return (implementation.function)(
797 implementation.zone, parentDelegate, this, duration, f);
692 } 798 }
693 799
694 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { 800 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) {
695 return new _ZoneDelegate(this).createPeriodicTimer(this, duration, f); 801 _ZoneFunction implementation = this._createPeriodicTimer;
802 assert(implementation != null);
803 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
804 return (implementation.function)(
805 implementation.zone, parentDelegate, this, duration, f);
696 } 806 }
697 807
698 void print(String line) { 808 void print(String line) {
699 new _ZoneDelegate(this).print(this, line); 809 _ZoneFunction implementation = this._print;
810 assert(implementation != null);
811 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone);
812 return (implementation.function)(
813 implementation.zone, parentDelegate, this, line);
700 } 814 }
701 } 815 }
702 816
703 void _rootHandleUncaughtError( 817 void _rootHandleUncaughtError(
704 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { 818 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) {
705 self.run(() { 819 _rootScheduleMicrotask(null, null, _ROOT_ZONE, () {
706 _scheduleAsyncCallback(() { 820 print("Uncaught Error: ${error}");
707 print("Uncaught Error: ${error}"); 821 var trace = stackTrace;
708 var trace = stackTrace; 822 if (trace == null && error is Error) trace = error.stackTrace;
709 if (trace == null && error is Error) trace = error.stackTrace; 823 if (trace != null) {
710 if (trace != null) { 824 print("Stack Trace: \n$trace\n");
711 print("Stack Trace: \n$trace\n"); 825 }
712 } 826 throw error;
713 throw error;
714 });
715 }); 827 });
716 } 828 }
717 829
718 dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) { 830 dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) {
719 if (Zone._current == zone) return f(); 831 if (Zone._current == zone) return f();
720 832
721 Zone old = Zone._enter(zone); 833 Zone old = Zone._enter(zone);
722 try { 834 try {
723 return f(); 835 return f();
724 } finally { 836 } finally {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 Zone self, ZoneDelegate parent, Zone zone, f(arg)) { 870 Zone self, ZoneDelegate parent, Zone zone, f(arg)) {
759 return f; 871 return f;
760 } 872 }
761 873
762 ZoneBinaryCallback _rootRegisterBinaryCallback( 874 ZoneBinaryCallback _rootRegisterBinaryCallback(
763 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)) { 875 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)) {
764 return f; 876 return f;
765 } 877 }
766 878
767 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { 879 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) {
768 if (Zone.ROOT != zone) { 880 if (!identical(_ROOT_ZONE, zone)) {
769 f = zone.bindCallback(f); 881 f = zone.bindCallback(f);
770 } 882 }
771 _scheduleAsyncCallback(f); 883 _scheduleAsyncCallback(f);
772 } 884 }
773 885
774 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, 886 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone,
775 Duration duration, void callback()) { 887 Duration duration, void callback()) {
776 if (Zone.ROOT != zone) { 888 if (!identical(_ROOT_ZONE, zone)) {
777 callback = zone.bindCallback(callback); 889 callback = zone.bindCallback(callback);
778 } 890 }
779 return _createTimer(duration, callback); 891 return Timer._createTimer(duration, callback);
780 } 892 }
781 893
782 Timer _rootCreatePeriodicTimer( 894 Timer _rootCreatePeriodicTimer(
783 Zone self, ZoneDelegate parent, Zone zone, 895 Zone self, ZoneDelegate parent, Zone zone,
784 Duration duration, void callback(Timer timer)) { 896 Duration duration, void callback(Timer timer)) {
785 if (Zone.ROOT != zone) { 897 if (!identical(_ROOT_ZONE, zone)) {
786 callback = zone.bindUnaryCallback(callback); 898 callback = zone.bindUnaryCallback(callback);
787 } 899 }
788 return _createPeriodicTimer(duration, callback); 900 return Timer._createPeriodicTimer(duration, callback);
789 } 901 }
790 902
791 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) { 903 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) {
792 printToConsole(line); 904 printToConsole(line);
793 } 905 }
794 906
795 void _printToZone(String line) { 907 void _printToZone(String line) {
796 Zone.current.print(line); 908 Zone.current.print(line);
797 } 909 }
798 910
799 Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone, 911 Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone,
800 ZoneSpecification specification, 912 ZoneSpecification specification,
801 Map zoneValues) { 913 Map zoneValues) {
802 // TODO(floitsch): it would be nice if we could get rid of this hack. 914 // TODO(floitsch): it would be nice if we could get rid of this hack.
803 // Change the static zoneOrDirectPrint function to go through zones 915 // Change the static zoneOrDirectPrint function to go through zones
804 // from now on. 916 // from now on.
805 printToZone = _printToZone; 917 printToZone = _printToZone;
806 918
807 if (specification == null) { 919 if (specification == null) {
808 specification = const ZoneSpecification(); 920 specification = const ZoneSpecification();
809 } else if (specification is! _ZoneSpecification) { 921 } else if (specification is! _ZoneSpecification) {
810 throw new ArgumentError("ZoneSpecifications must be instantiated" 922 throw new ArgumentError("ZoneSpecifications must be instantiated"
811 " with the provided constructor."); 923 " with the provided constructor.");
812 } 924 }
813 Map copiedMap = new HashMap(); 925 Map valueMap;
814 if (zoneValues != null) { 926 if (zoneValues == null) {
815 zoneValues.forEach((key, value) { 927 if (zone is _Zone) {
816 copiedMap[key] = value; 928 valueMap = zone._map;
floitsch 2014/06/24 12:50:30 clever.
817 }); 929 } else {
930 valueMap = new HashMap();
931 }
932 } else {
933 valueMap = new HashMap.from(zoneValues);
818 } 934 }
819 return new _CustomizedZone(zone, specification, copiedMap); 935 return new _CustomZone(zone, specification, valueMap);
820 } 936 }
821 937
822 class _RootZoneSpecification implements ZoneSpecification { 938 class _RootZoneSpecification implements ZoneSpecification {
823 const _RootZoneSpecification();
824
825 HandleUncaughtErrorHandler get handleUncaughtError => 939 HandleUncaughtErrorHandler get handleUncaughtError =>
826 _rootHandleUncaughtError; 940 _rootHandleUncaughtError;
827 RunHandler get run => _rootRun; 941 RunHandler get run => _rootRun;
828 RunUnaryHandler get runUnary => _rootRunUnary; 942 RunUnaryHandler get runUnary => _rootRunUnary;
829 RunBinaryHandler get runBinary => _rootRunBinary; 943 RunBinaryHandler get runBinary => _rootRunBinary;
830 RegisterCallbackHandler get registerCallback => _rootRegisterCallback; 944 RegisterCallbackHandler get registerCallback => _rootRegisterCallback;
831 RegisterUnaryCallbackHandler get registerUnaryCallback => 945 RegisterUnaryCallbackHandler get registerUnaryCallback =>
832 _rootRegisterUnaryCallback; 946 _rootRegisterUnaryCallback;
833 RegisterBinaryCallbackHandler get registerBinaryCallback => 947 RegisterBinaryCallbackHandler get registerBinaryCallback =>
834 _rootRegisterBinaryCallback; 948 _rootRegisterBinaryCallback;
835 ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask; 949 ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask;
836 CreateTimerHandler get createTimer => _rootCreateTimer; 950 CreateTimerHandler get createTimer => _rootCreateTimer;
837 CreatePeriodicTimerHandler get createPeriodicTimer => 951 CreatePeriodicTimerHandler get createPeriodicTimer =>
838 _rootCreatePeriodicTimer; 952 _rootCreatePeriodicTimer;
839 PrintHandler get print => _rootPrint; 953 PrintHandler get print => _rootPrint;
840 ForkHandler get fork => _rootFork; 954 ForkHandler get fork => _rootFork;
841 } 955 }
842 956
843 class _RootZone extends _BaseZone { 957 class _RootZoneDelegate implements ZoneDelegate {
floitsch 2014/06/24 12:50:30 I wonder if this will cost more than it is worth.
Lasse Reichstein Nielsen 2014/06/24 14:56:06 I can try with a normal _ZoneDelegate for the root
958 const _RootZoneDelegate();
959 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace) =>
960 _rootHandleUncaughtError(null, null, zone, error, stackTrace);
961 dynamic run(Zone zone, f()) =>
962 _rootRun(null, null, zone, f);
963 dynamic runUnary(Zone zone, f(arg), arg) =>
964 _rootRunUnary(null, null, zone, f, arg);
965 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2) =>
966 _rootRunBinary(null, null, zone, f, arg1, arg2);
967 ZoneCallback registerCallback(Zone zone, f()) => f;
968 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)) => f;
969 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)) => f;
970 void scheduleMicrotask(Zone zone, f()) {
971 _rootScheduleMicrotask(null, null, zone, f);
972 }
973 Timer createTimer(Zone zone, Duration duration, void f()) {
974 return _rootCreateTimer(null, null, zone, duration, f);
975 }
976 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) {
977 return _rootCreatePeriodicTimer(null, null, zone, period, f);
978 }
979 void print(Zone zone, String line) {
980 _rootPrint(null, null, zone, line);
981 }
982 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues) {
983 return _rootFork(null, null, zone, specification, zoneValues);
984 }
985 }
986
987 class _RootZone extends _Zone {
floitsch 2014/06/24 12:50:30 Ditto: can't we use the normal _CustomZone to mini
Lasse Reichstein Nielsen 2014/06/24 14:56:06 No, I tried that and it was signficantly less effi
844 const _RootZone(); 988 const _RootZone();
845 989
846 Zone get parent => null; 990 _ZoneFunction get _run =>
847 ZoneSpecification get _specification => const _RootZoneSpecification(); 991 const _ZoneFunction(_ROOT_ZONE, _rootRun);
848 Zone get _errorZone => this; 992 _ZoneFunction get _runUnary =>
993 const _ZoneFunction(_ROOT_ZONE, _rootRunUnary);
994 _ZoneFunction get _runBinary =>
995 const _ZoneFunction(_ROOT_ZONE, _rootRunBinary);
996 _ZoneFunction get _registerCallback =>
997 const _ZoneFunction(_ROOT_ZONE, _rootRegisterCallback);
998 _ZoneFunction get _registerUnaryCallback =>
999 const _ZoneFunction(_ROOT_ZONE, _rootRegisterUnaryCallback);
1000 _ZoneFunction get _registerBinaryCallback =>
1001 const _ZoneFunction(_ROOT_ZONE, _rootRegisterBinaryCallback);
1002 _ZoneFunction get _scheduleMicrotask =>
1003 const _ZoneFunction(_ROOT_ZONE, _rootScheduleMicrotask);
1004 _ZoneFunction get _createTimer =>
1005 const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer);
1006 _ZoneFunction get _createPeriodicTimer =>
1007 const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer);
1008 _ZoneFunction get _print =>
1009 const _ZoneFunction(_ROOT_ZONE, _rootPrint);
1010 _ZoneFunction get _fork =>
1011 const _ZoneFunction(_ROOT_ZONE, _rootFork);
1012 _ZoneFunction get _handleUncaughtError =>
1013 const _ZoneFunction(_ROOT_ZONE, _rootHandleUncaughtError);
849 1014
850 bool inSameErrorZone(Zone otherZone) => otherZone._errorZone == this; 1015 /// The parent zone.
1016 _Zone get parent => null;
1017
1018 /// The zone's scoped value declaration map.
1019 ///
1020 /// This is always a [HashMap].
1021 Map get _map => const {};
1022
1023 ZoneDelegate get _delegate => const _RootZoneDelegate();
1024
1025 /**
1026 * The closest error-handling zone.
1027 *
1028 * Returns `this` if `this` has an error-handler. Otherwise returns the
1029 * parent's error-zone.
1030 */
1031 Zone get errorZone => this;
1032
1033 // Zone interface.
1034
1035 dynamic runGuarded(f()) {
1036 try {
1037 if (identical(_ROOT_ZONE, Zone._current)) {
1038 return f();
1039 }
1040 return _rootRun(null, null, this, f);
1041 } catch (e, s) {
1042 return handleUncaughtError(e, s);
1043 }
1044 }
1045
1046 dynamic runUnaryGuarded(f(arg), arg) {
1047 try {
1048 if (identical(_ROOT_ZONE, Zone._current)) {
1049 return f(arg);
1050 }
1051 return _rootRunUnary(null, null, this, f, arg);
1052 } catch (e, s) {
1053 return handleUncaughtError(e, s);
1054 }
1055 }
1056
1057 dynamic runBinaryGuarded(f(arg1, arg2), arg1, arg2) {
1058 try {
1059 if (identical(_ROOT_ZONE, Zone._current)) {
1060 return f(arg1, arg2);
1061 }
1062 return _rootRunBinary(null, null, this, f, arg1, arg2);
1063 } catch (e, s) {
1064 return handleUncaughtError(e, s);
1065 }
1066 }
1067
1068 ZoneCallback bindCallback(f(), { bool runGuarded: true }) {
1069 if (runGuarded) {
1070 return () => this.runGuarded(f);
1071 } else {
1072 return () => this.run(f);
1073 }
1074 }
1075
1076 ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded: true }) {
1077 if (runGuarded) {
1078 return (arg) => this.runUnaryGuarded(f, arg);
1079 } else {
1080 return (arg) => this.runUnary(f, arg);
1081 }
1082 }
1083
1084 ZoneBinaryCallback bindBinaryCallback(
1085 f(arg1, arg2), { bool runGuarded: true }) {
1086 if (runGuarded) {
1087 return (arg1, arg2) => this.runBinaryGuarded(f, arg1, arg2);
1088 } else {
1089 return (arg1, arg2) => this.runBinary(f, arg1, arg2);
1090 }
1091 }
851 1092
852 operator [](Object key) => null; 1093 operator [](Object key) => null;
853 1094
854 // Methods that can be customized by the zone specification. 1095 // Methods that can be customized by the zone specification.
855 1096
856 dynamic handleUncaughtError(error, StackTrace stackTrace) => 1097 dynamic handleUncaughtError(error, StackTrace stackTrace) {
857 _rootHandleUncaughtError(this, null, this, error, stackTrace); 1098 _rootHandleUncaughtError(null, null, this, error, stackTrace);
floitsch 2014/06/24 12:50:30 return Yes: I think there are cases where handleU
Lasse Reichstein Nielsen 2014/06/24 14:56:06 Ack. I was wondering about the return type.
1099 }
858 1100
859 Zone fork({ZoneSpecification specification, Map zoneValues}) => 1101 Zone fork({ZoneSpecification specification, Map zoneValues}) {
860 _rootFork(this, null, this, specification, zoneValues); 1102 return _rootFork(null, null, this, specification, zoneValues);
1103 }
861 1104
862 dynamic run(f()) => _rootRun(this, null, this, f); 1105 dynamic run(f()) {
1106 if (identical(Zone._current, _ROOT_ZONE)) return f();
1107 return _rootRun(null, null, this, f);
1108 }
863 1109
864 dynamic runUnary(f(arg), arg) => _rootRunUnary(this, null, this, f, arg); 1110 dynamic runUnary(f(arg), arg) {
1111 if (identical(Zone._current, _ROOT_ZONE)) return f(arg);
1112 return _rootRunUnary(null, null, this, f, arg);
1113 }
865 1114
866 dynamic runBinary(f(arg1, arg2), arg1, arg2) => 1115 dynamic runBinary(f(arg1, arg2), arg1, arg2) {
867 _rootRunBinary(this, null, this, f, arg1, arg2); 1116 if (identical(Zone._current, _ROOT_ZONE)) return f(arg1, arg2);
1117 return _rootRunBinary(null, null, this, f, arg1, arg2);
1118 }
868 1119
869 ZoneCallback registerCallback(f()) => 1120 ZoneCallback registerCallback(f()) => f;
870 _rootRegisterCallback(this, null, this, f);
871 1121
872 ZoneUnaryCallback registerUnaryCallback(f(arg)) => 1122 ZoneUnaryCallback registerUnaryCallback(f(arg)) => f;
873 _rootRegisterUnaryCallback(this, null, this, f);
874 1123
875 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => 1124 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => f;
876 _rootRegisterBinaryCallback(this, null, this, f);
877 1125
878 void scheduleMicrotask(void f()) { 1126 void scheduleMicrotask(void f()) {
879 _rootScheduleMicrotask(this, null, this, f); 1127 _rootScheduleMicrotask(null, null, this, f);
880 } 1128 }
881 1129
882 Timer createTimer(Duration duration, void f()) => 1130 Timer createTimer(Duration duration, void f()) {
883 _rootCreateTimer(this, null, this, duration, f); 1131 return Timer._createTimer(duration, f);
1132 }
884 1133
885 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) => 1134 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) {
886 _rootCreatePeriodicTimer(this, null, this, duration, f); 1135 return Timer._createPeriodicTimer(duration, f);
1136 }
887 1137
888 void print(String line) => _rootPrint(this, null, this, line); 1138 void print(String line) {
1139 printToConsole(line);
1140 }
889 } 1141 }
890 1142
891 const _ROOT_ZONE = const _RootZone(); 1143 const _ROOT_ZONE = const _RootZone();
892 1144
893
894 /** 1145 /**
895 * Runs [body] in its own zone. 1146 * Runs [body] in its own zone.
896 * 1147 *
897 * If [onError] is non-null the zone is considered an error zone. All uncaught 1148 * If [onError] is non-null the zone is considered an error zone. All uncaught
898 * errors, synchronous or asynchronous, in the zone are caught and handled 1149 * errors, synchronous or asynchronous, in the zone are caught and handled
899 * by the callback. 1150 * by the callback.
900 * 1151 *
901 * Errors may never cross error-zone boundaries. This is intuitive for leaving 1152 * Errors may never cross error-zone boundaries. This is intuitive for leaving
902 * a zone, but it also applies for errors that would enter an error-zone. 1153 * a zone, but it also applies for errors that would enter an error-zone.
903 * Errors that try to cross error-zone boundaries are considered uncaught. 1154 * Errors that try to cross error-zone boundaries are considered uncaught.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 handleUncaughtError: errorHandler); 1198 handleUncaughtError: errorHandler);
948 } 1199 }
949 Zone zone = Zone.current.fork(specification: zoneSpecification, 1200 Zone zone = Zone.current.fork(specification: zoneSpecification,
950 zoneValues: zoneValues); 1201 zoneValues: zoneValues);
951 if (onError != null) { 1202 if (onError != null) {
952 return zone.runGuarded(body); 1203 return zone.runGuarded(body);
953 } else { 1204 } else {
954 return zone.run(body); 1205 return zone.run(body);
955 } 1206 }
956 } 1207 }
OLDNEW
« no previous file with comments | « sdk/lib/async/timer.dart ('k') | tests/lib/async/run_zoned9_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698