Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix(core): fix #1153, ZoneTask.toString should always be a string (#1166
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JiaLiPassion authored and mhevery committed Dec 12, 2018
1 parent 33a0ad6 commit afa1363
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ const Zone: ZoneType = (function(global: any) {

public toString() {
if (this.data && typeof this.data.handleId !== 'undefined') {
return this.data.handleId;
return this.data.handleId.toString();
} else {
return Object.prototype.toString.call(this);
}
Expand Down
40 changes: 40 additions & 0 deletions test/common/toString.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,43 @@ describe('global function patch', () => {
}));
});
});

describe('ZoneTask', () => {
it('should return handleId.toString if handleId is available', () => {
let macroTask1: any = undefined;
let macroTask2: any = undefined;
let microTask: any = undefined;
const zone = Zone.current.fork({
name: 'timer',
onScheduleTask: (delegate: ZoneDelegate, curr: Zone, target: Zone, task: Task) => {
if (task.type === 'macroTask') {
if (!macroTask1) {
macroTask1 = task;
} else {
macroTask2 = task;
}
} else if (task.type === 'microTask') {
microTask = task;
}
return task;
}
});
zone.run(() => {
const id1 = setTimeout(() => {});
clearTimeout(id1);
const id2 = setTimeout(() => {});
clearTimeout(id2);
Promise.resolve().then(() => {});
const macroTask1Str = macroTask1.toString();
const macroTask2Str = macroTask2.toString();
expect(typeof macroTask1Str).toEqual('string');
expect(macroTask1Str).toEqual(id1.toString());
expect(typeof macroTask2Str).toEqual('string');
expect(macroTask2Str).toEqual(id2.toString());
if (macroTask1.data && typeof macroTask1.data.handleId === 'number') {
expect(macroTask1Str).not.toEqual(macroTask2Str);
}
expect(typeof microTask.toString()).toEqual('string');
});
});
});

0 comments on commit afa1363

Please sign in to comment.