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

Commit db24753

Browse files
committed
fix(core): fix #1153, ZoneTask.toString should always be a string
1 parent 9ed5712 commit db24753

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/zone.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ const Zone: ZoneType = (function(global: any) {
12401240

12411241
public toString() {
12421242
if (this.data && typeof this.data.handleId !== 'undefined') {
1243-
return this.data.handleId;
1243+
return Object.prototype.toString.call(this.data.handleId);
12441244
} else {
12451245
return Object.prototype.toString.call(this);
12461246
}

test/common/toString.spec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,29 @@ describe('global function patch', () => {
4747
}));
4848
});
4949
});
50+
51+
describe('ZoneTask', () => {
52+
it('should return handleId.toString if handleId is available', () => {
53+
let macroTask: any = undefined;
54+
let microTask: any = undefined;
55+
const zone = Zone.current.fork({
56+
name: 'timer',
57+
onScheduleTask: (delegate: ZoneDelegate, curr: Zone, target: Zone, task: Task) => {
58+
if (task.type === 'macroTask') {
59+
macroTask = task;
60+
} else if (task.type === 'microTask') {
61+
microTask = task;
62+
}
63+
return task;
64+
}
65+
});
66+
zone.run(() => {
67+
const id = setTimeout(() => {});
68+
clearTimeout(id);
69+
Promise.resolve().then(() => {});
70+
expect(typeof macroTask.toString()).toEqual('string');
71+
expect(macroTask.toString()).toEqual(id.toString());
72+
expect(typeof microTask.toString()).toEqual('string');
73+
});
74+
});
75+
});

0 commit comments

Comments
 (0)