|
1 | 1 | import {FIELD, print} from 'angular2/src/facade/lang'; |
2 | 2 | import {ChangeDetector} from 'angular2/change_detection'; |
3 | 3 | import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone'; |
| 4 | +import {ExceptionHandler} from 'angular2/src/core/exception_handler'; |
4 | 5 | import {ListWrapper} from 'angular2/src/facade/collection'; |
5 | 6 | import {isPresent} from 'angular2/src/facade/lang'; |
6 | 7 |
|
7 | 8 | export class LifeCycle { |
| 9 | + _errorHandler; |
8 | 10 | _changeDetector:ChangeDetector; |
9 | 11 | _enforceNoNewChanges:boolean; |
10 | 12 |
|
11 | | - constructor(changeDetector:ChangeDetector = null, enforceNoNewChanges:boolean = false) { |
| 13 | + constructor(exceptionHandler:ExceptionHandler, changeDetector:ChangeDetector = null, enforceNoNewChanges:boolean = false) { |
| 14 | + this._errorHandler = (exception, stackTrace) => { |
| 15 | + exceptionHandler.call(exception, stackTrace); |
| 16 | + throw exception; |
| 17 | + }; |
12 | 18 | this._changeDetector = changeDetector; // may be null when instantiated from application bootstrap |
13 | 19 | this._enforceNoNewChanges = enforceNoNewChanges; |
14 | 20 | } |
15 | 21 |
|
16 | 22 | registerWith(zone:VmTurnZone, changeDetector:ChangeDetector = null) { |
17 | | - // temporary error handler, we should inject one |
18 | | - var errorHandler = (exception, stackTrace) => { |
19 | | - var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n"); |
20 | | - print(`${exception}\n\n${longStackTrace}`); |
21 | | - throw exception; |
22 | | - }; |
23 | | - |
24 | 23 | if (isPresent(changeDetector)) { |
25 | 24 | this._changeDetector=changeDetector; |
26 | 25 | } |
27 | 26 |
|
28 | 27 | zone.initCallbacks({ |
29 | | - onErrorHandler: errorHandler, |
| 28 | + onErrorHandler: this._errorHandler, |
30 | 29 | onTurnDone: () => this.tick() |
31 | 30 | }); |
32 | 31 | } |
|
0 commit comments