From 0d9a1de4d9956d55cf3db7b65eacf1af72874e5c Mon Sep 17 00:00:00 2001 From: vsavkin Date: Tue, 8 Dec 2015 13:27:56 -0800 Subject: [PATCH] fix(bootstrap): fix the configuration of ExceptionHandler --- modules/angular2/src/core/application_ref.ts | 11 +++++++++-- modules/angular2/src/platform/browser_common.ts | 6 ++++-- modules/angular2/src/platform/worker_render_common.ts | 4 ++-- .../angular2/test/platform/browser/bootstrap_spec.ts | 4 ++-- modules/angular2/test/router/route_config_spec.ts | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/angular2/src/core/application_ref.ts b/modules/angular2/src/core/application_ref.ts index 2800dca73a..3973f2d34c 100644 --- a/modules/angular2/src/core/application_ref.ts +++ b/modules/angular2/src/core/application_ref.ts @@ -1,5 +1,5 @@ import {NgZone} from 'angular2/src/core/zone/ng_zone'; -import {Type, isBlank, isPresent, assertionsEnabled, print} from 'angular2/src/facade/lang'; +import {Type, isBlank, isPresent, assertionsEnabled, print, IS_DART} from 'angular2/src/facade/lang'; import {provide, Provider, Injector, OpaqueToken} from 'angular2/src/core/di'; import { APP_COMPONENT_REF_PROMISE, @@ -412,7 +412,14 @@ export class ApplicationRef_ extends ApplicationRef { var tickResult = PromiseWrapper.then(compRefToken, tick); - PromiseWrapper.then(tickResult, (_) => {}); + // THIS MUST ONLY RUN IN DART. + // This is required to report an error when no components with a matching selector found. + // Otherwise the promise will never be completed. + // Doing this in JS causes an extra error message to appear. + if (IS_DART) { + PromiseWrapper.then(tickResult, (_) => {}); + } + PromiseWrapper.then(tickResult, null, (err, stackTrace) => completer.reject(err, stackTrace)); } catch (e) { diff --git a/modules/angular2/src/platform/browser_common.ts b/modules/angular2/src/platform/browser_common.ts index 81ba5ddee5..300829bffc 100644 --- a/modules/angular2/src/platform/browser_common.ts +++ b/modules/angular2/src/platform/browser_common.ts @@ -1,4 +1,4 @@ -import {CONST_EXPR} from 'angular2/src/facade/lang'; +import {CONST_EXPR, IS_DART} from 'angular2/src/facade/lang'; import {provide, Provider, Injector, OpaqueToken} from 'angular2/src/core/di'; import { @@ -48,7 +48,9 @@ export const BROWSER_PROVIDERS: Array = CONST_E ]); function _exceptionHandler(): ExceptionHandler { - return new ExceptionHandler(DOM, false); + // !IS_DART is required because we must rethrow exceptions in JS, + // but must not rethrow exceptions in Dart + return new ExceptionHandler(DOM, !IS_DART); } function _document(): any { diff --git a/modules/angular2/src/platform/worker_render_common.ts b/modules/angular2/src/platform/worker_render_common.ts index b51bdff8c8..7f950c01fe 100644 --- a/modules/angular2/src/platform/worker_render_common.ts +++ b/modules/angular2/src/platform/worker_render_common.ts @@ -1,4 +1,4 @@ -import {CONST_EXPR} from 'angular2/src/facade/lang'; +import {CONST_EXPR, IS_DART} from 'angular2/src/facade/lang'; import {MessageBus} from 'angular2/src/web_workers/shared/message_bus'; import {NgZone} from 'angular2/src/core/zone/ng_zone'; import {AnchorBasedAppRootUrl} from 'angular2/src/compiler/anchor_based_app_root_url'; @@ -112,7 +112,7 @@ export function initWebWorkerRenderPlatform(): void { } function _exceptionHandler(): ExceptionHandler { - return new ExceptionHandler(DOM, false); + return new ExceptionHandler(DOM, !IS_DART); } function _document(): any { diff --git a/modules/angular2/test/platform/browser/bootstrap_spec.ts b/modules/angular2/test/platform/browser/bootstrap_spec.ts index f89882e322..1b6b1ce529 100644 --- a/modules/angular2/test/platform/browser/bootstrap_spec.ts +++ b/modules/angular2/test/platform/browser/bootstrap_spec.ts @@ -125,7 +125,7 @@ export function main() { it('should throw if no element is found', inject([AsyncTestCompleter], (async) => { var logger = new _ArrayLogger(); - var exceptionHandler = new ExceptionHandler(logger, IS_DART ? false : true); + var exceptionHandler = new ExceptionHandler(logger, !IS_DART); var refPromise = bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]); @@ -140,7 +140,7 @@ export function main() { it('should invoke the default exception handler when bootstrap fails', inject([AsyncTestCompleter], (async) => { var logger = new _ArrayLogger(); - var exceptionHandler = new ExceptionHandler(logger, IS_DART ? false : true); + var exceptionHandler = new ExceptionHandler(logger, !IS_DART); var refPromise = bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]); diff --git a/modules/angular2/test/router/route_config_spec.ts b/modules/angular2/test/router/route_config_spec.ts index 6094178ac4..c3040ef7fd 100644 --- a/modules/angular2/test/router/route_config_spec.ts +++ b/modules/angular2/test/router/route_config_spec.ts @@ -16,7 +16,7 @@ import {Component, Directive, View} from 'angular2/src/core/metadata'; import {DOM} from 'angular2/src/platform/dom/dom_adapter'; import {provide} from 'angular2/core'; import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens'; -import {Type} from 'angular2/src/facade/lang'; +import {Type, IS_DART} from 'angular2/src/facade/lang'; import { ROUTER_PROVIDERS, @@ -46,7 +46,7 @@ export function main() { el = DOM.createElement('app-cmp', fakeDoc); DOM.appendChild(fakeDoc.body, el); var logger = new _ArrayLogger(); - var exceptionHandler = new ExceptionHandler(logger, true); + var exceptionHandler = new ExceptionHandler(logger, !IS_DART); testBindings = [ ROUTER_PROVIDERS, provide(LocationStrategy, {useClass: MockLocationStrategy}),