Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Merged
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
16 changes: 16 additions & 0 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,22 @@ const Zone: ZoneType = (function(global: any) {
return Object.prototype.toString.call(this);
}
}

// add toJSON method to prevent cyclic error when
// call JSON.stringify(zoneTask)
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