diff --git a/modules/angular2/src/core/application.dart b/modules/angular2/src/core/application.dart index cee336add1..d6fa23c6f6 100644 --- a/modules/angular2/src/core/application.dart +++ b/modules/angular2/src/core/application.dart @@ -15,7 +15,7 @@ export 'application_common.dart' show ApplicationRef; /// /// See [commonBootstrap] for detailed documentation. Future bootstrap(Type appComponentType, - [List componentInjectableBindings, Function errorReporter]) { + [List componentInjectableBindings]) { reflector.reflectionCapabilities = new ReflectionCapabilities(); - return commonBootstrap(appComponentType, componentInjectableBindings, errorReporter); + return commonBootstrap(appComponentType, componentInjectableBindings); } diff --git a/modules/angular2/src/core/application_common.ts b/modules/angular2/src/core/application_common.ts index 77f51b0441..3ffd1aa3a3 100644 --- a/modules/angular2/src/core/application_common.ts +++ b/modules/angular2/src/core/application_common.ts @@ -97,9 +97,8 @@ function _injectorBindings(appComponentType): List> { bind(appComponentType) .toFactory((p: Promise) => p.then(ref => ref.instance), [appComponentRefPromiseToken]), - bind(LifeCycle) - .toFactory((exceptionHandler) => new LifeCycle(exceptionHandler, null, assertionsEnabled()), - [ExceptionHandler]), + bind(LifeCycle).toFactory((exceptionHandler) => new LifeCycle(null, assertionsEnabled()), + [ExceptionHandler]), bind(EventManager) .toFactory( (ngZone) => { @@ -141,22 +140,13 @@ function _injectorBindings(appComponentType): List> { ]; } -function _createNgZone(givenReporter: Function): NgZone { - var defaultErrorReporter = (exception, stackTrace) => { - var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n"); - DOM.logError(`${exception}\n\n${longStackTrace}`); - - if (exception instanceof BaseException && isPresent(exception.context)) { - print("Error Context:"); - print(exception.context); - } - throw exception; - }; - - var reporter = isPresent(givenReporter) ? givenReporter : defaultErrorReporter; - +function _createNgZone(): NgZone { + // bootstrapErrorReporter is needed because we cannot use custom exception handler + // configured via DI until the root Injector has been created. + var handler = new ExceptionHandler(); + var bootstrapErrorReporter = (exception, stackTrace) => handler.call(exception, stackTrace); var zone = new NgZone({enableLongStackTrace: assertionsEnabled()}); - zone.overrideOnErrorHandler(reporter); + zone.overrideOnErrorHandler(bootstrapErrorReporter); return zone; } @@ -287,17 +277,20 @@ function _createNgZone(givenReporter: Function): NgZone { * Returns a `Promise` of {@link ApplicationRef}. */ export function commonBootstrap( - appComponentType: Type, componentInjectableBindings: List> = null, - errorReporter: Function = null): Promise { + appComponentType: Type, componentInjectableBindings: List> = null): + Promise { BrowserDomAdapter.makeCurrent(); var bootstrapProcess = PromiseWrapper.completer(); - var zone = _createNgZone(errorReporter); + var zone = _createNgZone(); zone.run(() => { // TODO(rado): prepopulate template cache, so applications with only // index.html and main.js are possible. var appInjector = _createAppInjector(appComponentType, componentInjectableBindings, zone); + var exceptionHandler = appInjector.get(ExceptionHandler); + zone.overrideOnErrorHandler((e, s) => exceptionHandler.call(e, s)); + var compRefToken: Promise = PromiseWrapper.wrap(() => appInjector.get(appComponentRefPromiseToken)); var tick = (componentRef) => { diff --git a/modules/angular2/src/core/application_static.dart b/modules/angular2/src/core/application_static.dart index ef2b8f57a9..6d8cb45e1a 100644 --- a/modules/angular2/src/core/application_static.dart +++ b/modules/angular2/src/core/application_static.dart @@ -8,7 +8,6 @@ import 'application_common.dart'; /// See [commonBootstrap] for detailed documentation. Future bootstrapStatic( Type appComponentType, - [List componentInjectableBindings, - Function errorReporter]) { - return commonBootstrap(appComponentType, componentInjectableBindings, errorReporter); + [List componentInjectableBindings]) { + return commonBootstrap(appComponentType, componentInjectableBindings); } diff --git a/modules/angular2/src/core/exception_handler.ts b/modules/angular2/src/core/exception_handler.ts index 3751b38b39..33937a7d8a 100644 --- a/modules/angular2/src/core/exception_handler.ts +++ b/modules/angular2/src/core/exception_handler.ts @@ -28,7 +28,7 @@ import {DOM} from 'angular2/src/dom/dom_adapter'; export class ExceptionHandler { logError: Function = DOM.logError; - call(exception: Object, stackTrace: string | string[] = null, reason: string = null) { + call(exception: Object, stackTrace: any = null, reason: string = null) { var longStackTrace = isListLikeIterable(stackTrace) ? (stackTrace).join("\n\n-----async gap-----\n") : stackTrace; diff --git a/modules/angular2/src/core/life_cycle/life_cycle.ts b/modules/angular2/src/core/life_cycle/life_cycle.ts index 5acbd53313..227014696e 100644 --- a/modules/angular2/src/core/life_cycle/life_cycle.ts +++ b/modules/angular2/src/core/life_cycle/life_cycle.ts @@ -1,7 +1,6 @@ import {Injectable} from 'angular2/di'; import {ChangeDetector} from 'angular2/change_detection'; import {NgZone} from 'angular2/src/core/zone/ng_zone'; -import {ExceptionHandler} from 'angular2/src/core/exception_handler'; import {isPresent, BaseException} from 'angular2/src/facade/lang'; /** @@ -32,17 +31,11 @@ import {isPresent, BaseException} from 'angular2/src/facade/lang'; */ @Injectable() export class LifeCycle { - _errorHandler; _changeDetector: ChangeDetector; _enforceNoNewChanges: boolean; _runningTick: boolean = false; - constructor(exceptionHandler: ExceptionHandler, changeDetector: ChangeDetector = null, - enforceNoNewChanges: boolean = false) { - this._errorHandler = (exception, stackTrace) => { - exceptionHandler.call(exception, stackTrace); - throw exception; - }; + constructor(changeDetector: ChangeDetector = null, enforceNoNewChanges: boolean = false) { this._changeDetector = changeDetector; // may be null when instantiated from application bootstrap this._enforceNoNewChanges = enforceNoNewChanges; @@ -55,8 +48,6 @@ export class LifeCycle { if (isPresent(changeDetector)) { this._changeDetector = changeDetector; } - - zone.overrideOnErrorHandler(this._errorHandler); zone.overrideOnTurnDone(() => this.tick()); } diff --git a/modules/angular2/test/core/application_spec.ts b/modules/angular2/test/core/application_spec.ts index f185f70e9b..76a60d544f 100644 --- a/modules/angular2/test/core/application_spec.ts +++ b/modules/angular2/test/core/application_spec.ts @@ -83,8 +83,7 @@ export function main() { it('should throw if bootstrapped Directive is not a Component', inject([AsyncTestCompleter], (async) => { - var refPromise = - bootstrap(HelloRootDirectiveIsNotCmp, testBindings, (e, t) => { throw e; }); + var refPromise = bootstrap(HelloRootDirectiveIsNotCmp, testBindings); PromiseWrapper.then(refPromise, null, (reason) => { expect(reason.message) @@ -96,7 +95,7 @@ export function main() { })); it('should throw if no element is found', inject([AsyncTestCompleter], (async) => { - var refPromise = bootstrap(HelloRootCmp, [], (e, t) => { throw e; }); + var refPromise = bootstrap(HelloRootCmp, []); PromiseWrapper.then(refPromise, null, (reason) => { expect(reason.message).toContain('The selector "hello-app" did not match any elements'); async.done(); diff --git a/modules/angular2/test/core/life_cycle/life_cycle_spec.ts b/modules/angular2/test/core/life_cycle/life_cycle_spec.ts index 4774371b5d..b6e6baf5ef 100644 --- a/modules/angular2/test/core/life_cycle/life_cycle_spec.ts +++ b/modules/angular2/test/core/life_cycle/life_cycle_spec.ts @@ -21,7 +21,7 @@ export function main() { describe("LifeCycle", () => { it("should throw when reentering tick", () => { var cd = new SpyChangeDetector(); - var lc = new LifeCycle(null, cd, false); + var lc = new LifeCycle(cd, false); cd.spy("detectChanges").andCallFake(() => lc.tick()); expect(() => lc.tick()).toThrowError("LifeCycle.tick is called recursively");