Skip to content

Commit 0d9a1de

Browse files
vsavkinjelbourn
authored andcommitted
fix(bootstrap): fix the configuration of ExceptionHandler
1 parent d58f017 commit 0d9a1de

5 files changed

Lines changed: 19 additions & 10 deletions

File tree

modules/angular2/src/core/application_ref.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {NgZone} from 'angular2/src/core/zone/ng_zone';
2-
import {Type, isBlank, isPresent, assertionsEnabled, print} from 'angular2/src/facade/lang';
2+
import {Type, isBlank, isPresent, assertionsEnabled, print, IS_DART} from 'angular2/src/facade/lang';
33
import {provide, Provider, Injector, OpaqueToken} from 'angular2/src/core/di';
44
import {
55
APP_COMPONENT_REF_PROMISE,
@@ -412,7 +412,14 @@ export class ApplicationRef_ extends ApplicationRef {
412412

413413
var tickResult = PromiseWrapper.then(compRefToken, tick);
414414

415-
PromiseWrapper.then(tickResult, (_) => {});
415+
// THIS MUST ONLY RUN IN DART.
416+
// This is required to report an error when no components with a matching selector found.
417+
// Otherwise the promise will never be completed.
418+
// Doing this in JS causes an extra error message to appear.
419+
if (IS_DART) {
420+
PromiseWrapper.then(tickResult, (_) => {});
421+
}
422+
416423
PromiseWrapper.then(tickResult, null,
417424
(err, stackTrace) => completer.reject(err, stackTrace));
418425
} catch (e) {

modules/angular2/src/platform/browser_common.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {CONST_EXPR} from 'angular2/src/facade/lang';
1+
import {CONST_EXPR, IS_DART} from 'angular2/src/facade/lang';
22
import {provide, Provider, Injector, OpaqueToken} from 'angular2/src/core/di';
33

44
import {
@@ -48,7 +48,9 @@ export const BROWSER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CONST_E
4848
]);
4949

5050
function _exceptionHandler(): ExceptionHandler {
51-
return new ExceptionHandler(DOM, false);
51+
// !IS_DART is required because we must rethrow exceptions in JS,
52+
// but must not rethrow exceptions in Dart
53+
return new ExceptionHandler(DOM, !IS_DART);
5254
}
5355

5456
function _document(): any {

modules/angular2/src/platform/worker_render_common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {CONST_EXPR} from 'angular2/src/facade/lang';
1+
import {CONST_EXPR, IS_DART} from 'angular2/src/facade/lang';
22
import {MessageBus} from 'angular2/src/web_workers/shared/message_bus';
33
import {NgZone} from 'angular2/src/core/zone/ng_zone';
44
import {AnchorBasedAppRootUrl} from 'angular2/src/compiler/anchor_based_app_root_url';
@@ -112,7 +112,7 @@ export function initWebWorkerRenderPlatform(): void {
112112
}
113113

114114
function _exceptionHandler(): ExceptionHandler {
115-
return new ExceptionHandler(DOM, false);
115+
return new ExceptionHandler(DOM, !IS_DART);
116116
}
117117

118118
function _document(): any {

modules/angular2/test/platform/browser/bootstrap_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export function main() {
125125

126126
it('should throw if no element is found', inject([AsyncTestCompleter], (async) => {
127127
var logger = new _ArrayLogger();
128-
var exceptionHandler = new ExceptionHandler(logger, IS_DART ? false : true);
128+
var exceptionHandler = new ExceptionHandler(logger, !IS_DART);
129129

130130
var refPromise =
131131
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
@@ -140,7 +140,7 @@ export function main() {
140140
it('should invoke the default exception handler when bootstrap fails',
141141
inject([AsyncTestCompleter], (async) => {
142142
var logger = new _ArrayLogger();
143-
var exceptionHandler = new ExceptionHandler(logger, IS_DART ? false : true);
143+
var exceptionHandler = new ExceptionHandler(logger, !IS_DART);
144144

145145
var refPromise =
146146
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);

modules/angular2/test/router/route_config_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {Component, Directive, View} from 'angular2/src/core/metadata';
1616
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
1717
import {provide} from 'angular2/core';
1818
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
19-
import {Type} from 'angular2/src/facade/lang';
19+
import {Type, IS_DART} from 'angular2/src/facade/lang';
2020

2121
import {
2222
ROUTER_PROVIDERS,
@@ -46,7 +46,7 @@ export function main() {
4646
el = DOM.createElement('app-cmp', fakeDoc);
4747
DOM.appendChild(fakeDoc.body, el);
4848
var logger = new _ArrayLogger();
49-
var exceptionHandler = new ExceptionHandler(logger, true);
49+
var exceptionHandler = new ExceptionHandler(logger, !IS_DART);
5050
testBindings = [
5151
ROUTER_PROVIDERS,
5252
provide(LocationStrategy, {useClass: MockLocationStrategy}),

0 commit comments

Comments
 (0)