Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ function proxyServeDart() {

// ------------------
// web servers
gulp.task('serve.js.dev', ['build.js.dev'], function(neverDone) {
gulp.task('serve.js.dev', ['build.js.dev', 'build.js.cjs'], function(neverDone) {
var watch = require('./tools/build/watch');

watch('modules/**', {ignoreInitial: true}, '!broccoli.js.dev');
Expand Down Expand Up @@ -706,7 +706,7 @@ gulp.task('!build.payload.js.webpack', function() {
.then(function() { // pad bundle with mandatory dependencies
return new Promise(function(resolve, reject) {
gulp.src([
'node_modules/zone.js/dist/zone-microtask.js',
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/reflect-metadata/Reflect.js',
CASE_PATH + '/app-bundle.js'
Expand Down Expand Up @@ -991,7 +991,7 @@ gulp.task('test.typings',
['!pre.test.typings.layoutNodeModule', '!pre.test.typings.copyTypingsSpec'], function() {
var tsc = require('gulp-typescript');

return gulp.src([tmpdir + '/*.ts'])
return gulp.src([tmpdir + '/*.ts', 'node_modules/zone.js/dist/zone.js.d.ts'])
.pipe(tsc({
target: 'ES6',
module: 'commonjs',
Expand Down Expand Up @@ -1355,7 +1355,7 @@ gulp.task('!bundle.ng.polyfills', ['clean'],

var JS_DEV_DEPS = [
licenseWrap('node_modules/zone.js/LICENSE', true),
'node_modules/zone.js/dist/zone-microtask.js',
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js',
licenseWrap('node_modules/reflect-metadata/LICENSE', true),
'node_modules/reflect-metadata/Reflect.js'
Expand Down
3 changes: 1 addition & 2 deletions karma-js.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ module.exports = function(config) {
// include Angular v1 for upgrade module testing
'node_modules/angular/angular.min.js',

// zone-microtask must be included first as it contains a Promise monkey patch
'node_modules/zone.js/dist/zone-microtask.js',
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/zone.js/dist/jasmine-patch.js',

Expand Down
22 changes: 9 additions & 13 deletions modules/angular2/src/core/application_ref.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {NgZone, NgZoneError} from 'angular2/src/core/zone/ng_zone';
import {
Type,
isBlank,
Expand Down Expand Up @@ -254,7 +254,9 @@ export class PlatformRef_ extends PlatformRef {
try {
injector = this.injector.resolveAndCreateChild(providers);
exceptionHandler = injector.get(ExceptionHandler);
zone.overrideOnErrorHandler((e, s) => exceptionHandler.call(e, s));
ObservableWrapper.subscribe(zone.onError, (error: NgZoneError) => {
exceptionHandler.call(error.error, error.stackTrace);
});
} catch (e) {
if (isPresent(exceptionHandler)) {
exceptionHandler.call(e, e.stack);
Expand Down Expand Up @@ -394,7 +396,7 @@ export class ApplicationRef_ extends ApplicationRef {
constructor(private _platform: PlatformRef_, private _zone: NgZone, private _injector: Injector) {
super();
if (isPresent(this._zone)) {
ObservableWrapper.subscribe(this._zone.onTurnDone,
ObservableWrapper.subscribe(this._zone.onMicrotaskEmpty,
(_) => { this._zone.run(() => { this.tick(); }); });
}
this._enforceNoNewChanges = assertionsEnabled();
Expand Down Expand Up @@ -434,16 +436,10 @@ export class ApplicationRef_ extends ApplicationRef {

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

// 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));
PromiseWrapper.then(tickResult, null, (err, stackTrace) => {
completer.reject(err, stackTrace);
exceptionHandler.call(err, stackTrace);
});
} catch (e) {
exceptionHandler.call(e, e.stack);
completer.reject(e, e.stack);
Expand Down
56 changes: 27 additions & 29 deletions modules/angular2/src/core/testability/testability.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Injectable} from 'angular2/src/core/di';
import {Map, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
import {CONST, CONST_EXPR} from 'angular2/src/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
import {CONST, CONST_EXPR, scheduleMicroTask} from 'angular2/src/facade/lang';
import {BaseException} from 'angular2/src/facade/exceptions';
import {NgZone} from '../zone/ng_zone';
import {PromiseWrapper, ObservableWrapper} from 'angular2/src/facade/async';
import {ObservableWrapper} from 'angular2/src/facade/async';


/**
Expand All @@ -15,6 +15,7 @@ import {PromiseWrapper, ObservableWrapper} from 'angular2/src/facade/async';
export class Testability {
/** @internal */
_pendingCount: number = 0;
_isZoneStable: boolean = true;
/**
* Whether any work was done since the last 'whenStable' callback. This is
* useful to detect if this could have potentially destabilized another
Expand All @@ -24,23 +25,22 @@ export class Testability {
_didWork: boolean = false;
/** @internal */
_callbacks: Function[] = [];
/** @internal */
_isAngularEventPending: boolean = false;
constructor(_ngZone: NgZone) { this._watchAngularEvents(_ngZone); }
constructor(private _ngZone: NgZone) { this._watchAngularEvents(); }

/** @internal */
_watchAngularEvents(_ngZone: NgZone): void {
ObservableWrapper.subscribe(_ngZone.onTurnStart, (_) => {
_watchAngularEvents(): void {
ObservableWrapper.subscribe(this._ngZone.onUnstable, (_) => {
this._didWork = true;
this._isAngularEventPending = true;
this._isZoneStable = false;
});

_ngZone.runOutsideAngular(() => {
ObservableWrapper.subscribe(_ngZone.onEventDone, (_) => {
if (!_ngZone.hasPendingTimers) {
this._isAngularEventPending = false;
this._ngZone.runOutsideAngular(() => {
ObservableWrapper.subscribe(this._ngZone.onStable, (_) => {
NgZone.assertNotInAngularZone();
scheduleMicroTask(() => {
this._isZoneStable = true;
this._runCallbacksIfReady();
}
});
});
});
}
Expand All @@ -60,22 +60,24 @@ export class Testability {
return this._pendingCount;
}

isStable(): boolean { return this._pendingCount == 0 && !this._isAngularEventPending; }
isStable(): boolean {
return this._isZoneStable && this._pendingCount == 0 && !this._ngZone.hasPendingMacrotasks;
}

/** @internal */
_runCallbacksIfReady(): void {
if (!this.isStable()) {
if (this.isStable()) {
// Schedules the call backs in a new frame so that it is always async.
scheduleMicroTask(() => {
while (this._callbacks.length !== 0) {
(this._callbacks.pop())(this._didWork);
}
this._didWork = false;
});
} else {
// Not Ready
this._didWork = true;
return; // Not ready
}

// Schedules the call backs in a new frame so that it is always async.
PromiseWrapper.resolve(null).then((_) => {
while (this._callbacks.length !== 0) {
(this._callbacks.pop())(this._didWork);
}
this._didWork = false;
});
}

whenStable(callback: Function): void {
Expand All @@ -85,10 +87,6 @@ export class Testability {

getPendingRequestCount(): number { return this._pendingCount; }

// This only accounts for ngZone, and not pending counts. Use `whenStable` to
// check for stability.
isAngularEventPending(): boolean { return this._isAngularEventPending; }

findBindings(using: any, provider: string, exactMatch: boolean): any[] {
// TODO(juliemr): implement.
return [];
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/zone.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Public API for Zone
export {NgZone, ZeroArgFunction, ErrorHandlingFn, NgZoneError} from './zone/ng_zone';
export {NgZone, NgZoneError} from './zone/ng_zone';
Loading