diff --git a/modules/angular2/src/core/application.js b/modules/angular2/src/core/application.js index fb5be79b92..af4c949068 100644 --- a/modules/angular2/src/core/application.js +++ b/modules/angular2/src/core/application.js @@ -134,7 +134,7 @@ function _injectorBindings(appComponentType): List { function _createVmZone(givenReporter:Function): VmTurnZone { var defaultErrorReporter = (exception, stackTrace) => { var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n"); - print(`${exception}\n\n${longStackTrace}`); + DOM.logError(`${exception}\n\n${longStackTrace}`); throw exception; }; diff --git a/modules/angular2/src/core/exception_handler.js b/modules/angular2/src/core/exception_handler.js index d94d864b6f..9b5b61c953 100644 --- a/modules/angular2/src/core/exception_handler.js +++ b/modules/angular2/src/core/exception_handler.js @@ -1,6 +1,7 @@ import {Injectable} from 'angular2/di'; import {isPresent, print} from 'angular2/src/facade/lang'; import {ListWrapper, isListLikeIterable} from 'angular2/src/facade/collection'; +import {DOM} from 'angular2/src/dom/dom_adapter'; /** * Provides a hook for centralized exception handling. @@ -36,6 +37,6 @@ export class ExceptionHandler { call(error, stackTrace = null, reason = null) { var longStackTrace = isListLikeIterable(stackTrace) ? ListWrapper.join(stackTrace, "\n\n") : stackTrace; var reasonStr = isPresent(reason) ? `\n${reason}` : ''; - print(`${error}${reasonStr}\nSTACKTRACE:\n${longStackTrace}`); + DOM.logError(`${error}${reasonStr}\nSTACKTRACE:\n${longStackTrace}`); } } diff --git a/modules/angular2/src/dom/browser_adapter.dart b/modules/angular2/src/dom/browser_adapter.dart index d0f97d986c..6184ea0cd8 100644 --- a/modules/angular2/src/dom/browser_adapter.dart +++ b/modules/angular2/src/dom/browser_adapter.dart @@ -100,6 +100,10 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter { setRootDomAdapter(new BrowserDomAdapter()); } + logError(error) { + window.console.error(error); + } + @override Map get attrToPropMap => const { 'innerHtml': 'innerHtml', diff --git a/modules/angular2/src/dom/browser_adapter.es6 b/modules/angular2/src/dom/browser_adapter.es6 index e2850d9e20..567b6c0c36 100644 --- a/modules/angular2/src/dom/browser_adapter.es6 +++ b/modules/angular2/src/dom/browser_adapter.es6 @@ -57,6 +57,10 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { setRootDomAdapter(new BrowserDomAdapter()); } + logError(error) { + window.console.error(error); + } + get attrToPropMap() { return _attrToPropMap; } diff --git a/modules/angular2/src/dom/dom_adapter.js b/modules/angular2/src/dom/dom_adapter.js index d2adf3cb50..2ce54edb8b 100644 --- a/modules/angular2/src/dom/dom_adapter.js +++ b/modules/angular2/src/dom/dom_adapter.js @@ -16,6 +16,10 @@ function _abstract() { @ABSTRACT() export class DomAdapter { + logError(error) { + throw _abstract(); + } + /** * Maps attribute names to their corresponding property names for cases * where attribute name doesn't match property name. diff --git a/modules/angular2/src/dom/html_adapter.dart b/modules/angular2/src/dom/html_adapter.dart index 78a09c0020..d71a2c16f1 100644 --- a/modules/angular2/src/dom/html_adapter.dart +++ b/modules/angular2/src/dom/html_adapter.dart @@ -3,12 +3,17 @@ library angular2.dom.htmlAdapter; import 'dom_adapter.dart'; import 'package:html/parser.dart' as parser; import 'package:html/dom.dart'; +import 'dart:io'; class Html5LibDomAdapter implements DomAdapter { static void makeCurrent() { setRootDomAdapter(new Html5LibDomAdapter()); } + logError(error) { + stderr.writeln('${error}'); + } + @override final attrToPropMap = const { 'innerHtml': 'innerHtml', diff --git a/modules/angular2/src/dom/parse5_adapter.cjs b/modules/angular2/src/dom/parse5_adapter.cjs index df7e4b1ff1..4ac8ba3539 100644 --- a/modules/angular2/src/dom/parse5_adapter.cjs +++ b/modules/angular2/src/dom/parse5_adapter.cjs @@ -28,6 +28,10 @@ export class Parse5DomAdapter extends DomAdapter { setRootDomAdapter(new Parse5DomAdapter()); } + logError(error) { + console.error(error); + } + get attrToPropMap() { return _attrToPropMap; } diff --git a/modules/examples/e2e_test/sourcemap/sourcemap_spec.es6 b/modules/examples/e2e_test/sourcemap/sourcemap_spec.es6 index 844a358627..88c89aca89 100644 --- a/modules/examples/e2e_test/sourcemap/sourcemap_spec.es6 +++ b/modules/examples/e2e_test/sourcemap/sourcemap_spec.es6 @@ -6,6 +6,9 @@ describe('sourcemaps', function () { it('should map sources', function() { browser.get(URL); + + $('error-app .errorButton').click(); + // TODO(tbosch): Bug in ChromeDriver: Need to execute at least one command // so that the browser logs can be read out! browser.executeScript('1+1'); @@ -13,7 +16,7 @@ describe('sourcemaps', function () { var errorLine = null; var errorColumn = null; logs.forEach(function(log) { - var match = /Test\.run\s+\(.+:(\d+):(\d+)/m.exec(log.message); + var match = /\.createError\s+\(.+:(\d+):(\d+)/m.exec(log.message); if (match) { errorLine = parseInt(match[1]); errorColumn = parseInt(match[2]); diff --git a/modules/examples/src/sourcemap/index.html b/modules/examples/src/sourcemap/index.html index 1689e33399..c8b981108e 100644 --- a/modules/examples/src/sourcemap/index.html +++ b/modules/examples/src/sourcemap/index.html @@ -2,8 +2,15 @@ Sourcemaps + + Loading... + + +

Please look into the console and check whether the stack trace is mapped via source maps! +

+ $SCRIPTS$ diff --git a/modules/examples/src/sourcemap/index.js b/modules/examples/src/sourcemap/index.js index b4434cce8e..5634b9697f 100644 --- a/modules/examples/src/sourcemap/index.js +++ b/modules/examples/src/sourcemap/index.js @@ -1,24 +1,24 @@ import { BaseException, print, CONST } from 'angular2/src/facade/lang'; +import { bootstrap } from 'angular2/angular2'; +// TODO(radokirov): Once the application is transpiled by TS instead of Traceur, +// add those imports back into 'angular2/angular2'; +import {Component} from 'angular2/src/core/annotations_impl/annotations'; +import {View} from 'angular2/src/core/annotations_impl/view'; -class TestAnnotation { - @CONST() - constructor() {} -} - -// Use a class with an annotation, -// as this is where we expect the most source code changes -// through compilation. -@TestAnnotation() -class Test { - run() { - try { - throw new BaseException('Sourcemap test'); - } catch (e) { - print(e); - } +@Component({ + selector: 'error-app', +}) +@View({ + template: ` + `, + directives: [] +}) +export class ErrorComponent { + createError() { + throw new BaseException('Sourcemap test'); } } export function main() { - new Test().run(); + bootstrap(ErrorComponent); }