-
Notifications
You must be signed in to change notification settings - Fork 466
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
Conversation
var toString = Object.prototype.toString; | ||
|
||
var genFn = function* () {}; | ||
assert.sameValue(toString.call(gen), '[object GeneratorFunction]'); |
There was a problem hiding this comment.
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]'); |
There was a problem hiding this comment.
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]'); |
There was a problem hiding this comment.
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]'); |
There was a problem hiding this comment.
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]'); |
There was a problem hiding this comment.
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]'); |
There was a problem hiding this comment.
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]'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- Let tag be ? Get(O, @@toStringTag).
- If tag is not a String, set tag to builtinTag.
So if it finds null
on arrIterProto
, finds it unusable, and returns [object Object]
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
bcf2add
to
b698fe5
Compare
@syg ping on taking another look here |
835bcfb
to
bbdd74b
Compare
2d45b32
to
d9e984d
Compare
I agreed to review this one. Sorry it has taken me so long to get to it. I expect to have time this week. |
There was a problem hiding this 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.
See #3855 (comment)
I also added some test coverage that was previously missing.