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

fix(core): fix #1153, ZoneTask.toString should always be a string #1166

Merged
merged 1 commit into from
Dec 12, 2018

Conversation

JiaLiPassion
Copy link
Collaborator

fix #1153.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, if you want to retain behavior similar to the original one, you could also implement valueOf() (to return a number).
(But, tbh, I can't think of any valid usecase for that 😁)

lib/zone.ts Outdated
@@ -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 Object.prototype.toString.call(this.data.handleId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will have the expected behavior, as it will always return [object Number] (which would cause #341 again).
I think it should be this.data.handleId.toString() here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right, thanks!

expect(typeof macroTask.toString()).toEqual('string');
expect(macroTask.toString()).toEqual(id.toString());
expect(typeof microTask.toString()).toEqual('string');
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be valueable to also verify that two different macrotasks have different string representations (just in case).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, case added.

@JiaLiPassion
Copy link
Collaborator Author

@gkalpak, thanks for the review, I didn't implement the valueOf because besides setTimeout/interval, other types of task (microTask, eventTask) may not have some valid primitive representations.

expect(macroTask1Str).toEqual(id1.toString());
expect(typeof macroTask2Str).toEqual('string');
expect(macroTask2Str).toEqual(id2.toString());
if (macroTask1.data && typeof macroTask1.data.handleId === 'number') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the reason is this case will also run in nodejs environment, in nodejs the handleId will be a TimerObject, in that case, we will not check their equality.

@mhevery mhevery merged commit afa1363 into angular:master Dec 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ZoneTask.toString can return a number, which causes problems in Jasmine
4 participants