Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object.prototype.toString: split Symbol.toStringTag tests into separate files #3856

Merged
merged 2 commits into from
Oct 5, 2023

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Jun 15, 2023

See #3855 (comment)

I also added some test coverage that was previously missing.

@ljharb ljharb requested a review from syg June 15, 2023 20:42
@ljharb ljharb requested a review from a team as a code owner June 15, 2023 20:42
var toString = Object.prototype.toString;

var genFn = function* () {};
assert.sameValue(toString.call(gen), '[object GeneratorFunction]');
Copy link
Member Author

Choose a reason for hiding this comment

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

this line was added

assert.sameValue(toString.call(gen), '[object GeneratorFunction]');

var gen = genFn();
assert.sameValue(toString.call(gen), '[object Generator]');
Copy link
Member Author

Choose a reason for hiding this comment

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

this line was added

Object.defineProperty(genProto, Symbol.toStringTag, {
get: function() { return {}; },
});
assert.sameValue(toString.call(gen), '[object Iterator]');
Copy link
Member Author

Choose a reason for hiding this comment

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

this line was corrected - it was "Object" but it should be "Iterator"

Object.defineProperty(mapIterProto, Symbol.toStringTag, {
get: function() { return new String('ShouldNotBeUnwrapped'); },
});
assert.sameValue(toString.call(mapIter), '[object Iterator]');
Copy link
Member Author

Choose a reason for hiding this comment

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

this line was corrected - it was Object but should be Iterator

var toString = Object.prototype.toString;

var promise = new Promise(function () {});
assert.sameValue(toString.call(promise), '[object Promise]');
Copy link
Member Author

Choose a reason for hiding this comment

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

this line was added

Object.defineProperty(mapIterProto, Symbol.toStringTag, {
get: function() { return new String('ShouldNotBeUnwrapped'); },
});
assert.sameValue(toString.call(mapIter), '[object Iterator]');
Copy link
Member Author

Choose a reason for hiding this comment

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

this line was corrected from Object to Iterator

assert.sameValue(toString.call(arrIter), '[object Array Iterator]');

Object.defineProperty(arrIterProto, Symbol.toStringTag, {value: null});
assert.sameValue(toString.call(arrIter), '[object Iterator]');
Copy link
Member Author

Choose a reason for hiding this comment

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

this line was corrected from Object to Iterator

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the original test was correct. The line right above this one redefines %IteratorPrototype%'s @@toStringTag to be null, so it should be [object Object]. Please also double check the other changed tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

It redefines ArrayIteratorPrototype, not IteratorPrototype, i believe.

Copy link
Contributor

Choose a reason for hiding this comment

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

Quite right. Sorry, my reasoning was wrong but the original test is still correct.

Object.defineProperty(arrIterProto, Symbol.toStringTag, {value: null}); sets the value of @@toStringTag to null. Steps 14 and 15 of Object.prototype.toString are:

  1. Let tag be ? Get(O, @@toStringTag).
  2. If tag is not a String, set tag to builtinTag.

So if it finds null on arrIterProto, finds it unusable, and returns [object Object].

Copy link
Member Author

Choose a reason for hiding this comment

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

ahh, ok, without checking the spec or a repl I’d assumed it ignored it instead of breaking the chain lookup. I’ll fix all the relevant lines later this evening.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated - now it verifies its Object when unusable, then deletes it, and then verifies it’s Iterator.

@ljharb ljharb force-pushed the split-tests branch 3 times, most recently from bcf2add to b698fe5 Compare June 21, 2023 19:27
@ljharb
Copy link
Member Author

ljharb commented Aug 23, 2023

@syg ping on taking another look here

@ljharb ljharb force-pushed the split-tests branch 4 times, most recently from 835bcfb to bbdd74b Compare August 26, 2023 21:29
@ljharb ljharb force-pushed the split-tests branch 2 times, most recently from 2d45b32 to d9e984d Compare September 14, 2023 05:43
@ptomato
Copy link
Contributor

ptomato commented Oct 2, 2023

I agreed to review this one. Sorry it has taken me so long to get to it. I expect to have time this week.

Copy link
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

Thanks, looks good. Sorry for the long wait.

@ptomato ptomato merged commit e0436fc into main Oct 5, 2023
1 check passed
@ptomato ptomato deleted the split-tests branch October 5, 2023 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants