Skip to content

Commit

Permalink
fix angular#551, add toJSON to ZoneTask to prevent cyclic error
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Jan 1, 2017
1 parent c03acda commit 822bea6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,20 @@ const Zone: ZoneType = (function(global: any) {
return Object.prototype.toString.call(this);
}
}

public toJSON() {
return {
type: this.type,
source: this.source,
data: this.data,
zone: this.zone.name,
invoke: this.invoke,
scheduleFn: this.scheduleFn,
cancelFn: this.cancelFn,
runCount: this.runCount,
callback: this.callback
};
}
}

interface UncaughtPromiseError extends Error {
Expand Down
16 changes: 16 additions & 0 deletions test/common/zone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ describe('Zone', function() {

macro.invoke();
});

it('should convert task to json without cyclic error', () => {
const z = Zone.current;
const event = z.scheduleEventTask('test', () => {}, null, noop, noop);
const micro = z.scheduleMicroTask('test', () => {});
const macro = z.scheduleMacroTask('test', () => {}, null, noop, noop);
expect(function() {
JSON.stringify(event);
}).not.toThrow();
expect(function() {
JSON.stringify(micro);
}).not.toThrow();
expect(function() {
JSON.stringify(macro);
}).not.toThrow();
});
});
});

Expand Down

0 comments on commit 822bea6

Please sign in to comment.