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

Commit afa1363

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(core): fix#1153, ZoneTask.toString should always be a string (#1166)
1 parent 33a0ad6 commit afa1363

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎lib/zone.ts‎

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

12411241
publictoString(){
12421242
if(this.data&&typeofthis.data.handleId!=='undefined'){
1243-
returnthis.data.handleId;
1243+
returnthis.data.handleId.toString();
12441244
}else{
12451245
returnObject.prototype.toString.call(this);
12461246
}

‎test/common/toString.spec.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,43 @@ describe('global function patch', () => {
4747
}));
4848
});
4949
});
50+
51+
describe('ZoneTask',()=>{
52+
it('should return handleId.toString if handleId is available',()=>{
53+
letmacroTask1: any=undefined;
54+
letmacroTask2: any=undefined;
55+
letmicroTask: any=undefined;
56+
constzone=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+
}elseif(task.type==='microTask'){
66+
microTask=task;
67+
}
68+
returntask;
69+
}
70+
});
71+
zone.run(()=>{
72+
constid1=setTimeout(()=>{});
73+
clearTimeout(id1);
74+
constid2=setTimeout(()=>{});
75+
clearTimeout(id2);
76+
Promise.resolve().then(()=>{});
77+
constmacroTask1Str=macroTask1.toString();
78+
constmacroTask2Str=macroTask2.toString();
79+
expect(typeofmacroTask1Str).toEqual('string');
80+
expect(macroTask1Str).toEqual(id1.toString());
81+
expect(typeofmacroTask2Str).toEqual('string');
82+
expect(macroTask2Str).toEqual(id2.toString());
83+
if(macroTask1.data&&typeofmacroTask1.data.handleId==='number'){
84+
expect(macroTask1Str).not.toEqual(macroTask2Str);
85+
}
86+
expect(typeofmicroTask.toString()).toEqual('string');
87+
});
88+
});
89+
});

0 commit comments

Comments
 (0)