Skip to content

Commit 78ffe47

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

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-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 this.data.handleId.toString();
12441244
} else {
12451245
return Object.prototype.toString.call(this);
12461246
}

test/common/toString.spec.ts

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

0 commit comments

Comments
 (0)